@cryptiklemur/lattice 4.0.2 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/lattice +1 -9
- package/dist/client/assets/{angular-html-N8PCEquT.js → angular-html-DKTL-XDO.js} +1 -1
- package/dist/client/assets/{angular-ts-CJ8RJIPD.js → angular-ts-tvBzOwQR.js} +1 -1
- package/dist/client/assets/{apl-BD6tCLWN.js → apl-CCzl5qFl.js} +1 -1
- package/dist/client/assets/{astro-CpIIfBs6.js → astro-DNQTpO2Y.js} +1 -1
- package/dist/client/assets/{blade-D3qgnjiV.js → blade-CyJoIMeJ.js} +1 -1
- package/dist/client/assets/{c-Dr6ADN_t.js → c-OEwk5KN8.js} +1 -1
- package/dist/client/assets/{cobol-BIfDE0Hr.js → cobol-DpHyJzz2.js} +1 -1
- package/dist/client/assets/{coffee-DHQ57vfY.js → coffee-BX5dbDzZ.js} +1 -1
- package/dist/client/assets/{cpp-CEBY6JOp.js → cpp-BTBjNg2U.js} +1 -1
- package/dist/client/assets/{crystal-D125CSmP.js → crystal-CNzZd6DW.js} +1 -1
- package/dist/client/assets/{css-CBmrkYSr.js → css-BuKsNmms.js} +1 -1
- package/dist/client/assets/{dist-A_mCRD1f.js → dist-CKpDHMy6.js} +2 -2
- package/dist/client/assets/{edge-Ccsz7cJW.js → edge-DzhnGgJE.js} +1 -1
- package/dist/client/assets/{elixir-Do6gk14X.js → elixir-Dqs0waqF.js} +1 -1
- package/dist/client/assets/{elm-Db22zT4C.js → elm-BtWwjxWn.js} +1 -1
- package/dist/client/assets/{erb-MXVqAAJD.js → erb-iPD89b4v.js} +1 -1
- package/dist/client/assets/{git-rebase-B-LLWBOA.js → git-rebase-BxVNXJL4.js} +1 -1
- package/dist/client/assets/{glimmer-js-eWszRU73.js → glimmer-js-BlyCupwF.js} +1 -1
- package/dist/client/assets/{glimmer-ts-VQmwGqUp.js → glimmer-ts-DjIxWOS9.js} +1 -1
- package/dist/client/assets/{glsl-B8ilOfAl.js → glsl-CGIL-65r.js} +1 -1
- package/dist/client/assets/{graphql-DnTqxeOc.js → graphql-DeOn6mNV.js} +1 -1
- package/dist/client/assets/{hack-XJsHYSQb.js → hack-DVppeCmS.js} +1 -1
- package/dist/client/assets/{haml-CQ7Vqzwp.js → haml-WDhua0Mp.js} +1 -1
- package/dist/client/assets/{handlebars-C4szooBf.js → handlebars-i2Fu_9HI.js} +1 -1
- package/dist/client/assets/{html-B6EgAiSd.js → html-B1e6oxzK.js} +1 -1
- package/dist/client/assets/{html-derivative-DdinogQX.js → html-derivative-MofKXIVd.js} +1 -1
- package/dist/client/assets/{http-BSLxCgRq.js → http-Dk6S5pRD.js} +1 -1
- package/dist/client/assets/{hurl-pOsTwNfp.js → hurl-CroFYYJG.js} +1 -1
- package/dist/client/assets/{index-BHQ_8mvl.js → index-CVu-S6Yk.js} +2 -2
- package/dist/client/assets/{java-DRQLiiST.js → java-B89FYjqS.js} +1 -1
- package/dist/client/assets/{javascript-DvEK2-47.js → javascript-m6CO1Uiy.js} +1 -1
- package/dist/client/assets/{jinja-D2NYJ25y.js → jinja-DC9Wi41X.js} +1 -1
- package/dist/client/assets/{jison-DDZaLNAp.js → jison-6xiegwDk.js} +1 -1
- package/dist/client/assets/{json-TGR0NIWd.js → json-HA-96-qr.js} +1 -1
- package/dist/client/assets/{jsx-BjUoPYga.js → jsx-Wt1a8i8U.js} +1 -1
- package/dist/client/assets/{julia-C4gjSpFu.js → julia-7M93VBON.js} +1 -1
- package/dist/client/assets/{just-H351x5u_.js → just-CjfDLYLv.js} +1 -1
- package/dist/client/assets/{latex-BiTmf6gf.js → latex-CitsJ46x.js} +1 -1
- package/dist/client/assets/{liquid-86ufjRy-.js → liquid-C8VIFin8.js} +1 -1
- package/dist/client/assets/{lua-BNxR0F_8.js → lua-Ba2N7esc.js} +1 -1
- package/dist/client/assets/{marko-CvRxpRjM.js → marko-lTLvb2wu.js} +1 -1
- package/dist/client/assets/{mdc-CYbAIy2C.js → mdc-D6IV-8FD.js} +1 -1
- package/dist/client/assets/{nginx-egdgMq-F.js → nginx-Ch5AjE6S.js} +1 -1
- package/dist/client/assets/{nim-CXBJVz_w.js → nim-WmDDC6LW.js} +1 -1
- package/dist/client/assets/{perl-XRfMobzg.js → perl-CQv0gYuq.js} +1 -1
- package/dist/client/assets/{php-Br7a8uil.js → php-BJmH0qOB.js} +1 -1
- package/dist/client/assets/{pug-BVbbUVvy.js → pug-CsHPkzc9.js} +1 -1
- package/dist/client/assets/{qml-ByKvrL1j.js → qml-B36ecArG.js} +1 -1
- package/dist/client/assets/{r-mVoV0Ni6.js → r-D5Yi5Z4y.js} +1 -1
- package/dist/client/assets/{razor-T5O-9UJL.js → razor-CHAxVq4R.js} +1 -1
- package/dist/client/assets/{regexp-CioRuhuN.js → regexp-gfs--3M7.js} +1 -1
- package/dist/client/assets/{rst-V__uTudD.js → rst-ugdlp-hl.js} +1 -1
- package/dist/client/assets/{ruby-C_PuKPTI.js → ruby-CDRRW37j.js} +1 -1
- package/dist/client/assets/{sas-D_DqqQH4.js → sas-DZaNQaIP.js} +1 -1
- package/dist/client/assets/{scss-D-TjzZ4c.js → scss-CzWQEplj.js} +1 -1
- package/dist/client/assets/{shellscript-E5759VHu.js → shellscript-fgYvpu9N.js} +1 -1
- package/dist/client/assets/{shellsession-AESTM-Pv.js → shellsession-BoAohHh7.js} +1 -1
- package/dist/client/assets/{soy-QrbrrcDv.js → soy-DBzVgv9x.js} +1 -1
- package/dist/client/assets/{sql-0M8VcDHD.js → sql-BYXpAYTs.js} +1 -1
- package/dist/client/assets/{stata-CgeIpGtc.js → stata-I71MMY3p.js} +1 -1
- package/dist/client/assets/{surrealql-DBGwnZbw.js → surrealql-C9U8_1VO.js} +1 -1
- package/dist/client/assets/{svelte-Cv0PvUc_.js → svelte-VOFrPnWT.js} +1 -1
- package/dist/client/assets/{templ-B9t7xRE4.js → templ-BIaxAEtC.js} +1 -1
- package/dist/client/assets/{tex-DhZZ8dr2.js → tex-D1dwnBE5.js} +1 -1
- package/dist/client/assets/{ts-tags-BFv8sbnd.js → ts-tags-C0L2Q0r5.js} +1 -1
- package/dist/client/assets/{tsx-CXC9KSbY.js → tsx-BqcycEv1.js} +1 -1
- package/dist/client/assets/{twig-CM_OO66r.js → twig-vyWqOhpM.js} +1 -1
- package/dist/client/assets/{typescript-BdgOTaoD.js → typescript-B2YbovqG.js} +1 -1
- package/dist/client/assets/{vue-BnQhjnCm.js → vue-CbXxGdjo.js} +1 -1
- package/dist/client/assets/{vue-html-CNnGecRI.js → vue-html-DDX4KXW7.js} +1 -1
- package/dist/client/assets/{vue-vine-DCuMkRhK.js → vue-vine-DsyY1LR5.js} +1 -1
- package/dist/client/assets/{xml-CbTD7cB8.js → xml-Ddi0-r0D.js} +1 -1
- package/dist/client/assets/{xsl-uOqqo7cf.js → xsl-CsFcZHFS.js} +1 -1
- package/dist/client/assets/{yaml-BNrLoH59.js → yaml-tGJWoH6Y.js} +1 -1
- package/dist/client/index.html +1 -1
- package/dist/client/sw.js +1 -1
- package/dist/server/analytics/engine.js +832 -0
- package/dist/server/assets.js +39 -0
- package/dist/server/auth/passphrase.js +70 -0
- package/dist/server/config.js +47 -0
- package/dist/server/daemon.js +535 -0
- package/dist/server/features/ralph-loop.js +138 -0
- package/dist/server/features/scheduler.js +260 -0
- package/dist/server/features/sticky-notes.js +99 -0
- package/dist/server/handlers/analytics.js +28 -0
- package/dist/server/handlers/attachment.js +158 -0
- package/dist/server/handlers/bookmarks.js +41 -0
- package/dist/server/handlers/chat.js +350 -0
- package/dist/server/handlers/editor.js +72 -0
- package/dist/server/handlers/fs.js +234 -0
- package/dist/server/handlers/loop.js +33 -0
- package/dist/server/handlers/memory.js +181 -0
- package/dist/server/handlers/mesh.js +322 -0
- package/dist/server/handlers/notes.js +36 -0
- package/dist/server/handlers/plugins.js +593 -0
- package/dist/server/handlers/project-settings.js +166 -0
- package/dist/server/handlers/scheduler.js +52 -0
- package/dist/server/handlers/session.js +194 -0
- package/dist/server/handlers/settings.js +148 -0
- package/dist/server/handlers/skills.js +360 -0
- package/dist/server/handlers/terminal.js +75 -0
- package/dist/server/handlers/themes.js +102 -0
- package/dist/server/handlers/update.js +124 -0
- package/dist/server/identity.js +45 -0
- package/dist/server/index.js +435 -0
- package/dist/server/logger.js +20 -0
- package/dist/server/mesh/connector.js +355 -0
- package/dist/server/mesh/crypto.js +88 -0
- package/dist/server/mesh/discovery.js +95 -0
- package/dist/server/mesh/pairing.js +104 -0
- package/dist/server/mesh/peers.js +54 -0
- package/dist/server/mesh/proxy.js +86 -0
- package/dist/server/mesh/session-sync.js +85 -0
- package/dist/server/project/bookmarks.js +77 -0
- package/dist/server/project/context-breakdown.js +279 -0
- package/dist/server/project/file-browser.js +97 -0
- package/dist/server/project/project-files.js +274 -0
- package/dist/server/project/registry.js +51 -0
- package/dist/server/project/sdk-bridge.js +960 -0
- package/dist/server/project/session.js +696 -0
- package/dist/server/project/terminal.js +87 -0
- package/dist/server/project/warmup.js +242 -0
- package/dist/server/push.js +87 -0
- package/dist/server/tls.js +50 -0
- package/dist/server/tui.js +83 -0
- package/dist/server/update-checker.js +119 -0
- package/dist/server/ws/broadcast.js +50 -0
- package/dist/server/ws/router.js +105 -0
- package/dist/server/ws/server.js +2 -0
- package/dist/shared/analytics.js +1 -0
- package/dist/shared/messages.js +1 -0
- package/dist/shared/models.js +1 -0
- package/dist/shared/project-settings.js +1 -0
- package/package.json +5 -8
- package/themes/alabaster.json +9 -0
- package/themes/amoled.json +20 -0
- package/themes/ayu-light.json +9 -0
- package/themes/catppuccin-latte.json +9 -0
- package/themes/catppuccin-mocha.json +9 -0
- package/themes/clay-light.json +10 -0
- package/themes/clay.json +10 -0
- package/themes/dracula.json +9 -0
- package/themes/everforest-light.json +9 -0
- package/themes/everforest.json +9 -0
- package/themes/github-light.json +9 -0
- package/themes/gruvbox-dark.json +9 -0
- package/themes/gruvbox-light.json +9 -0
- package/themes/horizon-light.json +9 -0
- package/themes/kanagawa-lotus.json +9 -0
- package/themes/kanagawa.json +9 -0
- package/themes/modus-operandi.json +9 -0
- package/themes/monokai.json +9 -0
- package/themes/nightfox.json +9 -0
- package/themes/nord-light.json +9 -0
- package/themes/nord.json +9 -0
- package/themes/one-dark.json +9 -0
- package/themes/one-light.json +9 -0
- package/themes/palenight.json +9 -0
- package/themes/paper.json +9 -0
- package/themes/penumbra-light.json +9 -0
- package/themes/poimandres.json +9 -0
- package/themes/quiet-light.json +9 -0
- package/themes/rose-pine-dawn.json +9 -0
- package/themes/rose-pine.json +9 -0
- package/themes/solarized-dark.json +9 -0
- package/themes/solarized-light.json +9 -0
- package/themes/synthwave84.json +9 -0
- package/themes/tokyo-night-light.json +9 -0
- package/themes/tokyo-night.json +9 -0
- package/themes/vesper.json +9 -0
- package/index.html +0 -20
- package/public/icons/icon-192.svg +0 -11
- package/public/icons/icon-512.svg +0 -11
- package/public/sw-push.js +0 -53
- package/src/client/App.tsx +0 -42
- package/src/client/commands.ts +0 -36
- package/src/client/components/analytics/AnalyticsView.tsx +0 -244
- package/src/client/components/analytics/ChartCard.tsx +0 -194
- package/src/client/components/analytics/PeriodSelector.tsx +0 -42
- package/src/client/components/analytics/QuickStats.tsx +0 -122
- package/src/client/components/analytics/chartTokens.ts +0 -188
- package/src/client/components/analytics/charts/ActivityCalendar.tsx +0 -204
- package/src/client/components/analytics/charts/CacheEfficiencyChart.tsx +0 -56
- package/src/client/components/analytics/charts/ContextUtilizationChart.tsx +0 -106
- package/src/client/components/analytics/charts/CostAreaChart.tsx +0 -79
- package/src/client/components/analytics/charts/CostDistributionChart.tsx +0 -59
- package/src/client/components/analytics/charts/CostDonutChart.tsx +0 -84
- package/src/client/components/analytics/charts/CumulativeCostChart.tsx +0 -59
- package/src/client/components/analytics/charts/DailySummaryCards.tsx +0 -86
- package/src/client/components/analytics/charts/HourlyHeatmap.tsx +0 -133
- package/src/client/components/analytics/charts/NodeFleetOverview.tsx +0 -89
- package/src/client/components/analytics/charts/PermissionBreakdown.tsx +0 -98
- package/src/client/components/analytics/charts/ProjectRadar.tsx +0 -126
- package/src/client/components/analytics/charts/ResponseTimeScatter.tsx +0 -96
- package/src/client/components/analytics/charts/SessionBubbleChart.tsx +0 -114
- package/src/client/components/analytics/charts/SessionComplexityList.tsx +0 -65
- package/src/client/components/analytics/charts/SessionTimeline.tsx +0 -107
- package/src/client/components/analytics/charts/TokenFlowChart.tsx +0 -78
- package/src/client/components/analytics/charts/TokenSankeyChart.tsx +0 -93
- package/src/client/components/analytics/charts/ToolSunburst.tsx +0 -123
- package/src/client/components/analytics/charts/ToolTreemap.tsx +0 -110
- package/src/client/components/auth/PassphrasePrompt.tsx +0 -70
- package/src/client/components/chat/AttachmentChips.tsx +0 -116
- package/src/client/components/chat/ChatInput.tsx +0 -533
- package/src/client/components/chat/ChatView.tsx +0 -1076
- package/src/client/components/chat/CommandPalette.tsx +0 -162
- package/src/client/components/chat/ElicitationCard.tsx +0 -238
- package/src/client/components/chat/Message.tsx +0 -825
- package/src/client/components/chat/ModelSelector.tsx +0 -108
- package/src/client/components/chat/PermissionModeSelector.tsx +0 -41
- package/src/client/components/chat/PromptQuestion.tsx +0 -271
- package/src/client/components/chat/StatusBar.tsx +0 -50
- package/src/client/components/chat/TodoCard.tsx +0 -57
- package/src/client/components/chat/ToolGroup.tsx +0 -129
- package/src/client/components/chat/ToolResultRenderer.tsx +0 -348
- package/src/client/components/chat/VoiceRecorder.tsx +0 -85
- package/src/client/components/chat/toolSummary.ts +0 -41
- package/src/client/components/dashboard/DashboardView.tsx +0 -200
- package/src/client/components/dashboard/ProjectDashboardView.tsx +0 -179
- package/src/client/components/mesh/NodeBadge.tsx +0 -24
- package/src/client/components/mesh/PairingDialog.tsx +0 -340
- package/src/client/components/project-settings/ProjectClaude.tsx +0 -318
- package/src/client/components/project-settings/ProjectEnvironment.tsx +0 -235
- package/src/client/components/project-settings/ProjectGeneral.tsx +0 -76
- package/src/client/components/project-settings/ProjectMcp.tsx +0 -232
- package/src/client/components/project-settings/ProjectMemory.tsx +0 -488
- package/src/client/components/project-settings/ProjectNotifications.tsx +0 -48
- package/src/client/components/project-settings/ProjectPermissions.tsx +0 -209
- package/src/client/components/project-settings/ProjectPlugins.tsx +0 -117
- package/src/client/components/project-settings/ProjectRules.tsx +0 -286
- package/src/client/components/project-settings/ProjectSettingsView.tsx +0 -117
- package/src/client/components/project-settings/ProjectSkills.tsx +0 -91
- package/src/client/components/settings/Appearance.tsx +0 -275
- package/src/client/components/settings/BudgetSettings.tsx +0 -165
- package/src/client/components/settings/ClaudeSettings.tsx +0 -175
- package/src/client/components/settings/Editor.tsx +0 -123
- package/src/client/components/settings/Environment.tsx +0 -185
- package/src/client/components/settings/GlobalMcp.tsx +0 -216
- package/src/client/components/settings/GlobalMemory.tsx +0 -19
- package/src/client/components/settings/GlobalPlugins.tsx +0 -806
- package/src/client/components/settings/GlobalRules.tsx +0 -149
- package/src/client/components/settings/GlobalSkills.tsx +0 -140
- package/src/client/components/settings/MeshStatus.tsx +0 -183
- package/src/client/components/settings/Notifications.tsx +0 -123
- package/src/client/components/settings/SettingsView.tsx +0 -75
- package/src/client/components/settings/SkillMarketplace.tsx +0 -175
- package/src/client/components/settings/ThemePreview.tsx +0 -140
- package/src/client/components/settings/ThemeWizard.tsx +0 -405
- package/src/client/components/settings/mcp-shared.tsx +0 -194
- package/src/client/components/settings/skill-shared.tsx +0 -186
- package/src/client/components/setup/SetupWizard.tsx +0 -755
- package/src/client/components/sidebar/AddProjectModal.tsx +0 -438
- package/src/client/components/sidebar/NodeSettingsModal.tsx +0 -206
- package/src/client/components/sidebar/ProjectDropdown.tsx +0 -211
- package/src/client/components/sidebar/ProjectRail.tsx +0 -353
- package/src/client/components/sidebar/SearchFilter.tsx +0 -52
- package/src/client/components/sidebar/SessionList.tsx +0 -599
- package/src/client/components/sidebar/SettingsSidebar.tsx +0 -139
- package/src/client/components/sidebar/Sidebar.tsx +0 -469
- package/src/client/components/sidebar/UserIsland.tsx +0 -282
- package/src/client/components/sidebar/UserMenu.tsx +0 -107
- package/src/client/components/ui/CommandPalette.tsx +0 -321
- package/src/client/components/ui/ContextMenu.tsx +0 -153
- package/src/client/components/ui/ErrorBoundary.tsx +0 -56
- package/src/client/components/ui/IconPicker.tsx +0 -184
- package/src/client/components/ui/KeyboardShortcuts.tsx +0 -129
- package/src/client/components/ui/LatticeLogomark.tsx +0 -19
- package/src/client/components/ui/NodeDisconnectedOverlay.tsx +0 -35
- package/src/client/components/ui/PopupMenu.tsx +0 -120
- package/src/client/components/ui/SaveFooter.tsx +0 -63
- package/src/client/components/ui/Toast.tsx +0 -132
- package/src/client/components/ui/UpdateBanner.tsx +0 -110
- package/src/client/components/ui/UpdatePrompt.tsx +0 -47
- package/src/client/components/workspace/BookmarksView.tsx +0 -156
- package/src/client/components/workspace/FileBrowser.tsx +0 -174
- package/src/client/components/workspace/FileTree.tsx +0 -129
- package/src/client/components/workspace/FileViewer.tsx +0 -211
- package/src/client/components/workspace/NoteCard.tsx +0 -120
- package/src/client/components/workspace/NotesView.tsx +0 -102
- package/src/client/components/workspace/ScheduledTasksView.tsx +0 -117
- package/src/client/components/workspace/SplitPane.tsx +0 -81
- package/src/client/components/workspace/TabBar.tsx +0 -170
- package/src/client/components/workspace/TaskCard.tsx +0 -159
- package/src/client/components/workspace/TaskEditModal.tsx +0 -129
- package/src/client/components/workspace/TerminalInstance.tsx +0 -171
- package/src/client/components/workspace/TerminalView.tsx +0 -110
- package/src/client/components/workspace/WorkspaceView.tsx +0 -141
- package/src/client/hooks/useAnalytics.ts +0 -84
- package/src/client/hooks/useAttachments.ts +0 -313
- package/src/client/hooks/useBookmarks.ts +0 -57
- package/src/client/hooks/useEditorConfig.ts +0 -28
- package/src/client/hooks/useFocusTrap.ts +0 -74
- package/src/client/hooks/useIdleDetection.ts +0 -50
- package/src/client/hooks/useInstallPrompt.ts +0 -53
- package/src/client/hooks/useMesh.ts +0 -89
- package/src/client/hooks/useNotifications.ts +0 -54
- package/src/client/hooks/useOnline.ts +0 -6
- package/src/client/hooks/useProjectSettings.ts +0 -56
- package/src/client/hooks/useProjects.ts +0 -98
- package/src/client/hooks/usePushNotifications.ts +0 -92
- package/src/client/hooks/useSaveState.ts +0 -65
- package/src/client/hooks/useSession.ts +0 -580
- package/src/client/hooks/useSidebar.ts +0 -90
- package/src/client/hooks/useSkills.ts +0 -30
- package/src/client/hooks/useSpinnerVerb.ts +0 -36
- package/src/client/hooks/useSwipeDrawer.ts +0 -299
- package/src/client/hooks/useTheme.ts +0 -114
- package/src/client/hooks/useTimeTick.ts +0 -35
- package/src/client/hooks/useVoiceRecorder.ts +0 -169
- package/src/client/hooks/useWebSocket.ts +0 -27
- package/src/client/hooks/useWorkspace.ts +0 -57
- package/src/client/lib/theme-derive.ts +0 -196
- package/src/client/lib/workspace-url.ts +0 -219
- package/src/client/main.tsx +0 -10
- package/src/client/providers/WebSocketProvider.tsx +0 -186
- package/src/client/router.tsx +0 -578
- package/src/client/stores/analytics.ts +0 -68
- package/src/client/stores/bookmarks.ts +0 -45
- package/src/client/stores/mesh.ts +0 -78
- package/src/client/stores/session.ts +0 -569
- package/src/client/stores/sidebar.ts +0 -530
- package/src/client/stores/theme.ts +0 -44
- package/src/client/stores/workspace.ts +0 -518
- package/src/client/styles/global.css +0 -391
- package/src/client/styles/theme-vars.css +0 -18
- package/src/client/themes/index.ts +0 -105
- package/src/client/utils/editorUrl.ts +0 -55
- package/src/client/utils/findDuplicateKeys.ts +0 -12
- package/src/client/utils/formatSessionTitle.ts +0 -17
- package/src/client/vite-env.d.ts +0 -6
- package/src/server/analytics/engine.ts +0 -920
- package/src/server/assets.ts +0 -45
- package/src/server/auth/passphrase.ts +0 -78
- package/src/server/config.ts +0 -55
- package/src/server/daemon.ts +0 -567
- package/src/server/features/ralph-loop.ts +0 -173
- package/src/server/features/scheduler.ts +0 -304
- package/src/server/features/sticky-notes.ts +0 -104
- package/src/server/handlers/analytics.ts +0 -39
- package/src/server/handlers/attachment.ts +0 -189
- package/src/server/handlers/bookmarks.ts +0 -50
- package/src/server/handlers/chat.ts +0 -381
- package/src/server/handlers/editor.ts +0 -76
- package/src/server/handlers/fs.ts +0 -251
- package/src/server/handlers/loop.ts +0 -37
- package/src/server/handlers/memory.ts +0 -182
- package/src/server/handlers/mesh.ts +0 -362
- package/src/server/handlers/notes.ts +0 -47
- package/src/server/handlers/plugins.ts +0 -655
- package/src/server/handlers/project-settings.ts +0 -180
- package/src/server/handlers/scheduler.ts +0 -64
- package/src/server/handlers/session.ts +0 -226
- package/src/server/handlers/settings.ts +0 -157
- package/src/server/handlers/skills.ts +0 -378
- package/src/server/handlers/terminal.ts +0 -88
- package/src/server/handlers/themes.ts +0 -121
- package/src/server/handlers/update.ts +0 -133
- package/src/server/identity.ts +0 -56
- package/src/server/index.ts +0 -457
- package/src/server/logger.ts +0 -21
- package/src/server/mesh/connector.ts +0 -419
- package/src/server/mesh/crypto.ts +0 -106
- package/src/server/mesh/discovery.ts +0 -126
- package/src/server/mesh/pairing.ts +0 -123
- package/src/server/mesh/peers.ts +0 -60
- package/src/server/mesh/proxy.ts +0 -106
- package/src/server/mesh/session-sync.ts +0 -107
- package/src/server/project/bookmarks.ts +0 -83
- package/src/server/project/context-breakdown.ts +0 -307
- package/src/server/project/file-browser.ts +0 -106
- package/src/server/project/project-files.ts +0 -267
- package/src/server/project/pty-worker.cjs +0 -83
- package/src/server/project/registry.ts +0 -57
- package/src/server/project/sdk-bridge.ts +0 -1100
- package/src/server/project/session.ts +0 -723
- package/src/server/project/terminal.ts +0 -111
- package/src/server/project/warmup.ts +0 -285
- package/src/server/push.ts +0 -121
- package/src/server/tls.ts +0 -65
- package/src/server/tui.ts +0 -103
- package/src/server/update-checker.ts +0 -147
- package/src/server/ws/broadcast.ts +0 -61
- package/src/server/ws/router.ts +0 -123
- package/src/server/ws/server.ts +0 -2
- package/src/shared/analytics.ts +0 -40
- package/src/shared/messages.ts +0 -1302
- package/src/shared/models.ts +0 -255
- package/src/shared/project-settings.ts +0 -45
- package/tsconfig.json +0 -25
- package/vite.config.ts +0 -71
- /package/{src/server/runtime.ts → dist/server/runtime.js} +0 -0
- /package/{src/shared/constants.ts → dist/shared/constants.js} +0 -0
- /package/{src/shared/index.ts → dist/shared/index.js} +0 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { getPeerConnection } from "./connector.js";
|
|
3
|
+
import { sendTo, registerVirtualClient, removeVirtualClient } from "../ws/broadcast.js";
|
|
4
|
+
import { routeMessage } from "../ws/router.js";
|
|
5
|
+
import { log } from "../logger.js";
|
|
6
|
+
var pendingRequests = new Map();
|
|
7
|
+
export function proxyToRemoteNode(nodeId, projectSlug, clientId, message) {
|
|
8
|
+
log.meshProxy("→ proxy %s to node %s for project %s", message.type, nodeId.slice(0, 8), projectSlug);
|
|
9
|
+
var ws = getPeerConnection(nodeId);
|
|
10
|
+
if (!ws) {
|
|
11
|
+
log.meshProxy(" ✗ no connection to node %s", nodeId.slice(0, 8));
|
|
12
|
+
sendTo(clientId, { type: "chat:error", message: "Remote node is not connected" });
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
var requestId = randomUUID();
|
|
16
|
+
pendingRequests.set(requestId, clientId);
|
|
17
|
+
log.meshProxy(" envelope requestId=%s", requestId.slice(0, 8));
|
|
18
|
+
var envelope = {
|
|
19
|
+
type: "mesh:proxy_request",
|
|
20
|
+
projectSlug: projectSlug,
|
|
21
|
+
requestId: requestId,
|
|
22
|
+
payload: message,
|
|
23
|
+
};
|
|
24
|
+
ws.send(JSON.stringify(envelope));
|
|
25
|
+
}
|
|
26
|
+
export function handleProxyRequest(sourceNodeId, msg) {
|
|
27
|
+
var proxyClientId = "mesh-proxy:" + sourceNodeId + ":" + msg.requestId;
|
|
28
|
+
log.meshProxy("← proxy_request from %s: %s for %s (reqId=%s)", sourceNodeId.slice(0, 8), msg.payload.type, msg.projectSlug, msg.requestId.slice(0, 8));
|
|
29
|
+
registerVirtualClient(proxyClientId, function (response) {
|
|
30
|
+
log.meshProxy(" → proxy_response %s back to %s", response.type, sourceNodeId.slice(0, 8));
|
|
31
|
+
var ws = getPeerConnection(sourceNodeId);
|
|
32
|
+
if (!ws) {
|
|
33
|
+
console.warn("[mesh/proxy] Cannot send response, no connection to: " + sourceNodeId);
|
|
34
|
+
removeVirtualClient(proxyClientId);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
var envelope = {
|
|
38
|
+
type: "mesh:proxy_response",
|
|
39
|
+
projectSlug: msg.projectSlug,
|
|
40
|
+
requestId: msg.requestId,
|
|
41
|
+
payload: response,
|
|
42
|
+
};
|
|
43
|
+
ws.send(JSON.stringify(envelope));
|
|
44
|
+
removeVirtualClient(proxyClientId);
|
|
45
|
+
});
|
|
46
|
+
routeMessage(proxyClientId, msg.payload);
|
|
47
|
+
}
|
|
48
|
+
export function handleProxyResponse(msg) {
|
|
49
|
+
log.meshProxy("← proxy_response %s (reqId=%s)", msg.payload.type, msg.requestId.slice(0, 8));
|
|
50
|
+
var clientId = pendingRequests.get(msg.requestId);
|
|
51
|
+
if (!clientId) {
|
|
52
|
+
log.meshProxy(" ✗ no pending request for %s", msg.requestId.slice(0, 8));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
pendingRequests.delete(msg.requestId);
|
|
56
|
+
sendTo(clientId, msg.payload);
|
|
57
|
+
}
|
|
58
|
+
var proxyHandlers = new Map();
|
|
59
|
+
export function registerProxyAwareHandler(prefix, handler) {
|
|
60
|
+
proxyHandlers.set(prefix, handler);
|
|
61
|
+
}
|
|
62
|
+
function proxyRouteMessage(clientId, message, sendToFn) {
|
|
63
|
+
var prefix = message.type.split(":")[0];
|
|
64
|
+
var proxyHandler = proxyHandlers.get(prefix);
|
|
65
|
+
if (proxyHandler) {
|
|
66
|
+
proxyHandler(clientId, message, sendToFn);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
routeMessage(clientId, message);
|
|
70
|
+
}
|
|
71
|
+
export function getProxySendTo(requestId, sourceNodeId) {
|
|
72
|
+
var clientId = pendingRequests.get(requestId);
|
|
73
|
+
if (clientId !== undefined) {
|
|
74
|
+
var resolvedClientId = clientId;
|
|
75
|
+
return function (msg) {
|
|
76
|
+
sendTo(resolvedClientId, msg);
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return function (msg) {
|
|
80
|
+
var ws = getPeerConnection(sourceNodeId);
|
|
81
|
+
if (!ws) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
ws.send(JSON.stringify(msg));
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, appendFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { getConnectedPeerIds, getPeerConnection } from "./connector.js";
|
|
5
|
+
import { getLatticeHome } from "../config.js";
|
|
6
|
+
var syncOffsets = new Map();
|
|
7
|
+
function getSyncKey(nodeId, sessionId) {
|
|
8
|
+
return nodeId + ":" + sessionId;
|
|
9
|
+
}
|
|
10
|
+
function getRemoteSessionsDir(nodeId, projectSlug) {
|
|
11
|
+
var dir = join(getLatticeHome(), "remote-sessions", nodeId, projectSlug);
|
|
12
|
+
if (!existsSync(dir)) {
|
|
13
|
+
mkdirSync(dir, { recursive: true });
|
|
14
|
+
}
|
|
15
|
+
return dir;
|
|
16
|
+
}
|
|
17
|
+
function getSessionFilePath(projectPath, sessionId) {
|
|
18
|
+
var hash = projectPath.replace(/\//g, "-");
|
|
19
|
+
return join(homedir(), ".claude", "projects", hash, sessionId + ".jsonl");
|
|
20
|
+
}
|
|
21
|
+
export function syncSessionToPeers(projectPath, projectSlug, sessionId) {
|
|
22
|
+
var filePath = getSessionFilePath(projectPath, sessionId);
|
|
23
|
+
if (!existsSync(filePath)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
var content = readFileSync(filePath, "utf-8");
|
|
27
|
+
var peerIds = getConnectedPeerIds();
|
|
28
|
+
for (var i = 0; i < peerIds.length; i++) {
|
|
29
|
+
var nodeId = peerIds[i];
|
|
30
|
+
var key = getSyncKey(nodeId, sessionId);
|
|
31
|
+
var lastOffset = syncOffsets.get(key) || 0;
|
|
32
|
+
if (content.length <= lastOffset) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
var newContent = content.slice(lastOffset);
|
|
36
|
+
var newLines = newContent.split("\n").filter(function (l) { return l.trim().length > 0; });
|
|
37
|
+
if (newLines.length === 0) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
var ws = getPeerConnection(nodeId);
|
|
41
|
+
if (!ws) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
var msg = {
|
|
45
|
+
type: "mesh:session_sync",
|
|
46
|
+
projectSlug,
|
|
47
|
+
sessionId,
|
|
48
|
+
lines: newLines,
|
|
49
|
+
offset: lastOffset,
|
|
50
|
+
};
|
|
51
|
+
ws.send(JSON.stringify(msg));
|
|
52
|
+
syncOffsets.set(key, content.length);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export function handleSessionSync(nodeId, msg) {
|
|
56
|
+
var dir = getRemoteSessionsDir(nodeId, msg.projectSlug);
|
|
57
|
+
var filePath = join(dir, msg.sessionId + ".jsonl");
|
|
58
|
+
for (var i = 0; i < msg.lines.length; i++) {
|
|
59
|
+
appendFileSync(filePath, msg.lines[i] + "\n", "utf-8");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export function handleSessionRequest(nodeId, msg, projectPath) {
|
|
63
|
+
var filePath = getSessionFilePath(projectPath, msg.sessionId);
|
|
64
|
+
if (!existsSync(filePath)) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
var content = readFileSync(filePath, "utf-8");
|
|
68
|
+
var newContent = content.slice(msg.fromOffset);
|
|
69
|
+
var lines = newContent.split("\n").filter(function (l) { return l.trim().length > 0; });
|
|
70
|
+
if (lines.length === 0) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
var ws = getPeerConnection(nodeId);
|
|
74
|
+
if (!ws) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
var syncMsg = {
|
|
78
|
+
type: "mesh:session_sync",
|
|
79
|
+
projectSlug: msg.projectSlug,
|
|
80
|
+
sessionId: msg.sessionId,
|
|
81
|
+
lines,
|
|
82
|
+
offset: msg.fromOffset,
|
|
83
|
+
};
|
|
84
|
+
ws.send(JSON.stringify(syncMsg));
|
|
85
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { randomBytes } from "node:crypto";
|
|
4
|
+
import { getLatticeHome } from "../config.js";
|
|
5
|
+
var bookmarksFile = "";
|
|
6
|
+
var bookmarks = [];
|
|
7
|
+
function getBookmarksPath() {
|
|
8
|
+
if (!bookmarksFile) {
|
|
9
|
+
bookmarksFile = join(getLatticeHome(), "bookmarks.json");
|
|
10
|
+
}
|
|
11
|
+
return bookmarksFile;
|
|
12
|
+
}
|
|
13
|
+
export function loadBookmarks() {
|
|
14
|
+
var path = getBookmarksPath();
|
|
15
|
+
if (!existsSync(path)) {
|
|
16
|
+
bookmarks = [];
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
var raw = readFileSync(path, "utf-8");
|
|
21
|
+
bookmarks = JSON.parse(raw);
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
console.error("[bookmarks] Failed to load bookmarks:", err);
|
|
25
|
+
bookmarks = [];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function saveBookmarks() {
|
|
29
|
+
var path = getBookmarksPath();
|
|
30
|
+
var dir = join(path, "..");
|
|
31
|
+
if (!existsSync(dir)) {
|
|
32
|
+
mkdirSync(dir, { recursive: true });
|
|
33
|
+
}
|
|
34
|
+
var tmp = path + ".tmp";
|
|
35
|
+
try {
|
|
36
|
+
writeFileSync(tmp, JSON.stringify(bookmarks, null, 2));
|
|
37
|
+
renameSync(tmp, path);
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
console.error("[bookmarks] Failed to save bookmarks:", err);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export function listBookmarks(projectSlug, sessionId) {
|
|
44
|
+
var result = bookmarks;
|
|
45
|
+
if (projectSlug) {
|
|
46
|
+
result = result.filter(function (b) { return b.projectSlug === projectSlug; });
|
|
47
|
+
}
|
|
48
|
+
if (sessionId) {
|
|
49
|
+
result = result.filter(function (b) { return b.sessionId === sessionId; });
|
|
50
|
+
}
|
|
51
|
+
return result.slice();
|
|
52
|
+
}
|
|
53
|
+
export function addBookmark(bookmark) {
|
|
54
|
+
var now = Date.now();
|
|
55
|
+
var entry = {
|
|
56
|
+
id: "bm_" + now + "_" + randomBytes(3).toString("hex"),
|
|
57
|
+
sessionId: bookmark.sessionId,
|
|
58
|
+
projectSlug: bookmark.projectSlug,
|
|
59
|
+
messageUuid: bookmark.messageUuid,
|
|
60
|
+
messageText: bookmark.messageText.slice(0, 100),
|
|
61
|
+
messageType: bookmark.messageType,
|
|
62
|
+
createdAt: now,
|
|
63
|
+
};
|
|
64
|
+
bookmarks.push(entry);
|
|
65
|
+
saveBookmarks();
|
|
66
|
+
return entry;
|
|
67
|
+
}
|
|
68
|
+
export function removeBookmark(id) {
|
|
69
|
+
for (var i = 0; i < bookmarks.length; i++) {
|
|
70
|
+
if (bookmarks[i].id === id) {
|
|
71
|
+
bookmarks.splice(i, 1);
|
|
72
|
+
saveBookmarks();
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { encodingForModel } from "js-tiktoken";
|
|
2
|
+
import { existsSync, readFileSync, readdirSync, openSync, readSync, fstatSync, closeSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { guessContextWindow } from "./session.js";
|
|
6
|
+
import { loadConfig } from "../config.js";
|
|
7
|
+
import { getInstalledPluginCount, getPluginSkillRuleTokenEstimate } from "../handlers/plugins.js";
|
|
8
|
+
var encoder = encodingForModel("gpt-4o");
|
|
9
|
+
function countTokens(text) {
|
|
10
|
+
if (!text)
|
|
11
|
+
return 0;
|
|
12
|
+
return encoder.encode(text).length;
|
|
13
|
+
}
|
|
14
|
+
function readFileSafe(path) {
|
|
15
|
+
try {
|
|
16
|
+
if (existsSync(path))
|
|
17
|
+
return readFileSync(path, "utf-8");
|
|
18
|
+
}
|
|
19
|
+
catch { }
|
|
20
|
+
return "";
|
|
21
|
+
}
|
|
22
|
+
function readDirFiles(dirPath) {
|
|
23
|
+
try {
|
|
24
|
+
if (!existsSync(dirPath))
|
|
25
|
+
return "";
|
|
26
|
+
var files = readdirSync(dirPath, { withFileTypes: true });
|
|
27
|
+
var content = "";
|
|
28
|
+
for (var i = 0; i < files.length; i++) {
|
|
29
|
+
if (files[i].isFile()) {
|
|
30
|
+
content += readFileSafe(join(dirPath, files[i].name)) + "\n";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return content;
|
|
34
|
+
}
|
|
35
|
+
catch { }
|
|
36
|
+
return "";
|
|
37
|
+
}
|
|
38
|
+
function projectPathToHash(projectPath) {
|
|
39
|
+
return projectPath.replace(/\//g, "-");
|
|
40
|
+
}
|
|
41
|
+
function getProjectPath(projectSlug) {
|
|
42
|
+
var config = loadConfig();
|
|
43
|
+
var project = config.projects.find(function (p) { return p.slug === projectSlug; });
|
|
44
|
+
return project ? project.path : null;
|
|
45
|
+
}
|
|
46
|
+
// Known built-in Claude Code tools with approximate per-tool token counts
|
|
47
|
+
// These are the tool definitions sent in every API request
|
|
48
|
+
var BUILTIN_TOOLS = {
|
|
49
|
+
"Read": 350,
|
|
50
|
+
"Write": 300,
|
|
51
|
+
"Edit": 400,
|
|
52
|
+
"Bash": 500,
|
|
53
|
+
"Glob": 250,
|
|
54
|
+
"Grep": 450,
|
|
55
|
+
"Agent": 600,
|
|
56
|
+
"WebFetch": 400,
|
|
57
|
+
"WebSearch": 300,
|
|
58
|
+
"TodoWrite": 300,
|
|
59
|
+
"NotebookEdit": 350,
|
|
60
|
+
"AskUserQuestion": 400,
|
|
61
|
+
"Skill": 350,
|
|
62
|
+
"TaskOutput": 200,
|
|
63
|
+
"TaskStop": 150,
|
|
64
|
+
"EnterPlanMode": 200,
|
|
65
|
+
"ExitPlanMode": 150,
|
|
66
|
+
"EnterWorktree": 200,
|
|
67
|
+
"ExitWorktree": 150,
|
|
68
|
+
"CronCreate": 250,
|
|
69
|
+
"CronDelete": 200,
|
|
70
|
+
"CronList": 150,
|
|
71
|
+
"ToolSearch": 250,
|
|
72
|
+
};
|
|
73
|
+
// Average tokens per MCP tool definition (name + description + JSON schema)
|
|
74
|
+
var MCP_TOOL_AVG_TOKENS = 250;
|
|
75
|
+
function extractToolsFromSession(lines) {
|
|
76
|
+
var builtinSet = new Set();
|
|
77
|
+
var mcpMap = new Map();
|
|
78
|
+
// First: check compact boundary metadata for preCompactDiscoveredTools
|
|
79
|
+
for (var i = 0; i < lines.length; i++) {
|
|
80
|
+
var line = lines[i].trim();
|
|
81
|
+
if (!line || !line.includes("compactMetadata"))
|
|
82
|
+
continue;
|
|
83
|
+
try {
|
|
84
|
+
var parsed = JSON.parse(line);
|
|
85
|
+
var tools = parsed.compactMetadata?.preCompactDiscoveredTools;
|
|
86
|
+
if (Array.isArray(tools)) {
|
|
87
|
+
for (var t = 0; t < tools.length; t++) {
|
|
88
|
+
categorizeToolName(tools[t], builtinSet, mcpMap);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch { }
|
|
93
|
+
}
|
|
94
|
+
// Second: scan tool_use blocks from assistant messages for any we missed
|
|
95
|
+
for (var j = 0; j < lines.length; j++) {
|
|
96
|
+
var aLine = lines[j].trim();
|
|
97
|
+
if (!aLine || !aLine.includes("tool_use"))
|
|
98
|
+
continue;
|
|
99
|
+
try {
|
|
100
|
+
var aParsed = JSON.parse(aLine);
|
|
101
|
+
if (aParsed.type === "assistant" && aParsed.message && Array.isArray(aParsed.message.content)) {
|
|
102
|
+
for (var k = 0; k < aParsed.message.content.length; k++) {
|
|
103
|
+
var block = aParsed.message.content[k];
|
|
104
|
+
if (block.type === "tool_use" && block.name) {
|
|
105
|
+
categorizeToolName(block.name, builtinSet, mcpMap);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch { }
|
|
111
|
+
}
|
|
112
|
+
// If we found no tools at all, use the default known set
|
|
113
|
+
if (builtinSet.size === 0 && mcpMap.size === 0) {
|
|
114
|
+
return {
|
|
115
|
+
builtinTools: Object.keys(BUILTIN_TOOLS),
|
|
116
|
+
mcpTools: new Map(),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
builtinTools: Array.from(builtinSet),
|
|
121
|
+
mcpTools: new Map(Array.from(mcpMap.entries()).map(function (entry) {
|
|
122
|
+
return [entry[0], Array.from(entry[1])];
|
|
123
|
+
})),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function categorizeToolName(name, builtinSet, mcpMap) {
|
|
127
|
+
if (name.startsWith("mcp__")) {
|
|
128
|
+
var parts = name.split("__");
|
|
129
|
+
var serverName = parts[1] || "unknown";
|
|
130
|
+
if (!mcpMap.has(serverName)) {
|
|
131
|
+
mcpMap.set(serverName, new Set());
|
|
132
|
+
}
|
|
133
|
+
mcpMap.get(serverName).add(name);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
builtinSet.add(name);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function estimateBuiltinToolTokens(toolNames) {
|
|
140
|
+
var total = 0;
|
|
141
|
+
for (var i = 0; i < toolNames.length; i++) {
|
|
142
|
+
total += BUILTIN_TOOLS[toolNames[i]] || 300;
|
|
143
|
+
}
|
|
144
|
+
// Also include tools that are always sent but might not appear in usage
|
|
145
|
+
var knownKeys = Object.keys(BUILTIN_TOOLS);
|
|
146
|
+
for (var j = 0; j < knownKeys.length; j++) {
|
|
147
|
+
if (toolNames.indexOf(knownKeys[j]) === -1) {
|
|
148
|
+
total += BUILTIN_TOOLS[knownKeys[j]];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return total;
|
|
152
|
+
}
|
|
153
|
+
export async function getContextBreakdown(projectSlug, sessionId) {
|
|
154
|
+
var projectPath = getProjectPath(projectSlug);
|
|
155
|
+
if (!projectPath)
|
|
156
|
+
return null;
|
|
157
|
+
var home = homedir();
|
|
158
|
+
var hash = projectPathToHash(projectPath);
|
|
159
|
+
var sessionFile = join(home, ".claude", "projects", hash, sessionId + ".jsonl");
|
|
160
|
+
if (!existsSync(sessionFile))
|
|
161
|
+
return null;
|
|
162
|
+
// Read instruction files
|
|
163
|
+
var globalClaudeMd = readFileSafe(join(home, ".claude", "CLAUDE.md"));
|
|
164
|
+
var globalRulesContent = readDirFiles(join(home, ".claude", "rules"));
|
|
165
|
+
var projectClaudeMd = readFileSafe(join(projectPath, "CLAUDE.md"));
|
|
166
|
+
var projectLocalClaudeMd = readFileSafe(join(home, ".claude", "projects", hash, "CLAUDE.md"));
|
|
167
|
+
var memoryContent = readDirFiles(join(home, ".claude", "projects", hash, "memory"));
|
|
168
|
+
var memoryIndex = readFileSafe(join(home, ".claude", "projects", hash, "MEMORY.md"));
|
|
169
|
+
var instructionsTokens = countTokens(globalClaudeMd + globalRulesContent + projectClaudeMd + projectLocalClaudeMd);
|
|
170
|
+
var memoryTokens = countTokens(memoryContent + memoryIndex);
|
|
171
|
+
// Parse session — read last 2MB for recent context (avoids reading 35MB+ files)
|
|
172
|
+
var fd = openSync(sessionFile, "r");
|
|
173
|
+
var fileStat = fstatSync(fd);
|
|
174
|
+
var readSize = Math.min(fileStat.size, 2 * 1024 * 1024);
|
|
175
|
+
var readBuf = Buffer.alloc(readSize);
|
|
176
|
+
readSync(fd, readBuf, 0, readSize, fileStat.size - readSize);
|
|
177
|
+
closeSync(fd);
|
|
178
|
+
var content = readBuf.toString("utf-8");
|
|
179
|
+
var lines = content.split("\n").filter(function (l) { return l.length > 0; });
|
|
180
|
+
// Extract tool info
|
|
181
|
+
var toolCounts = extractToolsFromSession(lines);
|
|
182
|
+
var builtinToolTokens = estimateBuiltinToolTokens(toolCounts.builtinTools);
|
|
183
|
+
// Parse conversation messages
|
|
184
|
+
var userText = "";
|
|
185
|
+
var assistantText = "";
|
|
186
|
+
var toolResultText = "";
|
|
187
|
+
var contextWindow = 0;
|
|
188
|
+
var lastModel = "";
|
|
189
|
+
for (var i = 0; i < lines.length; i++) {
|
|
190
|
+
var line = lines[i].trim();
|
|
191
|
+
if (!line)
|
|
192
|
+
continue;
|
|
193
|
+
try {
|
|
194
|
+
var parsed = JSON.parse(line);
|
|
195
|
+
if (parsed.type === "user" && parsed.message) {
|
|
196
|
+
var userContent = parsed.message.content;
|
|
197
|
+
if (typeof userContent === "string") {
|
|
198
|
+
userText += userContent + "\n";
|
|
199
|
+
}
|
|
200
|
+
else if (Array.isArray(userContent)) {
|
|
201
|
+
for (var j = 0; j < userContent.length; j++) {
|
|
202
|
+
var block = userContent[j];
|
|
203
|
+
if (block.type === "text" && block.text) {
|
|
204
|
+
userText += block.text + "\n";
|
|
205
|
+
}
|
|
206
|
+
else if (block.type === "tool_result") {
|
|
207
|
+
if (typeof block.content === "string") {
|
|
208
|
+
toolResultText += block.content + "\n";
|
|
209
|
+
}
|
|
210
|
+
else if (Array.isArray(block.content)) {
|
|
211
|
+
for (var ri = 0; ri < block.content.length; ri++) {
|
|
212
|
+
if (block.content[ri].type === "text" && block.content[ri].text) {
|
|
213
|
+
toolResultText += block.content[ri].text + "\n";
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
else if (parsed.type === "assistant" && parsed.message) {
|
|
222
|
+
var aContent = parsed.message.content;
|
|
223
|
+
if (typeof aContent === "string") {
|
|
224
|
+
assistantText += aContent + "\n";
|
|
225
|
+
}
|
|
226
|
+
else if (Array.isArray(aContent)) {
|
|
227
|
+
for (var k = 0; k < aContent.length; k++) {
|
|
228
|
+
var ab = aContent[k];
|
|
229
|
+
if (ab.type === "text" && ab.text) {
|
|
230
|
+
assistantText += ab.text + "\n";
|
|
231
|
+
}
|
|
232
|
+
else if (ab.type === "tool_use" && ab.input) {
|
|
233
|
+
assistantText += JSON.stringify(ab.input) + "\n";
|
|
234
|
+
}
|
|
235
|
+
else if (ab.type === "thinking" && ab.thinking) {
|
|
236
|
+
assistantText += ab.thinking + "\n";
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (parsed.message.model) {
|
|
241
|
+
lastModel = parsed.message.model;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
catch { }
|
|
246
|
+
}
|
|
247
|
+
var userTokens = countTokens(userText);
|
|
248
|
+
var assistantTokens = countTokens(assistantText);
|
|
249
|
+
var toolResultTokens = countTokens(toolResultText);
|
|
250
|
+
contextWindow = guessContextWindow(lastModel);
|
|
251
|
+
var autocompactAt = Math.round(contextWindow * 0.9);
|
|
252
|
+
var systemPromptEstimate = 4500;
|
|
253
|
+
var segments = [
|
|
254
|
+
{ label: "System prompt", tokens: systemPromptEstimate, id: "system", estimated: true },
|
|
255
|
+
{ label: "Built-in tools (" + Object.keys(BUILTIN_TOOLS).length + ")", tokens: builtinToolTokens, id: "builtin_tools", estimated: true },
|
|
256
|
+
];
|
|
257
|
+
// Add per-MCP-server segments
|
|
258
|
+
toolCounts.mcpTools.forEach(function (tools, serverName) {
|
|
259
|
+
var mcpTokens = tools.length * MCP_TOOL_AVG_TOKENS;
|
|
260
|
+
segments.push({
|
|
261
|
+
label: serverName + " (" + tools.length + " tools)",
|
|
262
|
+
tokens: mcpTokens,
|
|
263
|
+
id: "mcp_" + serverName,
|
|
264
|
+
estimated: true,
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
var pluginCount = getInstalledPluginCount();
|
|
268
|
+
if (pluginCount > 0) {
|
|
269
|
+
var pluginTokens = getPluginSkillRuleTokenEstimate();
|
|
270
|
+
segments.push({
|
|
271
|
+
label: "Plugins (" + pluginCount + ")",
|
|
272
|
+
tokens: pluginTokens,
|
|
273
|
+
id: "plugins",
|
|
274
|
+
estimated: true,
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
segments.push({ label: "Instructions", tokens: instructionsTokens, id: "instructions", estimated: false }, { label: "Memory", tokens: memoryTokens, id: "memory", estimated: false }, { label: "Your messages", tokens: userTokens, id: "user", estimated: false }, { label: "Claude responses", tokens: assistantTokens, id: "assistant", estimated: false }, { label: "Tool results", tokens: toolResultTokens, id: "tool_results", estimated: false });
|
|
278
|
+
return { segments, contextWindow, autocompactAt };
|
|
279
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join, resolve, relative } from "node:path";
|
|
3
|
+
var MAX_FILE_SIZE = 512 * 1024;
|
|
4
|
+
export function validatePath(projectPath, relativePath) {
|
|
5
|
+
var resolved = resolve(projectPath, relativePath);
|
|
6
|
+
var normalizedRoot = resolve(projectPath);
|
|
7
|
+
if (!resolved.startsWith(normalizedRoot + "/") && resolved !== normalizedRoot) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
return resolved;
|
|
11
|
+
}
|
|
12
|
+
export function listDirectory(projectPath, relativePath) {
|
|
13
|
+
var fullPath = validatePath(projectPath, relativePath);
|
|
14
|
+
if (!fullPath) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
var entries = [];
|
|
18
|
+
var names;
|
|
19
|
+
try {
|
|
20
|
+
names = readdirSync(fullPath);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
for (var i = 0; i < names.length; i++) {
|
|
26
|
+
var name = names[i];
|
|
27
|
+
if (name.startsWith(".")) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
var entryFull = join(fullPath, name);
|
|
31
|
+
try {
|
|
32
|
+
var stat = statSync(entryFull);
|
|
33
|
+
var entryRelative = relative(projectPath, entryFull);
|
|
34
|
+
entries.push({
|
|
35
|
+
name: name,
|
|
36
|
+
path: entryRelative,
|
|
37
|
+
isDirectory: stat.isDirectory(),
|
|
38
|
+
size: stat.isDirectory() ? 0 : stat.size,
|
|
39
|
+
modifiedAt: stat.mtimeMs,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// skip entries we can't stat
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
entries.sort(function (a, b) {
|
|
47
|
+
if (a.isDirectory && !b.isDirectory)
|
|
48
|
+
return -1;
|
|
49
|
+
if (!a.isDirectory && b.isDirectory)
|
|
50
|
+
return 1;
|
|
51
|
+
return a.name.localeCompare(b.name);
|
|
52
|
+
});
|
|
53
|
+
return entries;
|
|
54
|
+
}
|
|
55
|
+
export function readFile(projectPath, relativePath) {
|
|
56
|
+
var fullPath = validatePath(projectPath, relativePath);
|
|
57
|
+
if (!fullPath) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
var stat;
|
|
61
|
+
try {
|
|
62
|
+
stat = statSync(fullPath);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
if (stat.size > MAX_FILE_SIZE) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
var buf;
|
|
71
|
+
try {
|
|
72
|
+
buf = readFileSync(fullPath);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
for (var i = 0; i < Math.min(buf.length, 8192); i++) {
|
|
78
|
+
var byte = buf[i];
|
|
79
|
+
if (byte === 0) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return buf.toString("utf-8");
|
|
84
|
+
}
|
|
85
|
+
export function writeFile(projectPath, relativePath, content) {
|
|
86
|
+
var fullPath = validatePath(projectPath, relativePath);
|
|
87
|
+
if (!fullPath) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
writeFileSync(fullPath, content, "utf-8");
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|