swayrouter 1.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/.env.example +43 -0
- package/CHANGELOG.md +132 -0
- package/LICENSE +30 -0
- package/README.id.md +633 -0
- package/README.md +628 -0
- package/cli/cli.js +388 -0
- package/cli/package.json +4 -0
- package/cli/src/cli/commands/xaiVideo.js +280 -0
- package/cli/src/cli/tray/SwayAvatar.svg +20 -0
- package/cli/src/cli/tray/autostart.js +351 -0
- package/cli/src/cli/tray/icon.ico +0 -0
- package/cli/src/cli/tray/icon.png +0 -0
- package/cli/src/cli/tray/tray.js +258 -0
- package/cli/src/cli/tray/tray.ps1 +129 -0
- package/cli/src/cli/tray/trayHost.js +157 -0
- package/cli/src/cli/tray/trayWin.js +83 -0
- package/cli/src/cli/utils/display.js +123 -0
- package/cli/src/cli/utils/input.js +138 -0
- package/cli/src/runtime/discover.js +153 -0
- package/cli/src/runtime/lifecycle.js +333 -0
- package/cli/src/runtime/runMenu.js +250 -0
- package/cli/src/runtime/uiAdapters.js +12 -0
- package/cli/src/runtime/update.js +130 -0
- package/dashboard/dist/assets/CliTools-Ch3gKuNw.js +24 -0
- package/dashboard/dist/assets/Combo-BBCldjWi.js +1 -0
- package/dashboard/dist/assets/ConsoleLog-wywAYcPT.js +6 -0
- package/dashboard/dist/assets/Dashboard-DxzyF41b.js +1 -0
- package/dashboard/dist/assets/Header-C_9Su9BF.js +1 -0
- package/dashboard/dist/assets/Keys-D0ufgcsc.js +1 -0
- package/dashboard/dist/assets/Login-BeKpipS_.js +1 -0
- package/dashboard/dist/assets/ManageApiKey-CVXsmW2B.js +1 -0
- package/dashboard/dist/assets/OAuthCallback-D_UZYcF6.js +1 -0
- package/dashboard/dist/assets/Provider-BU7JfTqm.js +4 -0
- package/dashboard/dist/assets/ProviderModelAccordion-BAifkfVR.js +1 -0
- package/dashboard/dist/assets/Proxy-CU15VJ--.js +1 -0
- package/dashboard/dist/assets/QuotaMonitor-HzGK7bcc.js +1 -0
- package/dashboard/dist/assets/Settings-Dt4y2dC0.js +1 -0
- package/dashboard/dist/assets/Setup-DSDUwU7N.js +1 -0
- package/dashboard/dist/assets/StatusBadge-1nAOyHU2.js +1 -0
- package/dashboard/dist/assets/SwayChat-Bup7up6D.js +10 -0
- package/dashboard/dist/assets/Usage-eWnrPQ_v.js +4 -0
- package/dashboard/dist/assets/accordion-DOOPDDgt.js +1 -0
- package/dashboard/dist/assets/admin-extras-api-CCdu5TFM.js +1 -0
- package/dashboard/dist/assets/api-keys-api-ifAC2Ok3.js +1 -0
- package/dashboard/dist/assets/card-CC0Omjcv.js +1 -0
- package/dashboard/dist/assets/chatStudio-C0zPz_Z_.js +2 -0
- package/dashboard/dist/assets/checkbox-7SZBrmbN.js +1 -0
- package/dashboard/dist/assets/connections-api-_N54UD3S.js +1 -0
- package/dashboard/dist/assets/copy-button-qBvM6H9z.js +1 -0
- package/dashboard/dist/assets/currency-api-SV9CBf5e.js +1 -0
- package/dashboard/dist/assets/flip-button-BGgkjtl0.js +1 -0
- package/dashboard/dist/assets/frame-cUiti6Lq.js +1 -0
- package/dashboard/dist/assets/icons-vendor-CUx7SB5V.js +541 -0
- package/dashboard/dist/assets/index-B6j-9zHy.js +10 -0
- package/dashboard/dist/assets/index-C-_l0yYz.css +1 -0
- package/dashboard/dist/assets/live-mode-CHShLY4E.js +1 -0
- package/dashboard/dist/assets/markdown-vendor-BY8e1gQ8.js +29 -0
- package/dashboard/dist/assets/motion-vendor-g5fpGzmJ.js +9 -0
- package/dashboard/dist/assets/oauth-callback-CqYQzyd7.js +1 -0
- package/dashboard/dist/assets/query-vendor-DVevaSVS.js +1 -0
- package/dashboard/dist/assets/react-vendor-xnYrwzsL.js +61 -0
- package/dashboard/dist/assets/ripple-button-l8aMiVVG.js +1 -0
- package/dashboard/dist/assets/segmented-CqmEnQjZ.js +1 -0
- package/dashboard/dist/assets/select-D8pUtMXp.js +1 -0
- package/dashboard/dist/assets/skeleton-7uJDiIXe.js +1 -0
- package/dashboard/dist/assets/table-D0M60Tu1.js +1 -0
- package/dashboard/dist/assets/tabs-C6YkuulG.js +1 -0
- package/dashboard/dist/assets/tunnel-api-DDPsBaDV.js +1 -0
- package/dashboard/dist/assets/ui-vendor-BuM9f2NY.js +17 -0
- package/dashboard/dist/image2/SwayAvatar.svg +20 -0
- package/dashboard/dist/index.html +32 -0
- package/dashboard/dist/logo/avatar.svg +1 -0
- package/dashboard/dist/logo/sway.svg +20 -0
- package/dashboard/dist/logo/swaychat.svg +20 -0
- package/dashboard/dist/providers/SwayCustom.svg +19 -0
- package/dashboard/dist/providers/alicode.svg +12 -0
- package/dashboard/dist/providers/anthropic.svg +11 -0
- package/dashboard/dist/providers/antigravity.svg +3 -0
- package/dashboard/dist/providers/azure.svg +5 -0
- package/dashboard/dist/providers/baidu.svg +3 -0
- package/dashboard/dist/providers/blackbox.svg +5 -0
- package/dashboard/dist/providers/byteplus.svg +3 -0
- package/dashboard/dist/providers/cerebras.svg +4 -0
- package/dashboard/dist/providers/chutes.svg +4 -0
- package/dashboard/dist/providers/claude.svg +3 -0
- package/dashboard/dist/providers/cline.svg +11 -0
- package/dashboard/dist/providers/cloudflare-ai.svg +4 -0
- package/dashboard/dist/providers/codebuddy.svg +11 -0
- package/dashboard/dist/providers/codex.svg +10 -0
- package/dashboard/dist/providers/commandcode.svg +3 -0
- package/dashboard/dist/providers/cursor.svg +3 -0
- package/dashboard/dist/providers/deepseek.svg +10 -0
- package/dashboard/dist/providers/featherless.svg +3 -0
- package/dashboard/dist/providers/fireworks.svg +3 -0
- package/dashboard/dist/providers/gemini.svg +3 -0
- package/dashboard/dist/providers/geminicli.svg +11 -0
- package/dashboard/dist/providers/github.svg +3 -0
- package/dashboard/dist/providers/grok.svg +3 -0
- package/dashboard/dist/providers/groq.svg +3 -0
- package/dashboard/dist/providers/hermesagent.svg +1 -0
- package/dashboard/dist/providers/kilocode.svg +15 -0
- package/dashboard/dist/providers/kimchi.svg +3 -0
- package/dashboard/dist/providers/kimi.svg +4 -0
- package/dashboard/dist/providers/kiro.svg +10 -0
- package/dashboard/dist/providers/meta.svg +3 -0
- package/dashboard/dist/providers/mimo.svg +10 -0
- package/dashboard/dist/providers/minimax.svg +3 -0
- package/dashboard/dist/providers/mistral.svg +3 -0
- package/dashboard/dist/providers/morph.svg +3 -0
- package/dashboard/dist/providers/nebius.svg +4 -0
- package/dashboard/dist/providers/nvidia.svg +3 -0
- package/dashboard/dist/providers/ollama.svg +3 -0
- package/dashboard/dist/providers/omp.svg +5 -0
- package/dashboard/dist/providers/openai.svg +3 -0
- package/dashboard/dist/providers/opencode.svg +3 -0
- package/dashboard/dist/providers/openrouter.svg +3 -0
- package/dashboard/dist/providers/perplexity.svg +3 -0
- package/dashboard/dist/providers/poolside.svg +36 -0
- package/dashboard/dist/providers/qoder.svg +11 -0
- package/dashboard/dist/providers/sumopod.svg +3 -0
- package/dashboard/dist/providers/tencent.svg +5 -0
- package/dashboard/dist/providers/together.svg +12 -0
- package/dashboard/dist/providers/trae.svg +3 -0
- package/dashboard/dist/providers/venice.svg +4 -0
- package/dashboard/dist/providers/vercel.svg +3 -0
- package/dashboard/dist/providers/vertex.svg +17 -0
- package/dashboard/dist/providers/windsurf.svg +10 -0
- package/dashboard/dist/providers/zai.svg +3 -0
- package/dashboard/tsconfig.json +13 -0
- package/package.json +87 -0
- package/src/config/appConstants.js +153 -0
- package/src/config/defaultThinkingSignature.js +7 -0
- package/src/config/errorConfig.js +117 -0
- package/src/config/grokCli.js +9 -0
- package/src/config/kiroConstants.js +235 -0
- package/src/config/mediaConfig.js +20 -0
- package/src/config/ollamaModels.js +18 -0
- package/src/config/providerModels.js +109 -0
- package/src/config/providers.js +17 -0
- package/src/config/runtimeConfig.js +84 -0
- package/src/dashboardGuard.js +254 -0
- package/src/executors/antigravity.js +389 -0
- package/src/executors/azure.js +49 -0
- package/src/executors/base.js +225 -0
- package/src/executors/codebuddy-cn.js +23 -0
- package/src/executors/codebuddy-intl.js +60 -0
- package/src/executors/codex.js +436 -0
- package/src/executors/commandcode.js +83 -0
- package/src/executors/cursor.js +1075 -0
- package/src/executors/default.js +294 -0
- package/src/executors/gemini-cli.js +88 -0
- package/src/executors/github.js +393 -0
- package/src/executors/grok-cli.js +510 -0
- package/src/executors/grok-web.js +342 -0
- package/src/executors/index.js +86 -0
- package/src/executors/kimchi.js +116 -0
- package/src/executors/kiro.js +1155 -0
- package/src/executors/ollama-local.js +14 -0
- package/src/executors/opencode-go.js +47 -0
- package/src/executors/opencode.js +31 -0
- package/src/executors/qoder.js +433 -0
- package/src/executors/trae.js +318 -0
- package/src/executors/vertex.js +151 -0
- package/src/executors/windsurf.js +555 -0
- package/src/executors/xiaomi-tokenplan.js +16 -0
- package/src/handlers/chatCore/nonStreamingHandler.js +370 -0
- package/src/handlers/chatCore/requestDetail.js +130 -0
- package/src/handlers/chatCore/sseToJsonHandler.js +318 -0
- package/src/handlers/chatCore/streamingHandler.js +250 -0
- package/src/handlers/chatCore.js +652 -0
- package/src/lib/auth/dashboardSession.js +83 -0
- package/src/lib/auth/loginLimiter.js +99 -0
- package/src/lib/cache/ttlCache.js +153 -0
- package/src/lib/consoleLogBuffer.js +127 -0
- package/src/lib/dataDir.js +45 -0
- package/src/lib/db/adapters/betterSqliteAdapter.js +36 -0
- package/src/lib/db/adapters/bunSqliteAdapter.js +47 -0
- package/src/lib/db/adapters/nodeSqliteAdapter.js +65 -0
- package/src/lib/db/adapters/runtimeHelpers.js +23 -0
- package/src/lib/db/adapters/sqljsAdapter.js +103 -0
- package/src/lib/db/backup.js +75 -0
- package/src/lib/db/driver.js +110 -0
- package/src/lib/db/helpers/jsonCol.js +18 -0
- package/src/lib/db/helpers/kvStore.js +48 -0
- package/src/lib/db/helpers/metaStore.js +32 -0
- package/src/lib/db/index.js +473 -0
- package/src/lib/db/migrate.js +267 -0
- package/src/lib/db/migrations/001-initial.js +12 -0
- package/src/lib/db/migrations/002-prune-headroom-pxpipe-settings.js +32 -0
- package/src/lib/db/migrations/004-request-details-trace-id.js +12 -0
- package/src/lib/db/migrations/005-request-details-payload-capture.js +11 -0
- package/src/lib/db/migrations/007-headroom-readd-settings.js +35 -0
- package/src/lib/db/migrations/008-account-model-locks.js +22 -0
- package/src/lib/db/migrations/009-warp-pool-lifecycle.js +5 -0
- package/src/lib/db/migrations/010-api-key-file-permissions.js +7 -0
- package/src/lib/db/migrations/011-remove-upstream-user-agent-profile.js +41 -0
- package/src/lib/db/migrations/012-remove-headroom-settings.js +33 -0
- package/src/lib/db/migrations/013-default-fill-first-routing.js +20 -0
- package/src/lib/db/migrations/014-normalize-fill-first-routing.js +37 -0
- package/src/lib/db/migrations/015-remove-ip-ban-tables.js +8 -0
- package/src/lib/db/migrations/016-prune-legacy-codebuddy-intl-models.js +25 -0
- package/src/lib/db/migrations/index.js +20 -0
- package/src/lib/db/nineRouterMigration.js +785 -0
- package/src/lib/db/paths.js +23 -0
- package/src/lib/db/repos/accountModelLocksRepo.js +74 -0
- package/src/lib/db/repos/aliasRepo.js +108 -0
- package/src/lib/db/repos/apiKeysRepo.js +204 -0
- package/src/lib/db/repos/combosRepo.js +85 -0
- package/src/lib/db/repos/connectionsRepo.js +522 -0
- package/src/lib/db/repos/disabledModelsRepo.js +63 -0
- package/src/lib/db/repos/nodesRepo.js +127 -0
- package/src/lib/db/repos/pricingRepo.js +108 -0
- package/src/lib/db/repos/proxyPoolsRepo.js +104 -0
- package/src/lib/db/repos/requestDetailsRepo.js +345 -0
- package/src/lib/db/repos/settingsRepo.js +135 -0
- package/src/lib/db/repos/usageRepo.js +1335 -0
- package/src/lib/db/schema.js +179 -0
- package/src/lib/db/version.js +32 -0
- package/src/lib/db/writeBehind.js +174 -0
- package/src/lib/disabledModelsDb.js +3 -0
- package/src/lib/env.ts +175 -0
- package/src/lib/errors/publicError.js +18 -0
- package/src/lib/grokBuildConfig.js +243 -0
- package/src/lib/guardRequest.js +51 -0
- package/src/lib/localDb.js +21 -0
- package/src/lib/mcp/stdioSseBridge.js +174 -0
- package/src/lib/network/connectionProxy.js +200 -0
- package/src/lib/network/proxyTest.js +158 -0
- package/src/lib/network/proxyUrl.js +76 -0
- package/src/lib/network/relay.js +71 -0
- package/src/lib/oauth/constants/oauth.js +152 -0
- package/src/lib/oauth/constants/xai.js +43 -0
- package/src/lib/oauth/kiroExternalIdp.js +167 -0
- package/src/lib/oauth/providerHelpers.js +90 -0
- package/src/lib/oauth/providers/_shared.js +12 -0
- package/src/lib/oauth/providers/antigravity.js +126 -0
- package/src/lib/oauth/providers/claude.js +60 -0
- package/src/lib/oauth/providers/cline.js +62 -0
- package/src/lib/oauth/providers/clinepass.js +62 -0
- package/src/lib/oauth/providers/codebuddy-cn.js +75 -0
- package/src/lib/oauth/providers/codebuddy-intl.js +73 -0
- package/src/lib/oauth/providers/codex.js +72 -0
- package/src/lib/oauth/providers/cursor.js +18 -0
- package/src/lib/oauth/providers/gemini-cli.js +84 -0
- package/src/lib/oauth/providers/github.js +96 -0
- package/src/lib/oauth/providers/grok-cli.js +123 -0
- package/src/lib/oauth/providers/index.js +233 -0
- package/src/lib/oauth/providers/kilocode.js +60 -0
- package/src/lib/oauth/providers/kimchi.js +79 -0
- package/src/lib/oauth/providers/kimi.js +79 -0
- package/src/lib/oauth/providers/kiro.js +147 -0
- package/src/lib/oauth/providers/qoder.js +90 -0
- package/src/lib/oauth/providers/trae.js +244 -0
- package/src/lib/oauth/providers/windsurf.js +123 -0
- package/src/lib/oauth/providers/xai.js +95 -0
- package/src/lib/oauth/providers.js +16 -0
- package/src/lib/oauth/services/cursor.js +132 -0
- package/src/lib/oauth/services/kiro.js +351 -0
- package/src/lib/oauth/services/oauth.js +135 -0
- package/src/lib/oauth/services/qoder.js +151 -0
- package/src/lib/oauth/services/xai.js +204 -0
- package/src/lib/oauth/utils/ideDetect.js +55 -0
- package/src/lib/oauth/utils/pkce.js +25 -0
- package/src/lib/oauth/utils/server.js +732 -0
- package/src/lib/oauth/utils/ui.js +43 -0
- package/src/lib/providerNormalization.js +40 -0
- package/src/lib/qoder/constants.js +1 -0
- package/src/lib/requestDetailsDb.js +3 -0
- package/src/lib/resourceProfile.ts +124 -0
- package/src/lib/runtimeSecrets.ts +130 -0
- package/src/lib/security/payloadCapture.js +87 -0
- package/src/lib/tunnel/cloudflare/cloudflared.js +436 -0
- package/src/lib/tunnel/cloudflare/config.js +8 -0
- package/src/lib/tunnel/cloudflare/healthCheck.js +37 -0
- package/src/lib/tunnel/cloudflare/manager.js +149 -0
- package/src/lib/tunnel/cloudflare/pid.js +31 -0
- package/src/lib/tunnel/cloudflare/publicUrl.js +41 -0
- package/src/lib/tunnel/cloudflare/requirements.js +12 -0
- package/src/lib/tunnel/index.js +26 -0
- package/src/lib/tunnel/shared/dnsResolver.js +16 -0
- package/src/lib/tunnel/shared/internetCheck.js +30 -0
- package/src/lib/tunnel/shared/state.js +45 -0
- package/src/lib/tunnel/shared/watchdogConfig.js +6 -0
- package/src/lib/update/installer.js +52 -0
- package/src/lib/update/version.js +116 -0
- package/src/lib/usageDb.js +6 -0
- package/src/lib/usageRefresh.js +88 -0
- package/src/lifecycle/appLifecycle.ts +99 -0
- package/src/models.js +36 -0
- package/src/next/headers.js +12 -0
- package/src/next/server.js +74 -0
- package/src/observability/metrics.js +439 -0
- package/src/observability/tracing.js +107 -0
- package/src/open-sse-index.js +70 -0
- package/src/providers/capabilities.js +299 -0
- package/src/providers/display.ts +142 -0
- package/src/providers/index.js +27 -0
- package/src/providers/models/helpers.js +19 -0
- package/src/providers/models/namePatterns.js +27 -0
- package/src/providers/models/schema.js +32 -0
- package/src/providers/pricing.js +248 -0
- package/src/providers/registry/agentrouter.js +52 -0
- package/src/providers/registry/alicode-intl.js +32 -0
- package/src/providers/registry/alicode.js +33 -0
- package/src/providers/registry/alims-intl.js +30 -0
- package/src/providers/registry/anthropic.js +29 -0
- package/src/providers/registry/antigravity.js +139 -0
- package/src/providers/registry/azure.js +23 -0
- package/src/providers/registry/baidu.js +35 -0
- package/src/providers/registry/blackbox.js +41 -0
- package/src/providers/registry/byteplus.js +36 -0
- package/src/providers/registry/cerebras.js +33 -0
- package/src/providers/registry/chutes.js +26 -0
- package/src/providers/registry/claude.js +80 -0
- package/src/providers/registry/cline.js +53 -0
- package/src/providers/registry/clinepass.js +62 -0
- package/src/providers/registry/cloudflare-ai.js +84 -0
- package/src/providers/registry/codebuddy-cn.js +95 -0
- package/src/providers/registry/codebuddy-intl.js +91 -0
- package/src/providers/registry/codex.js +145 -0
- package/src/providers/registry/commandcode.js +45 -0
- package/src/providers/registry/cursor.js +61 -0
- package/src/providers/registry/deepseek.js +55 -0
- package/src/providers/registry/featherless.js +36 -0
- package/src/providers/registry/fireworks.js +34 -0
- package/src/providers/registry/gemini-cli.js +59 -0
- package/src/providers/registry/gemini.js +76 -0
- package/src/providers/registry/github.js +131 -0
- package/src/providers/registry/glm-cn.js +35 -0
- package/src/providers/registry/glm.js +58 -0
- package/src/providers/registry/grok-cli.js +87 -0
- package/src/providers/registry/grok-web.js +41 -0
- package/src/providers/registry/groq.js +38 -0
- package/src/providers/registry/index.js +77 -0
- package/src/providers/registry/kilo-gateway.js +34 -0
- package/src/providers/registry/kilocode.js +48 -0
- package/src/providers/registry/kimchi.js +49 -0
- package/src/providers/registry/kimi.js +82 -0
- package/src/providers/registry/kiro.js +132 -0
- package/src/providers/registry/meta.js +34 -0
- package/src/providers/registry/minimax-cn.js +90 -0
- package/src/providers/registry/minimax.js +90 -0
- package/src/providers/registry/mistral.js +36 -0
- package/src/providers/registry/morph.js +31 -0
- package/src/providers/registry/nebius.js +26 -0
- package/src/providers/registry/nvidia.js +55 -0
- package/src/providers/registry/ollama-local.js +18 -0
- package/src/providers/registry/ollama.js +38 -0
- package/src/providers/registry/openai.js +114 -0
- package/src/providers/registry/opencode-go.js +41 -0
- package/src/providers/registry/opencode.js +26 -0
- package/src/providers/registry/openrouter.js +36 -0
- package/src/providers/registry/perplexity.js +56 -0
- package/src/providers/registry/poolside.js +30 -0
- package/src/providers/registry/qoder.js +58 -0
- package/src/providers/registry/sumopod.js +84 -0
- package/src/providers/registry/tencent.js +29 -0
- package/src/providers/registry/together.js +38 -0
- package/src/providers/registry/trae.js +71 -0
- package/src/providers/registry/venice.js +69 -0
- package/src/providers/registry/vercel-ai-gateway.js +37 -0
- package/src/providers/registry/vertex-partner.js +31 -0
- package/src/providers/registry/vertex.js +33 -0
- package/src/providers/registry/windsurf.js +129 -0
- package/src/providers/registry/xai.js +46 -0
- package/src/providers/registry/xiaomi-mimo.js +66 -0
- package/src/providers/registry/xiaomi-tokenplan.js +58 -0
- package/src/providers/registryEntry.js +3 -0
- package/src/providers/schema.js +33 -0
- package/src/providers/shared.js +114 -0
- package/src/providers/thinkingLevels.js +49 -0
- package/src/routes/api/auth/login/route.js +82 -0
- package/src/routes/api/auth/logout/route.js +9 -0
- package/src/routes/api/auth/reset-password/route.js +12 -0
- package/src/routes/api/auth/status/route.js +33 -0
- package/src/routes/api/auth/verify-password/route.js +39 -0
- package/src/routes/api/chat/tools/curl/route.js +100 -0
- package/src/routes/api/chat/tools/router/route.js +215 -0
- package/src/routes/api/chat/tools/search/route.js +362 -0
- package/src/routes/api/chat/tools/shell/route.js +228 -0
- package/src/routes/api/cli-tools/all-statuses/route.js +37 -0
- package/src/routes/api/cli-tools/claude-settings/route.js +261 -0
- package/src/routes/api/cli-tools/codex-settings/route.js +220 -0
- package/src/routes/api/cli-tools/cowork-mcp-registry/route.js +80 -0
- package/src/routes/api/cli-tools/cowork-mcp-tools/route.js +96 -0
- package/src/routes/api/cli-tools/cowork-settings/route.js +380 -0
- package/src/routes/api/cli-tools/grok-build-settings/route.js +152 -0
- package/src/routes/api/cli-tools/hermes-settings/route.js +169 -0
- package/src/routes/api/cli-tools/kilo-settings/route.js +131 -0
- package/src/routes/api/cli-tools/model-mappings/route.js +43 -0
- package/src/routes/api/cli-tools/omp-settings/route.js +266 -0
- package/src/routes/api/cli-tools/opencode-settings/route.js +243 -0
- package/src/routes/api/combos/[id]/route.js +73 -0
- package/src/routes/api/combos/route.js +43 -0
- package/src/routes/api/health/live/route.js +7 -0
- package/src/routes/api/health/ready/route.js +19 -0
- package/src/routes/api/health/route.js +17 -0
- package/src/routes/api/inflight/stream/route.js +24 -0
- package/src/routes/api/init/route.js +3 -0
- package/src/routes/api/keys/[id]/route.js +71 -0
- package/src/routes/api/keys/route.js +41 -0
- package/src/routes/api/logs/route.js +19 -0
- package/src/routes/api/mcp/[plugin]/message/route.js +23 -0
- package/src/routes/api/mcp/[plugin]/sse/route.js +35 -0
- package/src/routes/api/models/availability/route.js +104 -0
- package/src/routes/api/models/custom/route.js +58 -0
- package/src/routes/api/models/disabled/route.js +47 -0
- package/src/routes/api/models/route.js +64 -0
- package/src/routes/api/models/test/ping.js +236 -0
- package/src/routes/api/models/test/route.js +14 -0
- package/src/routes/api/oauth/[provider]/[action]/route.js +491 -0
- package/src/routes/api/oauth/codex/bulk-import/route.js +105 -0
- package/src/routes/api/oauth/codex/import-token/route.js +82 -0
- package/src/routes/api/oauth/cursor/auto-import/route.js +250 -0
- package/src/routes/api/oauth/cursor/import/route.js +86 -0
- package/src/routes/api/oauth/kiro/api-key/route.js +60 -0
- package/src/routes/api/oauth/kiro/auto-import/route.js +120 -0
- package/src/routes/api/oauth/kiro/import/route.js +72 -0
- package/src/routes/api/oauth/kiro/import-cli-proxy/route.js +42 -0
- package/src/routes/api/oauth/kiro/social-authorize/route.js +40 -0
- package/src/routes/api/oauth/kiro/social-exchange/route.js +62 -0
- package/src/routes/api/pricing/route.js +96 -0
- package/src/routes/api/provider-nodes/[id]/route.js +106 -0
- package/src/routes/api/provider-nodes/route.js +110 -0
- package/src/routes/api/provider-nodes/validate/route.js +197 -0
- package/src/routes/api/providers/[id]/models/route.js +716 -0
- package/src/routes/api/providers/[id]/route.js +195 -0
- package/src/routes/api/providers/[id]/test/route.js +27 -0
- package/src/routes/api/providers/[id]/test/testUtils.js +912 -0
- package/src/routes/api/providers/[id]/test-models/route.js +211 -0
- package/src/routes/api/providers/catalog/route.js +58 -0
- package/src/routes/api/providers/client/route.js +133 -0
- package/src/routes/api/providers/counts/route.js +43 -0
- package/src/routes/api/providers/kilo/free-models/route.js +58 -0
- package/src/routes/api/providers/route.js +361 -0
- package/src/routes/api/providers/suggested-models/filters.js +24 -0
- package/src/routes/api/providers/suggested-models/route.js +34 -0
- package/src/routes/api/providers/test-batch/route.js +145 -0
- package/src/routes/api/providers/validate/route.js +633 -0
- package/src/routes/api/proxy-pools/[id]/route.js +129 -0
- package/src/routes/api/proxy-pools/[id]/test/route.js +64 -0
- package/src/routes/api/proxy-pools/cloudflare-deploy/route.js +183 -0
- package/src/routes/api/proxy-pools/route.js +85 -0
- package/src/routes/api/proxy-pools/vercel-deploy/route.js +181 -0
- package/src/routes/api/settings/currency/route.js +29 -0
- package/src/routes/api/settings/database/path/route.js +8 -0
- package/src/routes/api/settings/database/route.js +89 -0
- package/src/routes/api/settings/migrate-9router/route.js +81 -0
- package/src/routes/api/settings/require-login/route.js +14 -0
- package/src/routes/api/settings/route.js +186 -0
- package/src/routes/api/shutdown/route.js +25 -0
- package/src/routes/api/tags/route.js +17 -0
- package/src/routes/api/translator/console-logs/route.js +28 -0
- package/src/routes/api/translator/console-logs/stream/route.js +95 -0
- package/src/routes/api/tunnel/disable/route.js +18 -0
- package/src/routes/api/tunnel/enable/route.js +32 -0
- package/src/routes/api/tunnel/status/route.js +23 -0
- package/src/routes/api/update/route.js +42 -0
- package/src/routes/api/usage/[connectionId]/codex-reset-credits/route.js +169 -0
- package/src/routes/api/usage/[connectionId]/route.js +222 -0
- package/src/routes/api/usage/chart/route.js +27 -0
- package/src/routes/api/usage/history/route.js +94 -0
- package/src/routes/api/usage/logs/route.js +14 -0
- package/src/routes/api/usage/providers/route.js +36 -0
- package/src/routes/api/usage/request-details/route.js +61 -0
- package/src/routes/api/usage/request-logs/route.js +15 -0
- package/src/routes/api/usage/stats/route.js +23 -0
- package/src/routes/api/usage/stream/route.js +78 -0
- package/src/routes/api/v1/api/chat/route.js +36 -0
- package/src/routes/api/v1/chat/completions/route.js +28 -0
- package/src/routes/api/v1/images/edits/route.js +70 -0
- package/src/routes/api/v1/images/generations/route.js +50 -0
- package/src/routes/api/v1/images/imageValidation.js +45 -0
- package/src/routes/api/v1/messages/count_tokens/route.js +87 -0
- package/src/routes/api/v1/messages/route.js +26 -0
- package/src/routes/api/v1/models/route.js +440 -0
- package/src/routes/api/v1/responses/compact/route.js +34 -0
- package/src/routes/api/v1/responses/route.js +26 -0
- package/src/routes/api/v1/route.js +1 -0
- package/src/routes/api/version/route.js +11 -0
- package/src/routes/table.js +1141 -0
- package/src/rtk/applyFilter.js +13 -0
- package/src/rtk/autodetect.js +104 -0
- package/src/rtk/caveman.js +6 -0
- package/src/rtk/cavemanPrompts.js +107 -0
- package/src/rtk/constants.js +51 -0
- package/src/rtk/filters/buildOutput.js +120 -0
- package/src/rtk/filters/dedupLog.js +43 -0
- package/src/rtk/filters/find.js +47 -0
- package/src/rtk/filters/gitDiff.js +90 -0
- package/src/rtk/filters/gitLog.js +88 -0
- package/src/rtk/filters/gitStatus.js +101 -0
- package/src/rtk/filters/grep.js +45 -0
- package/src/rtk/filters/ls.js +73 -0
- package/src/rtk/filters/readNumbered.js +22 -0
- package/src/rtk/filters/searchList.js +49 -0
- package/src/rtk/filters/smartTruncate.js +13 -0
- package/src/rtk/filters/tree.js +28 -0
- package/src/rtk/index.js +143 -0
- package/src/rtk/ponytail.js +6 -0
- package/src/rtk/ponytailPrompt.js +49 -0
- package/src/rtk/systemInject.js +89 -0
- package/src/server.ts +474 -0
- package/src/services/accountFallback.js +241 -0
- package/src/services/accountPool.js +389 -0
- package/src/services/capacityAdapter.js +140 -0
- package/src/services/cliModelMapping.js +84 -0
- package/src/services/clinepassModels.js +60 -0
- package/src/services/codebuddyModels.js +250 -0
- package/src/services/combo.js +482 -0
- package/src/services/copilotModels.js +126 -0
- package/src/services/currencyRate.js +56 -0
- package/src/services/cursorModels.js +197 -0
- package/src/services/grokCliModels.js +130 -0
- package/src/services/kimchiModels.js +175 -0
- package/src/services/kiroModels.js +246 -0
- package/src/services/model.js +83 -0
- package/src/services/oauthCredentialManager.js +153 -0
- package/src/services/projectId.js +240 -0
- package/src/services/provider.js +145 -0
- package/src/services/qoderModels.js +274 -0
- package/src/services/tokenRefresh/dedup.js +70 -0
- package/src/services/tokenRefresh/providers.js +626 -0
- package/src/services/tokenRefresh.js +274 -0
- package/src/services/usage/claude.js +134 -0
- package/src/services/usage/codebuddy-cn.js +212 -0
- package/src/services/usage/codex.js +193 -0
- package/src/services/usage/deepseek.js +103 -0
- package/src/services/usage/github.js +94 -0
- package/src/services/usage/google.js +218 -0
- package/src/services/usage/grok-cli.js +368 -0
- package/src/services/usage/grokCliQuotaFrame.js +170 -0
- package/src/services/usage/kimi.js +185 -0
- package/src/services/usage/kiro.js +172 -0
- package/src/services/usage/minimax.js +215 -0
- package/src/services/usage/misc.js +264 -0
- package/src/services/usage/shared.js +59 -0
- package/src/services/usage.js +56 -0
- package/src/shared/clineAuth.js +37 -0
- package/src/shared/constants/config.js +80 -0
- package/src/shared/constants/coworkPlugins.js +69 -0
- package/src/shared/constants/models.js +41 -0
- package/src/shared/constants/providers.js +128 -0
- package/src/shared/constants/providersDisplay.js +1 -0
- package/src/shared/qoder/constants.js +50 -0
- package/src/shared/qoder/cosy.js +134 -0
- package/src/shared/qoder/encoding.js +36 -0
- package/src/shared/services/initializeApp.js +226 -0
- package/src/shared/services/quotaAutoPing.js +310 -0
- package/src/shared/utils/apiKey.js +65 -0
- package/src/shared/utils/clineAuth.js +1 -0
- package/src/shared/utils/index.js +3 -0
- package/src/shared/utils/machineId.js +60 -0
- package/src/shared/utils/ssrfGuard.js +280 -0
- package/src/sse/handlers/chat.js +426 -0
- package/src/sse/oauthLease.js +32 -0
- package/src/sse/recovery.js +235 -0
- package/src/sse/services/auth.js +489 -0
- package/src/sse/services/backgroundTokenRefresh.js +173 -0
- package/src/sse/services/model.js +129 -0
- package/src/sse/services/requestCancellation.js +4 -0
- package/src/sse/services/tokenRefresh.js +264 -0
- package/src/sse/utils/logger.js +142 -0
- package/src/staticServe.ts +95 -0
- package/src/transformer/streamToJsonConverter.js +87 -0
- package/src/translator/canonical.js +81 -0
- package/src/translator/concerns/chunk.js +9 -0
- package/src/translator/concerns/compatFallback.js +147 -0
- package/src/translator/concerns/finishReason.js +59 -0
- package/src/translator/concerns/image.js +105 -0
- package/src/translator/concerns/json.js +4 -0
- package/src/translator/concerns/kiroConversation.js +428 -0
- package/src/translator/concerns/message.js +5 -0
- package/src/translator/concerns/modality.js +134 -0
- package/src/translator/concerns/paramSupport.js +97 -0
- package/src/translator/concerns/prefetch.js +86 -0
- package/src/translator/concerns/reasoning.js +18 -0
- package/src/translator/concerns/thinking.js +40 -0
- package/src/translator/concerns/thinkingUnified.js +319 -0
- package/src/translator/concerns/toolCall.js +134 -0
- package/src/translator/concerns/usage.js +61 -0
- package/src/translator/detection.js +42 -0
- package/src/translator/formats/claude.js +323 -0
- package/src/translator/formats/gemini.js +366 -0
- package/src/translator/formats/maxTokens.js +19 -0
- package/src/translator/formats/openai.js +116 -0
- package/src/translator/formats/responsesApi.js +117 -0
- package/src/translator/formats.js +28 -0
- package/src/translator/index.js +237 -0
- package/src/translator/request/antigravity-to-openai.js +217 -0
- package/src/translator/request/claude-to-kiro.js +288 -0
- package/src/translator/request/claude-to-openai.js +199 -0
- package/src/translator/request/gemini-to-openai.js +142 -0
- package/src/translator/request/openai-responses.js +373 -0
- package/src/translator/request/openai-to-claude.js +260 -0
- package/src/translator/request/openai-to-commandcode.js +161 -0
- package/src/translator/request/openai-to-cursor.js +175 -0
- package/src/translator/request/openai-to-gemini.js +422 -0
- package/src/translator/request/openai-to-kiro.js +360 -0
- package/src/translator/request/openai-to-ollama.js +152 -0
- package/src/translator/request/openai-to-vertex.js +36 -0
- package/src/translator/response/claude-to-openai.js +185 -0
- package/src/translator/response/commandcode-to-openai.js +164 -0
- package/src/translator/response/cursor-to-openai.js +18 -0
- package/src/translator/response/gemini-to-openai.js +127 -0
- package/src/translator/response/kiro-to-claude.js +230 -0
- package/src/translator/response/kiro-to-openai.js +136 -0
- package/src/translator/response/ollama-to-openai.js +106 -0
- package/src/translator/response/openai-responses.js +534 -0
- package/src/translator/response/openai-to-antigravity.js +107 -0
- package/src/translator/response/openai-to-claude.js +231 -0
- package/src/translator/schema/blocks.js +40 -0
- package/src/translator/schema/defaults.js +3 -0
- package/src/translator/schema/finishReasons.js +22 -0
- package/src/translator/schema/index.js +7 -0
- package/src/translator/schema/roles.js +12 -0
- package/src/transport/requestBoundary.ts +223 -0
- package/src/transport/routerAdmission.ts +380 -0
- package/src/types/provider.ts +59 -0
- package/src/utils/bypassHandler.js +272 -0
- package/src/utils/claudeCloaking.js +10 -0
- package/src/utils/claudeSignature.js +35 -0
- package/src/utils/clientDetector.js +183 -0
- package/src/utils/cursorChecksum.js +104 -0
- package/src/utils/cursorProtobuf.js +801 -0
- package/src/utils/debugLog.js +12 -0
- package/src/utils/error.js +120 -0
- package/src/utils/inflight.js +127 -0
- package/src/utils/kiroSessionReplay.js +139 -0
- package/src/utils/ollamaTransform.js +83 -0
- package/src/utils/proxyFetch.js +308 -0
- package/src/utils/reasoningContentInjector.js +71 -0
- package/src/utils/requestLogger.js +272 -0
- package/src/utils/responsesStreamHelpers.js +46 -0
- package/src/utils/sessionManager.js +205 -0
- package/src/utils/sse.js +13 -0
- package/src/utils/sseConstants.js +21 -0
- package/src/utils/stream.js +511 -0
- package/src/utils/streamHandler.js +256 -0
- package/src/utils/streamHelpers.js +113 -0
- package/src/utils/toolDeduper.js +44 -0
- package/src/utils/usageTracking.js +329 -0
- package/tsconfig.json +45 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function safeApply(fn, text) {
|
|
2
|
+
if (typeof fn !== "function") return text;
|
|
3
|
+
try {
|
|
4
|
+
const out = fn(text);
|
|
5
|
+
if (typeof out !== "string") return text;
|
|
6
|
+
return out;
|
|
7
|
+
} catch (err) {
|
|
8
|
+
|
|
9
|
+
const name = fn.filterName || fn.name || "anonymous";
|
|
10
|
+
console.warn(`[rtk] warning: filter '${name}' panicked — passing through raw output: ${err?.message || err}`);
|
|
11
|
+
return text;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { DETECT_WINDOW, READ_NUMBERED_MIN_HIT_RATIO, SMART_TRUNCATE_MIN_LINES } from "./constants.js";
|
|
2
|
+
import { gitDiff } from "./filters/gitDiff.js";
|
|
3
|
+
import { gitStatus } from "./filters/gitStatus.js";
|
|
4
|
+
import { gitLog } from "./filters/gitLog.js";
|
|
5
|
+
import { buildOutput } from "./filters/buildOutput.js";
|
|
6
|
+
import { grep } from "./filters/grep.js";
|
|
7
|
+
import { find } from "./filters/find.js";
|
|
8
|
+
import { dedupLog } from "./filters/dedupLog.js";
|
|
9
|
+
import { ls } from "./filters/ls.js";
|
|
10
|
+
import { tree } from "./filters/tree.js";
|
|
11
|
+
import { smartTruncate } from "./filters/smartTruncate.js";
|
|
12
|
+
import { readNumbered, READ_NUMBERED_LINE_RE } from "./filters/readNumbered.js";
|
|
13
|
+
import { searchList, SEARCH_LIST_HEADER_RE } from "./filters/searchList.js";
|
|
14
|
+
|
|
15
|
+
const RE_GIT_DIFF = /^diff --git /m;
|
|
16
|
+
const RE_GIT_DIFF_HUNK = /^@@ /m;
|
|
17
|
+
const RE_GIT_STATUS = /^On branch |^nothing to commit|^Changes (not |to be )|^Untracked files:/m;
|
|
18
|
+
const RE_GIT_LOG = /^[*|/\\ ]*commit [0-9a-f]{7,40}$/m;
|
|
19
|
+
const RE_PORCELAIN = /^[ MADRCU?!][ MADRCU?!] \S/m;
|
|
20
|
+
const RE_BUILD_OUTPUT = /^(npm (warn|error|ERR!)|yarn (warn|error)|\s*Compiling\s+\S+|\s*Downloading\s+\S+|added \d+ package|\[ERROR\]|BUILD (SUCCESS|FAILED)|\s*Finished\s+|Successfully (installed|built)|ERROR:)/im;
|
|
21
|
+
const RE_TREE_GLYPH = /[├└]──|│ /;
|
|
22
|
+
const RE_LS_ROW = /^[-dlbcps][rwx-]{9}/m;
|
|
23
|
+
const RE_LS_TOTAL = /^total \d+$/m;
|
|
24
|
+
|
|
25
|
+
export function autoDetectFilter(text) {
|
|
26
|
+
|
|
27
|
+
const head = text.length > DETECT_WINDOW ? text.slice(0, DETECT_WINDOW) : text;
|
|
28
|
+
|
|
29
|
+
if (RE_GIT_LOG.test(head)) return gitLog;
|
|
30
|
+
if (RE_GIT_DIFF.test(head) || RE_GIT_DIFF_HUNK.test(head)) return gitDiff;
|
|
31
|
+
if (RE_GIT_STATUS.test(head)) return gitStatus;
|
|
32
|
+
|
|
33
|
+
if (RE_BUILD_OUTPUT.test(head)) return buildOutput;
|
|
34
|
+
|
|
35
|
+
if (isMostlyPorcelain(head)) return gitStatus;
|
|
36
|
+
|
|
37
|
+
const lines = head.split("\n");
|
|
38
|
+
const nonEmpty = lines.filter(l => l.trim().length > 0);
|
|
39
|
+
|
|
40
|
+
const first5 = nonEmpty.slice(0, 5);
|
|
41
|
+
if (first5.some(isGrepLine)) return grep;
|
|
42
|
+
|
|
43
|
+
if (nonEmpty.length >= 3 && nonEmpty.every(isPathLike)) return find;
|
|
44
|
+
|
|
45
|
+
if (RE_TREE_GLYPH.test(head)) return tree;
|
|
46
|
+
|
|
47
|
+
if (RE_LS_TOTAL.test(head) || countMatches(head, RE_LS_ROW) >= 3) return ls;
|
|
48
|
+
|
|
49
|
+
if (SEARCH_LIST_HEADER_RE.test(head)) return searchList;
|
|
50
|
+
|
|
51
|
+
if (lines.length >= SMART_TRUNCATE_MIN_LINES && isLineNumbered(lines)) {
|
|
52
|
+
return readNumbered;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (nonEmpty.length >= 5) return dedupLog;
|
|
56
|
+
|
|
57
|
+
if (text.split("\n").length >= SMART_TRUNCATE_MIN_LINES) return smartTruncate;
|
|
58
|
+
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function isGrepLine(line) {
|
|
63
|
+
|
|
64
|
+
const first = line.indexOf(":");
|
|
65
|
+
if (first === -1) return false;
|
|
66
|
+
const second = line.indexOf(":", first + 1);
|
|
67
|
+
if (second === -1) return false;
|
|
68
|
+
const lineno = line.slice(first + 1, second);
|
|
69
|
+
return /^\d+$/.test(lineno);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function isPathLike(line) {
|
|
73
|
+
const t = line.trim();
|
|
74
|
+
if (t.length === 0) return false;
|
|
75
|
+
|
|
76
|
+
if (/^[A-Za-z]:[\\/]/.test(t)) return true;
|
|
77
|
+
if (t.includes(":")) return false;
|
|
78
|
+
return t.startsWith(".") || t.startsWith("/") || t.includes("/");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function isMostlyPorcelain(head) {
|
|
82
|
+
const lines = head.split("\n").filter(l => l.trim());
|
|
83
|
+
if (lines.length < 3) return false;
|
|
84
|
+
const hits = lines.filter(l => RE_PORCELAIN.test(l)).length;
|
|
85
|
+
return hits / lines.length >= 0.6;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function isLineNumbered(lines) {
|
|
89
|
+
let hits = 0;
|
|
90
|
+
let nonEmpty = 0;
|
|
91
|
+
const sample = lines.slice(0, 100);
|
|
92
|
+
for (const l of sample) {
|
|
93
|
+
if (l.length === 0) continue;
|
|
94
|
+
nonEmpty++;
|
|
95
|
+
if (READ_NUMBERED_LINE_RE.test(l)) hits++;
|
|
96
|
+
}
|
|
97
|
+
if (nonEmpty < 5) return false;
|
|
98
|
+
return hits / nonEmpty >= READ_NUMBERED_MIN_HIT_RATIO;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function countMatches(text, re) {
|
|
102
|
+
const g = new RegExp(re.source, re.flags.includes("g") ? re.flags : re.flags + "g");
|
|
103
|
+
return (text.match(g) || []).length;
|
|
104
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
export const CAVEMAN_LEVELS = {
|
|
2
|
+
LITE: "lite",
|
|
3
|
+
FULL: "full",
|
|
4
|
+
ULTRA: "ultra",
|
|
5
|
+
WENYAN_LITE: "wenyan-lite",
|
|
6
|
+
WENYAN: "wenyan",
|
|
7
|
+
WENYAN_ULTRA: "wenyan-ultra",
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const SHARED_BOUNDARIES = "Code blocks, file paths, commands, errors, URLs: keep exact. Security warnings, irreversible action confirmations, multi-step ordered sequences: write normal. Resume terse style after.";
|
|
11
|
+
|
|
12
|
+
const SHARED_EXAMPLES = "Not: \"Sure! I'd be happy to help you with that. The issue you're experiencing is likely caused by...\" Yes: \"Bug in auth middleware. Token expiry check use `<` not `<=`. Fix:\"";
|
|
13
|
+
|
|
14
|
+
const SHARED_AUTO_CLARITY = "Auto-Clarity: drop caveman for security warnings, irreversible actions, multi-step sequences where fragment ambiguity risks misread, or when user repeats a question. Resume after the clear part.";
|
|
15
|
+
|
|
16
|
+
const SHARED_PERSISTENCE = "ACTIVE EVERY RESPONSE. No revert after many turns. No filler drift. Still active if unsure.";
|
|
17
|
+
|
|
18
|
+
const SHARED_NO_INVENTED_ABBREV = "No invented abbreviations. Standard well-known tech acronyms (DB, API, HTTP, URL, JSON, ID, OS, CPU) OK. Names of code symbols, function names, API names, error strings: keep verbatim.";
|
|
19
|
+
|
|
20
|
+
const SHARED_PRESERVE_LANGUAGE = "Preserve the user's dominant language. User wrote Vietnamese, reply Vietnamese. User wrote English, reply English. Wenyan/classical-Chinese levels override this language-preservation rule. Code identifiers, error strings, file paths, commands: keep in their original form regardless of language.";
|
|
21
|
+
|
|
22
|
+
const SHARED_NO_SELF_REFERENCE = 'No self-reference. Do not name or announce the style (no "caveman mode", no "me caveman think", no "compressed mode active"). Just respond.';
|
|
23
|
+
|
|
24
|
+
const SHARED_NO_DECORATION = 'No decorative emoji. No narrating tool calls ("I will now search", "I used X to find Y"). No status phrases ("Sure!", "Of course!", "I\'d be happy to"). No causal arrow shorthand ("A -> B -> fails"). State the thing, the action, the reason. Then next step.';
|
|
25
|
+
|
|
26
|
+
export const CAVEMAN_PROMPTS = {
|
|
27
|
+
[CAVEMAN_LEVELS.LITE]: [
|
|
28
|
+
"Respond tersely. Keep grammar and full sentences but drop filler, hedging and pleasantries (just/really/basically/sure/of course/I'd be happy to).",
|
|
29
|
+
"Pattern: state the thing, the action, the reason. Then next step.",
|
|
30
|
+
SHARED_EXAMPLES,
|
|
31
|
+
SHARED_BOUNDARIES,
|
|
32
|
+
SHARED_AUTO_CLARITY,
|
|
33
|
+
SHARED_PERSISTENCE,
|
|
34
|
+
SHARED_NO_INVENTED_ABBREV,
|
|
35
|
+
SHARED_PRESERVE_LANGUAGE,
|
|
36
|
+
SHARED_NO_SELF_REFERENCE,
|
|
37
|
+
SHARED_NO_DECORATION,
|
|
38
|
+
].join(" "),
|
|
39
|
+
|
|
40
|
+
[CAVEMAN_LEVELS.FULL]: [
|
|
41
|
+
"Respond like terse caveman. All technical substance stay exact, only fluff die.",
|
|
42
|
+
"Drop: articles (a/an/the), filler (just/really/basically/actually/simply), pleasantries, hedging. Fragments OK. Short synonyms (big not extensive, fix not implement a solution for).",
|
|
43
|
+
"Pattern: [thing] [action] [reason]. [next step].",
|
|
44
|
+
SHARED_EXAMPLES,
|
|
45
|
+
SHARED_BOUNDARIES,
|
|
46
|
+
SHARED_AUTO_CLARITY,
|
|
47
|
+
SHARED_PERSISTENCE,
|
|
48
|
+
SHARED_NO_INVENTED_ABBREV,
|
|
49
|
+
SHARED_PRESERVE_LANGUAGE,
|
|
50
|
+
SHARED_NO_SELF_REFERENCE,
|
|
51
|
+
SHARED_NO_DECORATION,
|
|
52
|
+
].join(" "),
|
|
53
|
+
|
|
54
|
+
[CAVEMAN_LEVELS.ULTRA]: [
|
|
55
|
+
"Respond ultra-terse. Maximum compression. Telegraphic.",
|
|
56
|
+
"Strip conjunctions. One word when one word enough.",
|
|
57
|
+
"Pattern: [thing] [action] [reason]. [next step].",
|
|
58
|
+
SHARED_EXAMPLES,
|
|
59
|
+
SHARED_BOUNDARIES,
|
|
60
|
+
SHARED_AUTO_CLARITY,
|
|
61
|
+
SHARED_PERSISTENCE,
|
|
62
|
+
SHARED_NO_INVENTED_ABBREV,
|
|
63
|
+
SHARED_PRESERVE_LANGUAGE,
|
|
64
|
+
SHARED_NO_SELF_REFERENCE,
|
|
65
|
+
SHARED_NO_DECORATION,
|
|
66
|
+
].join(" "),
|
|
67
|
+
|
|
68
|
+
[CAVEMAN_LEVELS.WENYAN_LITE]: [
|
|
69
|
+
"Respond semi-classical. Drop filler/hedging but keep grammar structure, classical register.",
|
|
70
|
+
"Use classical Chinese sentence patterns where natural. Keep English for technical terms.",
|
|
71
|
+
SHARED_EXAMPLES,
|
|
72
|
+
SHARED_BOUNDARIES,
|
|
73
|
+
SHARED_AUTO_CLARITY,
|
|
74
|
+
SHARED_PERSISTENCE,
|
|
75
|
+
SHARED_NO_INVENTED_ABBREV,
|
|
76
|
+
SHARED_PRESERVE_LANGUAGE,
|
|
77
|
+
SHARED_NO_SELF_REFERENCE,
|
|
78
|
+
SHARED_NO_DECORATION,
|
|
79
|
+
].join(" "),
|
|
80
|
+
|
|
81
|
+
[CAVEMAN_LEVELS.WENYAN]: [
|
|
82
|
+
"Respond classical Chinese (文言文). Maximum classical terseness. 80-90% character reduction.",
|
|
83
|
+
"Classical sentence patterns, verbs precede objects, subjects often omitted, classical particles (之/乃/為/其).",
|
|
84
|
+
"Keep English for code, commands, function names, API names, error strings.",
|
|
85
|
+
SHARED_EXAMPLES,
|
|
86
|
+
SHARED_BOUNDARIES,
|
|
87
|
+
SHARED_AUTO_CLARITY,
|
|
88
|
+
SHARED_PERSISTENCE,
|
|
89
|
+
SHARED_NO_INVENTED_ABBREV,
|
|
90
|
+
SHARED_PRESERVE_LANGUAGE,
|
|
91
|
+
SHARED_NO_SELF_REFERENCE,
|
|
92
|
+
SHARED_NO_DECORATION,
|
|
93
|
+
].join(" "),
|
|
94
|
+
|
|
95
|
+
[CAVEMAN_LEVELS.WENYAN_ULTRA]: [
|
|
96
|
+
"Respond extreme classical compression (文言文 ultra). Maximum compression, ultra terse.",
|
|
97
|
+
"Same classical rules as wenyan-full but even more compressed. One classical particle per clause.",
|
|
98
|
+
SHARED_EXAMPLES,
|
|
99
|
+
SHARED_BOUNDARIES,
|
|
100
|
+
SHARED_AUTO_CLARITY,
|
|
101
|
+
SHARED_PERSISTENCE,
|
|
102
|
+
SHARED_NO_INVENTED_ABBREV,
|
|
103
|
+
SHARED_PRESERVE_LANGUAGE,
|
|
104
|
+
SHARED_NO_SELF_REFERENCE,
|
|
105
|
+
SHARED_NO_DECORATION,
|
|
106
|
+
].join(" "),
|
|
107
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export const RAW_CAP = 10 * 1024 * 1024;
|
|
2
|
+
export const MIN_COMPRESS_SIZE = 500;
|
|
3
|
+
export const DETECT_WINDOW = 1024;
|
|
4
|
+
export const GIT_DIFF_HUNK_MAX_LINES = 100;
|
|
5
|
+
export const GIT_DIFF_CONTEXT_KEEP = 3;
|
|
6
|
+
export const GIT_LOG_MAX_LINES = 200;
|
|
7
|
+
export const DEDUP_LINE_MAX = 2000;
|
|
8
|
+
|
|
9
|
+
export const GREP_PER_FILE_MAX = 10;
|
|
10
|
+
export const FIND_PER_DIR_MAX = 10;
|
|
11
|
+
export const FIND_TOTAL_DIR_MAX = 20;
|
|
12
|
+
|
|
13
|
+
export const STATUS_MAX_FILES = 10;
|
|
14
|
+
export const STATUS_MAX_UNTRACKED = 10;
|
|
15
|
+
|
|
16
|
+
export const LS_EXT_SUMMARY_TOP = 5;
|
|
17
|
+
export const LS_NOISE_DIRS = [
|
|
18
|
+
"node_modules", ".git", "target", "__pycache__",
|
|
19
|
+
".next", "dist", "build", ".cache", ".turbo",
|
|
20
|
+
".vercel", ".pytest_cache", ".mypy_cache", ".tox",
|
|
21
|
+
".venv", "venv",
|
|
22
|
+
"env",
|
|
23
|
+
"coverage", ".nyc_output", ".DS_Store", "Thumbs.db",
|
|
24
|
+
".idea", ".vscode", ".vs", "*.egg-info", ".eggs"
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
export const TREE_MAX_LINES = 200;
|
|
28
|
+
|
|
29
|
+
export const SEARCH_LIST_PER_DIR_MAX = 10;
|
|
30
|
+
export const SEARCH_LIST_TOTAL_DIR_MAX = 20;
|
|
31
|
+
|
|
32
|
+
export const SMART_TRUNCATE_HEAD = 120;
|
|
33
|
+
export const SMART_TRUNCATE_TAIL = 60;
|
|
34
|
+
export const SMART_TRUNCATE_MIN_LINES = 250;
|
|
35
|
+
|
|
36
|
+
export const READ_NUMBERED_MIN_HIT_RATIO = 0.7;
|
|
37
|
+
|
|
38
|
+
export const FILTERS = {
|
|
39
|
+
GIT_DIFF: "git-diff",
|
|
40
|
+
GIT_STATUS: "git-status",
|
|
41
|
+
GIT_LOG: "git-log",
|
|
42
|
+
GREP: "grep",
|
|
43
|
+
FIND: "find",
|
|
44
|
+
LS: "ls",
|
|
45
|
+
TREE: "tree",
|
|
46
|
+
DEDUP_LOG: "dedup-log",
|
|
47
|
+
SMART_TRUNCATE: "smart-truncate",
|
|
48
|
+
READ_NUMBERED: "read-numbered",
|
|
49
|
+
SEARCH_LIST: "search-list",
|
|
50
|
+
BUILD_OUTPUT: "build-output"
|
|
51
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
const RE_CARGO_ERR_CONT = /^\s*(-->|\||\d+\s*\||=)/;
|
|
2
|
+
const DEPRECATION_KEEP = 3;
|
|
3
|
+
|
|
4
|
+
export function buildOutput(input) {
|
|
5
|
+
const lines = input.split("\n");
|
|
6
|
+
if (lines.length === 0) return input;
|
|
7
|
+
|
|
8
|
+
const errors = [];
|
|
9
|
+
const warnings = [];
|
|
10
|
+
const deprecations = [];
|
|
11
|
+
let summary = null;
|
|
12
|
+
let compilingCount = 0;
|
|
13
|
+
let downloadingCount = 0;
|
|
14
|
+
let inCargoError = false;
|
|
15
|
+
|
|
16
|
+
for (const line of lines) {
|
|
17
|
+
const trimmed = line.trim();
|
|
18
|
+
|
|
19
|
+
if (inCargoError) {
|
|
20
|
+
if (!trimmed) { inCargoError = false; continue; }
|
|
21
|
+
if (RE_CARGO_ERR_CONT.test(line)) { errors.push(line); continue; }
|
|
22
|
+
inCargoError = false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (!trimmed) continue;
|
|
26
|
+
|
|
27
|
+
if (/^npm (ERR!|error)/i.test(trimmed) || /^yarn error/i.test(trimmed)) {
|
|
28
|
+
errors.push(line);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (/^npm warn deprecated/i.test(trimmed)) {
|
|
33
|
+
deprecations.push(line);
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (/^npm warn/i.test(trimmed) || /^yarn warn/i.test(trimmed)) {
|
|
37
|
+
warnings.push(line);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (/^error(\[|:)/i.test(trimmed) || trimmed.startsWith("error -->")) {
|
|
42
|
+
errors.push(line);
|
|
43
|
+
inCargoError = true;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (/^warning(\[|:)/i.test(trimmed) || trimmed.startsWith("warning -->")) {
|
|
48
|
+
warnings.push(line);
|
|
49
|
+
inCargoError = true;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (/^ERROR:/i.test(trimmed)) {
|
|
54
|
+
errors.push(line);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (/^\[ERROR\]/i.test(trimmed) || /^BUILD FAILED/i.test(trimmed)) {
|
|
59
|
+
errors.push(line);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (/^\[WARNING\]/i.test(trimmed)) {
|
|
64
|
+
warnings.push(line);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (/^\s*Compiling\s+\S+/i.test(trimmed)) {
|
|
69
|
+
compilingCount++;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (/^\s*Downloading\s+\S+/i.test(trimmed) || /^Fetching\s+/i.test(trimmed)) {
|
|
73
|
+
downloadingCount++;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (
|
|
78
|
+
/^(added|removed|changed|audited|installed)\s+\d+\s+package/i.test(trimmed) ||
|
|
79
|
+
/^\s*Finished\s+/i.test(trimmed) ||
|
|
80
|
+
/^BUILD SUCCESS/i.test(trimmed) ||
|
|
81
|
+
/^\d+\s+(vulnerabilities|packages?|warnings?|errors?)/i.test(trimmed) ||
|
|
82
|
+
/^Successfully (installed|built)/i.test(trimmed) ||
|
|
83
|
+
/^To address .* issues/i.test(trimmed) ||
|
|
84
|
+
/^Run `npm (audit|fund)`/i.test(trimmed) ||
|
|
85
|
+
/packages are looking for funding/i.test(trimmed)
|
|
86
|
+
) {
|
|
87
|
+
summary = summary ? `${summary}\n${line}` : line;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
let out = "";
|
|
93
|
+
|
|
94
|
+
const keepDep = deprecations.slice(0, DEPRECATION_KEEP);
|
|
95
|
+
for (const d of keepDep) out += `${d}\n`;
|
|
96
|
+
if (deprecations.length > DEPRECATION_KEEP) {
|
|
97
|
+
out += `... +${deprecations.length - DEPRECATION_KEEP} more deprecated packages\n`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (compilingCount > 0) {
|
|
101
|
+
out += `Compiled ${compilingCount} packages\n`;
|
|
102
|
+
}
|
|
103
|
+
if (downloadingCount > 0) {
|
|
104
|
+
out += `Downloaded ${downloadingCount} packages\n`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
for (const e of errors) out += `${e}\n`;
|
|
108
|
+
|
|
109
|
+
const keepWarnings = warnings.slice(0, 5);
|
|
110
|
+
for (const w of keepWarnings) out += `${w}\n`;
|
|
111
|
+
if (warnings.length > 5) {
|
|
112
|
+
out += `... +${warnings.length - 5} more warnings\n`;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (summary) out += `${summary}\n`;
|
|
116
|
+
|
|
117
|
+
return out.replace(/\n+$/, "") || input;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
buildOutput.filterName = "build-output";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { DEDUP_LINE_MAX } from "../constants.js";
|
|
2
|
+
|
|
3
|
+
export function dedupLog(input) {
|
|
4
|
+
const lines = input.split("\n");
|
|
5
|
+
const out = [];
|
|
6
|
+
let prev = null;
|
|
7
|
+
let runCount = 0;
|
|
8
|
+
let blankStreak = 0;
|
|
9
|
+
|
|
10
|
+
const flushRun = () => {
|
|
11
|
+
if (prev !== null && runCount > 1) {
|
|
12
|
+
out.push(` ... (${runCount - 1} duplicate lines)`);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
for (const line of lines) {
|
|
17
|
+
if (line.trim() === "") {
|
|
18
|
+
if (blankStreak < 1) out.push(line);
|
|
19
|
+
blankStreak += 1;
|
|
20
|
+
flushRun();
|
|
21
|
+
prev = null;
|
|
22
|
+
runCount = 0;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
blankStreak = 0;
|
|
26
|
+
if (line === prev) {
|
|
27
|
+
runCount += 1;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
flushRun();
|
|
31
|
+
out.push(line);
|
|
32
|
+
prev = line;
|
|
33
|
+
runCount = 1;
|
|
34
|
+
if (out.length >= DEDUP_LINE_MAX) {
|
|
35
|
+
out.push(`... (truncated at ${DEDUP_LINE_MAX} lines)`);
|
|
36
|
+
return out.join("\n");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
flushRun();
|
|
40
|
+
return out.join("\n");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
dedupLog.filterName = "dedup-log";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { FIND_PER_DIR_MAX, FIND_TOTAL_DIR_MAX } from "../constants.js";
|
|
2
|
+
|
|
3
|
+
export function find(input) {
|
|
4
|
+
const lines = input.split("\n").filter(l => l.trim());
|
|
5
|
+
if (lines.length === 0) return input;
|
|
6
|
+
|
|
7
|
+
const byDir = new Map();
|
|
8
|
+
|
|
9
|
+
for (const path of lines) {
|
|
10
|
+
|
|
11
|
+
const lastSep = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
|
|
12
|
+
let dir;
|
|
13
|
+
let basename;
|
|
14
|
+
if (lastSep === -1) {
|
|
15
|
+
dir = ".";
|
|
16
|
+
basename = path;
|
|
17
|
+
} else {
|
|
18
|
+
|
|
19
|
+
dir = path.slice(0, lastSep) || "/";
|
|
20
|
+
basename = path.slice(lastSep + 1);
|
|
21
|
+
}
|
|
22
|
+
if (!byDir.has(dir)) byDir.set(dir, []);
|
|
23
|
+
byDir.get(dir).push(basename);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const dirs = Array.from(byDir.keys()).sort();
|
|
27
|
+
let out = `${lines.length} files in ${dirs.length} dirs:\n\n`;
|
|
28
|
+
|
|
29
|
+
const showDirs = dirs.slice(0, FIND_TOTAL_DIR_MAX);
|
|
30
|
+
for (const dir of showDirs) {
|
|
31
|
+
const files = byDir.get(dir);
|
|
32
|
+
const dirLabel = dir.replace(/\\/g, "/");
|
|
33
|
+
out += `${dirLabel}/ (${files.length})\n`;
|
|
34
|
+
const showFiles = files.slice(0, FIND_PER_DIR_MAX);
|
|
35
|
+
for (const f of showFiles) out += ` ${f}\n`;
|
|
36
|
+
if (files.length > FIND_PER_DIR_MAX) {
|
|
37
|
+
out += ` +${files.length - FIND_PER_DIR_MAX}\n`;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (dirs.length > FIND_TOTAL_DIR_MAX) {
|
|
41
|
+
out += `\n+${dirs.length - FIND_TOTAL_DIR_MAX} more dirs\n`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
find.filterName = "find";
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { GIT_DIFF_HUNK_MAX_LINES } from "../constants.js";
|
|
2
|
+
|
|
3
|
+
export function gitDiff(diff, maxLines = 500) {
|
|
4
|
+
const result = [];
|
|
5
|
+
let currentFile = "";
|
|
6
|
+
let added = 0;
|
|
7
|
+
let removed = 0;
|
|
8
|
+
let inHunk = false;
|
|
9
|
+
let hunkShown = 0;
|
|
10
|
+
let hunkSkipped = 0;
|
|
11
|
+
let wasTruncated = false;
|
|
12
|
+
const maxHunkLines = GIT_DIFF_HUNK_MAX_LINES;
|
|
13
|
+
|
|
14
|
+
const lines = diff.split("\n");
|
|
15
|
+
|
|
16
|
+
outer: for (const line of lines) {
|
|
17
|
+
if (line.startsWith("diff --git")) {
|
|
18
|
+
if (hunkSkipped > 0) {
|
|
19
|
+
result.push(` ... (${hunkSkipped} lines truncated)`);
|
|
20
|
+
wasTruncated = true;
|
|
21
|
+
hunkSkipped = 0;
|
|
22
|
+
}
|
|
23
|
+
if (currentFile && (added > 0 || removed > 0)) {
|
|
24
|
+
result.push(` +${added} -${removed}`);
|
|
25
|
+
}
|
|
26
|
+
const parts = line.split(" b/");
|
|
27
|
+
currentFile = parts.length > 1 ? parts.slice(1).join(" b/") : "unknown";
|
|
28
|
+
result.push(`\n${currentFile}`);
|
|
29
|
+
added = 0;
|
|
30
|
+
removed = 0;
|
|
31
|
+
inHunk = false;
|
|
32
|
+
hunkShown = 0;
|
|
33
|
+
} else if (line.startsWith("@@")) {
|
|
34
|
+
if (hunkSkipped > 0) {
|
|
35
|
+
result.push(` ... (${hunkSkipped} lines truncated)`);
|
|
36
|
+
wasTruncated = true;
|
|
37
|
+
hunkSkipped = 0;
|
|
38
|
+
}
|
|
39
|
+
inHunk = true;
|
|
40
|
+
hunkShown = 0;
|
|
41
|
+
result.push(` ${line}`);
|
|
42
|
+
} else if (inHunk) {
|
|
43
|
+
if (line.startsWith("+") && !line.startsWith("+++")) {
|
|
44
|
+
added += 1;
|
|
45
|
+
if (hunkShown < maxHunkLines) {
|
|
46
|
+
result.push(` ${line}`);
|
|
47
|
+
hunkShown += 1;
|
|
48
|
+
} else {
|
|
49
|
+
hunkSkipped += 1;
|
|
50
|
+
}
|
|
51
|
+
} else if (line.startsWith("-") && !line.startsWith("---")) {
|
|
52
|
+
removed += 1;
|
|
53
|
+
if (hunkShown < maxHunkLines) {
|
|
54
|
+
result.push(` ${line}`);
|
|
55
|
+
hunkShown += 1;
|
|
56
|
+
} else {
|
|
57
|
+
hunkSkipped += 1;
|
|
58
|
+
}
|
|
59
|
+
} else if (hunkShown < maxHunkLines && !line.startsWith("\\")) {
|
|
60
|
+
if (hunkShown > 0) {
|
|
61
|
+
result.push(` ${line}`);
|
|
62
|
+
hunkShown += 1;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (result.length >= maxLines) {
|
|
68
|
+
result.push("\n... (more changes truncated)");
|
|
69
|
+
wasTruncated = true;
|
|
70
|
+
break outer;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (hunkSkipped > 0) {
|
|
75
|
+
result.push(` ... (${hunkSkipped} lines truncated)`);
|
|
76
|
+
wasTruncated = true;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (currentFile && (added > 0 || removed > 0)) {
|
|
80
|
+
result.push(` +${added} -${removed}`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (wasTruncated) {
|
|
84
|
+
result.push("[full diff: rtk git diff --no-compact]");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return result.join("\n");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
gitDiff.filterName = "git-diff";
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { GIT_LOG_MAX_LINES } from "../constants.js";
|
|
2
|
+
|
|
3
|
+
export function gitLog(text, maxLines = GIT_LOG_MAX_LINES) {
|
|
4
|
+
if (!text) return "";
|
|
5
|
+
|
|
6
|
+
const input = String(text);
|
|
7
|
+
const lines = input.split("\n");
|
|
8
|
+
const out = [];
|
|
9
|
+
let skipped = 0;
|
|
10
|
+
let inCommit = false;
|
|
11
|
+
let subjectSeen = false;
|
|
12
|
+
|
|
13
|
+
function pushLine(l) {
|
|
14
|
+
if (out.length < maxLines) {
|
|
15
|
+
out.push(l);
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
skipped++;
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
for (let i = 0; i < lines.length; i++) {
|
|
23
|
+
const raw = lines[i];
|
|
24
|
+
const line = raw.trimEnd();
|
|
25
|
+
const trimmed = line.trim();
|
|
26
|
+
|
|
27
|
+
if (/^commit [0-9a-f]{7,40}$/i.test(trimmed) || /^[*|/\\ ]+commit [0-9a-f]{7,40}/i.test(trimmed)) {
|
|
28
|
+
inCommit = true;
|
|
29
|
+
subjectSeen = false;
|
|
30
|
+
pushLine(line);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (inCommit) {
|
|
35
|
+
|
|
36
|
+
if (/^[*|/\\ ]*(Author|Date):/i.test(trimmed)) {
|
|
37
|
+
pushLine(trimmed);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (trimmed === "") continue;
|
|
42
|
+
|
|
43
|
+
if (!subjectSeen && /^[*|/\\ ]* \S/.test(line)) {
|
|
44
|
+
pushLine(" Subject: " + trimmed);
|
|
45
|
+
subjectSeen = true;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (/^\d+ file\w* changed/.test(trimmed)) {
|
|
50
|
+
pushLine(" " + trimmed);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (/^diff --git /.test(trimmed)) {
|
|
55
|
+
pushLine(" ... diff body omitted");
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const graphMatch = trimmed.match(/^[*|/\\ ]+([0-9a-f]{7,40}\s+.+)/i);
|
|
63
|
+
if (graphMatch) {
|
|
64
|
+
pushLine(graphMatch[1]);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (/^[0-9a-f]{7,40}\s+/.test(trimmed)) {
|
|
69
|
+
pushLine(trimmed);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (/^[*|/\\ ]+$/.test(trimmed) && /[*|/\\]/.test(trimmed)) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
pushLine(trimmed);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (skipped > 0) out.push(`... (${skipped} more lines)`);
|
|
81
|
+
|
|
82
|
+
const result = out.join("\n");
|
|
83
|
+
if (!result && input) return input;
|
|
84
|
+
if (result.length > input.length) return input;
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
gitLog.filterName = "git-log";
|