|
1 | | -import { promises as fs } from "node:fs"; |
2 | 1 | import path from "node:path"; |
3 | 2 | import { fileURLToPath } from "node:url"; |
| 3 | +import { runFileSizeCheck } from "../../scripts/check-file-sizes-core.mjs"; |
4 | 4 |
|
5 | 5 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
6 | 6 | const projectRoot = path.resolve(__dirname, ".."); |
7 | 7 |
|
| 8 | +const MAX_LINES = 1000; |
| 9 | + |
8 | 10 | const rules = [ |
9 | | - { |
10 | | - root: "src-tauri/src", |
11 | | - extensions: new Set([".rs"]), |
12 | | - maxLines: 500, |
13 | | - }, |
| 11 | + { root: "src-tauri/src", extensions: new Set([".rs"]), maxLines: MAX_LINES }, |
14 | 12 | { |
15 | 13 | root: "src/app", |
16 | 14 | extensions: new Set([".ts", ".tsx"]), |
17 | | - maxLines: 500, |
| 15 | + maxLines: MAX_LINES, |
18 | 16 | }, |
19 | 17 | { |
20 | 18 | root: "src/features", |
21 | 19 | extensions: new Set([".ts", ".tsx"]), |
22 | | - maxLines: 500, |
| 20 | + maxLines: MAX_LINES, |
23 | 21 | }, |
24 | 22 | { |
25 | 23 | root: "src/shared/api", |
26 | 24 | extensions: new Set([".ts", ".tsx"]), |
27 | | - maxLines: 500, |
| 25 | + maxLines: MAX_LINES, |
28 | 26 | }, |
29 | 27 | ]; |
30 | 28 |
|
31 | | -// Exceptions should stay rare and temporary. Prefer splitting files instead. |
| 29 | +// TEMP — these files exceed the 1000-line limit and are queued to be split. |
| 30 | +// Do not add to this list; split the file instead. Remove each entry as its |
| 31 | +// file is broken up. Tracked as a follow-up. |
32 | 32 | const overrides = new Map([ |
33 | | - ["src-tauri/src/managed_agents/nest.rs", 1420], // version-gated AGENTS.md + SKILL.md refresh + .agents/.claude symlink migration + ensure_skill_symlinks (all known providers) + managed section upsert + dynamic agent context + tests |
34 | | - ["src-tauri/src/managed_agents/personas.rs", 980], // built-in persona system prompts (Solo + Kit + Scout) + merge_personas inequality checks + persona pack import/uninstall/list + uninstall safety check + retired persona migration (RETIRED_PERSONAS constant + migrate_retired_personas) |
35 | | - ["src-tauri/src/managed_agents/teams.rs", 580], // built-in team registry (Kit & Scout) + merge_teams + validate_team_deletion + JSON export/import + tests |
36 | | - ["src-tauri/src/managed_agents/persona_card.rs", 970], // PNG/ZIP/MD persona card codec + pack-zip detection + nested root finder + provider/model/namePool fields + 27 unit tests |
37 | | - ["src/app/AppShell.tsx", 880], // message edit state + handlers + ChannelPane edit prop threading + scrollback pagination + workflows view + projects view + memory-leak safeguards + home-badge state lifted here so it consumes the same NIP-RS read-state as the sidebar (single ReadStateManager) + dock bounce wiring + mark-all-read context + channel notification callback + desktopEnabled guard + useThreadFollows wiring + isNotifiedForThread combined predicate + threadActivityItems context plumbing + mutedRootIds denylist + handleFollowThread/handleUnfollowThread combined handlers |
38 | | - ["src/features/channels/hooks.ts", 550], // canvas query + mutation hooks + DM hide mutation |
39 | | - ["src/features/channels/ui/ChannelManagementSheet.tsx", 800], |
40 | | - ["src/features/channels/ui/ChannelPane.tsx", 540], // composer/timeline/sidebar orchestration + anchored agent activity footers + imetaMedia threading on editTarget + thread follow props passthrough |
41 | | - ["src/features/channels/ui/ChannelScreen.tsx", 580], // profile panel state + mutual exclusion wiring + ProfilePanelProvider context + agent typing classification + imetaMedia projection on editTarget + thread follow wiring from AppShell context |
42 | | - ["src/features/channels/useUnreadChannels.ts", 717], // NIP-RS read marker tracking + participated/authored/followed thread ID sets + localStorage persistence + catch-up REQ with thread activity collection + thread reply activity feed items + mutedRootIds denylist with localStorage persistence + muteThread/unmuteThread callbacks + markChannelRead latestByChannelRef fallback chain (matches markChannelUnread) |
43 | | - ["src/features/notifications/hooks.ts", 535], // notification settings + feed notification lifecycle + profile batch resolution + truncated-pubkey guard + badge state |
44 | | - ["src/features/home/ui/HomeView.tsx", 505], // inbox/feed orchestration + thread context + reply/delete flow + NIP-RS read-state projection wiring (useHomeInboxReadState) |
45 | | - ["src/features/messages/hooks.ts", 530], // message query/mutation hooks + optimistic updates + custom-emoji reaction URL resolution (reactionEmojiUrl from cached relay set) + outgoing tag split (splitOutgoingTags) routing custom-emoji tags through the dedicated emoji_tags send arg so they skip the imeta-only gate; edit mutation splits the merged tag set the same way so edited custom emoji ride the dedicated emoji_tags arg |
46 | | - ["src/features/messages/lib/useRichTextEditor.ts", 620], // editor setup + 3 inline Tiptap keymap extensions (macEmacs/smartShiftEnter/submitOnEnter) + editorProps.handleKeyDown for ↑-to-edit + editable-toggle focus-restore (records isFocused before disable on send, re-focuses on re-enable so the WebView blur-on-disable doesn't strand focus on body) + custom-emoji atom-node wiring (useComposerCustomEmoji extension + src re-resolve effect; replacePlainTextRange inserts the selectable/copyable CustomEmojiNode for `:shortcode:` so it behaves like a built-in emoji glyph). Split candidate: extract the 3 keymap extensions to a sibling module (tracked follow-up). |
47 | | - ["src/features/messages/ui/MessageComposer.tsx", 870], // media upload handlers (paste, drop, dialog) + channelId reset effect + edit mode (pre-fill, save, cancel, escape) + composer autofocus (#572) + Sprout code-block paste branch (round-trips copy-button output as a literal codeBlock so Markdown can't reshape it) + scroll-to-bottom on multi-line paste (#619) + Slack-style attachment-editable edits: seed pendingImeta from edit target, stash/restore user's draft pendingImeta across edit-mode entry/exit, re-append imeta markdown lines on edit-submit so renderer draws them + custom emoji: useCustomEmoji feeds picker/autocomplete and mergeOutgoingTags attaches NIP-30 emoji tags on send AND on edit-save (so edited custom emoji stay resolvable); insertEmoji inserts a known `:shortcode:` as the selectable CustomEmojiNode atom (else plain native unicode) |
48 | | - ["src/features/settings/ui/SettingsView.tsx", 600], |
49 | | - ["src/features/sidebar/ui/AppSidebar.tsx", 830], // channels + forums creation forms + Pulse nav + channel sections state/dialogs + SidebarDndContext wrapper + sectionIds memo for DnD section reorder + controlled create-channel dialog for ⌘⇧N shortcut |
50 | | - ["src/features/sidebar/ui/CustomChannelSection.tsx", 615], // ChannelGroupSection + CustomChannelSection + SectionHeaderActions + ChannelContextMenuItems + MoveToSectionSubmenu + per-section mark-all-read + DnD wrappers (SortableSectionShell, DraggableChannelRow, DroppableSectionBody, DroppableUngroupedBody) + draggable prop on ChannelGroupSection |
51 | | - ["src/shared/api/relayClientSession.ts", 1040], // durable websocket session manager with reconnect/replay/recovery state + sendTypingIndicator + fetchChannelHistoryBefore + subscribeToChannelLive (huddle TTS) + subscribeToHuddleEvents (huddle indicator) + disconnect() for workspace switch teardown + fetchEvents/subscribeLive/publishEvent for NIP-RS read state + publishUserStatus/subscribeToUserStatusUpdates (NIP-38) + ConnectionState plumbing & stall-watchdog wiring for half-open WS detection (Warp orange-icon case) + terminal session latch (auth rejection no longer racing back to reconnecting) — emitter + watchdog + reconnect policy logic extracted to relayConnectionStateEmitter.ts / relayStallWatchdog.ts / relayReconnectPolicy.ts |
52 | | - ["src-tauri/src/migration.rs", 1010], // worktree shared-agent-data symlink sync (SHARED_AGENT_FILES + SHARED_AGENT_DIRS symlink-to-canonical + sibling pack migration) + mcp_command provider reconciliation + persona_pack_path reconciliation + tests |
53 | | - ["src-tauri/src/commands/media.rs", 730], // ffmpeg video transcode + poster frame extraction + run_ffmpeg_with_timeout (find_ffmpeg via resolve_command, is_video_file, transcode_to_mp4, extract_poster_frame, transcode_and_extract_poster) + spawn_blocking wrappers + tests |
54 | | - ["src-tauri/src/commands/agents.rs", 910], // remote agent lifecycle routing (local + provider branches) + scope enforcement + persona pack metadata wiring + mcp_toolsets field + NIP-OA auth_tag in deploy payload + relay-mesh client preflight (start_local_agent_with_preflight + StartTarget split: async ensure outside store lock, then sync spawn under lock) |
55 | | - ["src-tauri/src/commands/messages.rs", 530], // feed multi-query + NIP-50 search + forum thread resolution + thread ref + edit_message media_tags + emoji_tags params (Slack-style attachment edits + edited custom emoji stay resolvable) + add_reaction custom-emoji branch (build_custom_emoji_reaction when emoji_url is set) |
56 | | - ["src-tauri/src/nostr_convert.rs", 1150], // 12 Nostr event→model converters (channels, profiles, members, notes, search, agents, relay members) + rank_user_search_results helper for NIP-50 user search + 33 unit tests |
57 | | - ["src-tauri/src/managed_agents/runtime.rs", 1390], // ... + respond-to gate env (SPROUT_ACP_RESPOND_TO[_ALLOWLIST]) + per-mode env builder + tests + persona/agent env_vars spawn merge (helper + tests now in env_vars.rs) + system-wide orphan sweep (proc_listallpids/proc on macOS, /proc on Linux) + SPROUT_MANAGED_AGENT env marker check (KERN_PROCARGS2 on macOS, /proc/environ on Linux), instance-scoped by app identifier so coexisting Sprout instances don't reap each other's agents + relay_mesh_model_id detector (mesh preset-env match) + tests |
58 | | - ["src-tauri/src/managed_agents/discovery.rs", 680], // KNOWN_ACP_PROVIDERS catalog + resolve_command cache + login_shell_path + classify_provider (four-state: Available/AdapterMissing/CliMissing/NotInstalled) + discover_acp_providers with dynamic install_hint + known_acp_provider/known_acp_provider_exact + normalize_agent_args + 15 unit tests |
59 | | - ["src-tauri/src/managed_agents/types.rs", 745], // ManagedAgentRecord/Summary + Create/Update request structs + AcpProviderCatalogEntry + InstallRuntimeResult + RespondTo enum + validate_respond_to_allowlist + tests + persona/agent env_vars field |
60 | | - ["src-tauri/src/managed_agents/backend.rs", 700], // provider IPC, validation, discovery, binary resolution + tests + redact_secrets_with for user env values + env_secrets_from_request + redact_env_values_in (shared with model discovery) |
61 | | - ["src/features/huddle/HuddleContext.tsx", 650], // huddle lifecycle context + joinHuddle + connectAndSetupMedia shared helper + activeSpeakers/isReconnecting state + PTT (reusable AudioContext) + TTS subscription + mic level analyser (10fps throttle) + agent pubkey refresh |
62 | | - ["src/features/agents/hooks.ts", 550], // agent query/mutation surface + useAvailableAcpProviders (type-narrowing filter hook) + useInstallAcpRuntimeMutation + built-in persona library activation |
63 | | - ["src/features/agents/ui/AgentsView.tsx", 880], // remote agent lifecycle controls + persona/team management + persona import-update dialog wiring + built-in catalog/library state orchestration |
64 | | - ["src/features/agents/ui/UnifiedAgentsSection.tsx", 570], // unified persona-grouped agent view with collapsible groups, bulk actions, drag-drop import, empty/loading states |
65 | | - ["src/features/agents/ui/ManagedAgentRow.tsx", 530], // EditAgentDialog integration + provider/local branching |
66 | | - ["src/features/agents/ui/TeamDialog.tsx", 530], // team create/edit dialog with persona multi-select, import button, window drag detection, removal confirmation |
67 | | - ["src/features/agents/ui/TeamImportUpdateDialog.tsx", 660], // team import diff preview with member matching/updating/adding/removing sections, LCS line counts, removal confirmation |
68 | | - ["src/features/agents/ui/useTeamActions.ts", 510], // team CRUD + export + import + import-update orchestration with query invalidation |
69 | | - ["src/features/agents/ui/PersonaDialog.tsx", 515], // persona create/edit form + env vars editor + drag-drop file import + runtime provider dropdown with availability warnings |
70 | | - ["src/features/agents/ui/CreateAgentDialog.tsx", 685], // provider selector + config form + schema-typed config coercion + required field validation + locked scopes |
71 | | - ["src/features/channels/ui/AddChannelBotDialog.tsx", 690], // provider mode: Run on selector, trust warning, probe effect, single-agent enforcement, provider warnings display + RespondTo field + reuse guardrail |
72 | | - ["src/features/settings/ui/ChannelTemplatesSettingsCard.tsx", 850], // template CRUD card + TemplateFormDialog (persona/team chip selectors + provider assignments + canvas template) + TemplateTeamSelector + ProviderAssignments + ProviderRow |
73 | | - ["src/shared/api/types.ts", 650], // ... + AcpProviderCatalogEntry + AcpProvider (narrowed subtype) + InstallRuntimeResult + RespondToMode + respondTo/respondToAllowlist on ManagedAgent/Create/Update inputs |
74 | | - ["src-tauri/src/events.rs", 830], // event builders + build_huddle_guidelines (kind:48106) + post_event_raw transport helper + participant p-tag on join/leave + NIP-43 relay admin builders (add/remove/change-role) + check_relay_role + DM/presence/workflow command builders + NIP-IA identity-archive builders (9035/9036) + .allow_self_tagging() guards (nostr 0.44 strips self-`p` by default; self-archive/unarchive needs it preserved) + spec vector 1 layout test + emoji_tags() NIP-30 builder (mirrors the imeta_tags injection guard, first elem must be "emoji"); build_message_edit also threads emoji_tags so edited custom emoji stay resolvable |
75 | | - ["src-tauri/src/huddle/mod.rs", 1020], // huddle state machine + Tauri commands + sync protocol doc; state/relay/pipeline extracted + emit_huddle_state_changed wiring |
76 | | - ["src-tauri/src/huddle/models.rs", 950], // model download manager for Parakeet TDT-CTC STT + Pocket TTS with streaming downloads + SHA-256 verification + Rust-native tar extraction + version manifest + atomic swap + hot-start signaling + MODEL_LICENSE.txt sidecar (fail-closed readiness) + idempotent legacy Moonshine dir cleanup + tts_readiness_requires_license_sidecar test + Mary (VCTK p333) reference voice attribution block |
77 | | - ["src-tauri/src/huddle/stt.rs", 580], // STT pipeline + PTT edge-detection flush + PTT gating (is_speech AND ptt_active) + barge-in for VAD mode + rubato resampler + earshot VAD + sherpa-onnx transcription |
78 | | - ["src-tauri/src/huddle/pocket.rs", 900], // Pocket TTS engine wrapper + prepare_pocket_prompt (capitalize/punctuate/pad short inputs + insert ". . " sacrificial cold-start prefix, mirror upstream pocket-tts prepare_text_prompt) + build_generation_extra (only overrides max_frames, and only for ≤4-word inputs, to bound runaway "monster breathing" generation without clipping multi-clause sentences) + trim_leading_cold_start (post-synth strip of sacrificial audio on short prompts, workaround for kyutai-labs/pocket-tts #91 first-phoneme drop) + 18 unit tests including regressions for the static-burst-on-multi-clause-sentence bug and the first-phoneme-drop trim hazards |
79 | | - ["src-tauri/src/huddle/preprocessing.rs", 670], // TTS text preprocessing pipeline + unified split_sentences + int_to_words 0-999999 + URL trailing punctuation preservation + 23 unit tests |
80 | | - ["src-tauri/src/huddle/relay_api.rs", 520], // audio relay recv task + per-peer frame counting for remote human TTS interrupt + NIP-98 channel member query |
81 | | - ["src-tauri/src/huddle/tts.rs", 1380], // TTS pipeline + session warmup + cancel/shutdown handling + apply_fade_out (fade-out only — leading fade removed 2026-05-18 after onset-attenuation regression measured in examples/pocket_onset_probe.rs) + FIRST_APPEND_LEAD_IN_SAMPLES + build_sentence_append_plan (pure helper enforcing the lead-in fires exactly once per utterance, not per sentence — see lead_in_pad_fires_exactly_once_per_utterance regression test) + normalize_for_playback (per-sentence peak normalization to -3 dBFS ceiling with MAX_GAIN cap) + 30 unit tests (18 interrupt + 5 fade-out + 1 first-append-lead-in + 3 build-sentence-append-plan + 6 normalize) |
82 | | - ["src-tauri/src/relay.rs", 510], // +4 lines for NIP-OA auth tag injection in profile sync (build_profile_event) + verification test |
83 | | - ["src-tauri/src/commands/pairing.rs", 600], // NIP-AB pairing actor: 3 Tauri commands + background WS task + NIP-42 auth + NIP-43 probe + event parsing helpers |
84 | | - ["src-tauri/src/lib.rs", 850], // + mesh_llm_stubs module (feature-gated no-op Tauri commands; incl mesh_dial_endpoint_addr + mesh_status_report_payload required for the default no-feature build's generate_handler! list) + mesh command registrations + PairingHandle managed state + 3 pairing command registrations + parse_message_deep_link helper extracted with 6 unit tests covering empty-param filter regression + mod migration + sync_shared_agent_data/reconcile_provider_mcp_commands/reconcile_persona_pack_paths calls on launch + SIGINT/SIGTERM/SIGHUP signal handlers for agent process cleanup |
85 | | - ["src/shared/api/tauri.ts", 1212], // pairing command wrappers + applyWorkspace + NIP-44 encrypt/decrypt wrappers + observer_url field + relay member API functions (list/get/add/remove/change-role) + prevent sleep + AcpProviderCatalogEntry raw types + fromRawAcpProviderCatalogEntry converter + installAcpRuntime |
| 33 | + ["src-tauri/src/managed_agents/nest.rs", 1415], |
| 34 | + ["src-tauri/src/managed_agents/runtime.rs", 1387], |
| 35 | + ["src-tauri/src/huddle/tts.rs", 1364], |
| 36 | + ["src/shared/api/tauri.ts", 1196], |
| 37 | + ["src-tauri/src/nostr_convert.rs", 1116], |
| 38 | + ["src/shared/api/relayClientSession.ts", 1022], |
| 39 | + ["src-tauri/src/migration.rs", 1005], |
86 | 40 | ]); |
87 | 41 |
|
88 | | -async function walkFiles(directory) { |
89 | | - const entries = await fs.readdir(directory, { withFileTypes: true }); |
90 | | - const files = await Promise.all( |
91 | | - entries.map(async (entry) => { |
92 | | - const fullPath = path.join(directory, entry.name); |
93 | | - if (entry.isDirectory()) { |
94 | | - return walkFiles(fullPath); |
95 | | - } |
96 | | - |
97 | | - return [fullPath]; |
98 | | - }), |
99 | | - ); |
100 | | - |
101 | | - return files.flat(); |
102 | | -} |
103 | | - |
104 | | -function findRule(relativePath) { |
105 | | - return rules.find((rule) => { |
106 | | - const normalizedRoot = `${rule.root}${path.sep}`; |
107 | | - return relativePath.startsWith(normalizedRoot); |
108 | | - }); |
109 | | -} |
110 | | - |
111 | | -function countLines(content) { |
112 | | - if (content.length === 0) { |
113 | | - return 0; |
114 | | - } |
115 | | - |
116 | | - return content.split(/\r?\n/).length; |
117 | | -} |
118 | | - |
119 | | -const candidateFiles = ( |
120 | | - await Promise.all( |
121 | | - rules.map((rule) => walkFiles(path.join(projectRoot, rule.root))), |
122 | | - ) |
123 | | -).flat(); |
124 | | - |
125 | | -const violations = []; |
126 | | - |
127 | | -for (const filePath of candidateFiles) { |
128 | | - const relativePath = path.relative(projectRoot, filePath); |
129 | | - const rule = findRule(relativePath); |
130 | | - if (!rule) { |
131 | | - continue; |
132 | | - } |
133 | | - |
134 | | - const extension = path.extname(relativePath); |
135 | | - if (!rule.extensions.has(extension)) { |
136 | | - continue; |
137 | | - } |
138 | | - |
139 | | - const limit = overrides.get(relativePath) ?? rule.maxLines; |
140 | | - const content = await fs.readFile(filePath, "utf8"); |
141 | | - const lineCount = countLines(content); |
142 | | - if (lineCount > limit) { |
143 | | - violations.push({ |
144 | | - limit, |
145 | | - lineCount, |
146 | | - relativePath, |
147 | | - }); |
148 | | - } |
149 | | -} |
150 | | - |
151 | | -if (violations.length > 0) { |
152 | | - console.error("Desktop file size check failed:"); |
153 | | - for (const violation of violations) { |
154 | | - console.error( |
155 | | - `- ${violation.relativePath}: ${violation.lineCount} lines (limit ${violation.limit})`, |
156 | | - ); |
157 | | - } |
158 | | - console.error( |
159 | | - "Split the file or add a narrowly scoped exception in `desktop/scripts/check-file-sizes.mjs`.", |
160 | | - ); |
161 | | - process.exit(1); |
162 | | -} |
| 42 | +await runFileSizeCheck({ |
| 43 | + projectRoot, |
| 44 | + rules, |
| 45 | + overrides, |
| 46 | + label: "Desktop", |
| 47 | + scriptPath: "desktop/scripts/check-file-sizes.mjs", |
| 48 | +}); |
0 commit comments