jonsoc 1.1.43
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/AGENTS.md +27 -0
- package/Dockerfile +18 -0
- package/PUBLISHING_GUIDE.md +151 -0
- package/README.md +58 -0
- package/bin/jonsoc +279 -0
- package/bunfig.toml +7 -0
- package/package.json +147 -0
- package/package.json.placeholder +11 -0
- package/parsers-config.ts +253 -0
- package/script/build.ts +115 -0
- package/script/publish-registries.ts +197 -0
- package/script/publish.ts +110 -0
- package/script/schema.ts +47 -0
- package/script/seed-e2e.ts +50 -0
- package/src/acp/README.md +164 -0
- package/src/acp/agent.ts +1437 -0
- package/src/acp/session.ts +105 -0
- package/src/acp/types.ts +22 -0
- package/src/agent/agent.ts +347 -0
- package/src/agent/generate.txt +75 -0
- package/src/agent/prompt/compaction.txt +12 -0
- package/src/agent/prompt/explore.txt +18 -0
- package/src/agent/prompt/summary.txt +11 -0
- package/src/agent/prompt/title.txt +44 -0
- package/src/auth/index.ts +73 -0
- package/src/brand/index.ts +73 -0
- package/src/bun/index.ts +139 -0
- package/src/bus/bus-event.ts +43 -0
- package/src/bus/global.ts +10 -0
- package/src/bus/index.ts +105 -0
- package/src/cli/bootstrap.ts +17 -0
- package/src/cli/cmd/acp.ts +69 -0
- package/src/cli/cmd/agent.ts +257 -0
- package/src/cli/cmd/auth.ts +405 -0
- package/src/cli/cmd/cmd.ts +7 -0
- package/src/cli/cmd/debug/agent.ts +166 -0
- package/src/cli/cmd/debug/config.ts +16 -0
- package/src/cli/cmd/debug/file.ts +97 -0
- package/src/cli/cmd/debug/index.ts +48 -0
- package/src/cli/cmd/debug/lsp.ts +52 -0
- package/src/cli/cmd/debug/ripgrep.ts +87 -0
- package/src/cli/cmd/debug/scrap.ts +16 -0
- package/src/cli/cmd/debug/skill.ts +16 -0
- package/src/cli/cmd/debug/snapshot.ts +52 -0
- package/src/cli/cmd/export.ts +88 -0
- package/src/cli/cmd/generate.ts +38 -0
- package/src/cli/cmd/github.ts +1548 -0
- package/src/cli/cmd/import.ts +99 -0
- package/src/cli/cmd/mcp.ts +765 -0
- package/src/cli/cmd/models.ts +77 -0
- package/src/cli/cmd/pr.ts +112 -0
- package/src/cli/cmd/run.ts +395 -0
- package/src/cli/cmd/serve.ts +20 -0
- package/src/cli/cmd/session.ts +135 -0
- package/src/cli/cmd/stats.ts +402 -0
- package/src/cli/cmd/tui/app.tsx +923 -0
- package/src/cli/cmd/tui/attach.ts +39 -0
- package/src/cli/cmd/tui/component/border.tsx +21 -0
- package/src/cli/cmd/tui/component/dialog-agent.tsx +31 -0
- package/src/cli/cmd/tui/component/dialog-command.tsx +162 -0
- package/src/cli/cmd/tui/component/dialog-error-log.tsx +155 -0
- package/src/cli/cmd/tui/component/dialog-mcp.tsx +86 -0
- package/src/cli/cmd/tui/component/dialog-model.tsx +234 -0
- package/src/cli/cmd/tui/component/dialog-provider.tsx +256 -0
- package/src/cli/cmd/tui/component/dialog-session-list.tsx +114 -0
- package/src/cli/cmd/tui/component/dialog-session-rename.tsx +31 -0
- package/src/cli/cmd/tui/component/dialog-stash.tsx +87 -0
- package/src/cli/cmd/tui/component/dialog-status.tsx +164 -0
- package/src/cli/cmd/tui/component/dialog-tag.tsx +44 -0
- package/src/cli/cmd/tui/component/dialog-theme-list.tsx +50 -0
- package/src/cli/cmd/tui/component/dynamic-layout.tsx +86 -0
- package/src/cli/cmd/tui/component/inspector-overlay.tsx +247 -0
- package/src/cli/cmd/tui/component/logo.tsx +88 -0
- package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +653 -0
- package/src/cli/cmd/tui/component/prompt/frecency.tsx +89 -0
- package/src/cli/cmd/tui/component/prompt/history.tsx +108 -0
- package/src/cli/cmd/tui/component/prompt/index.tsx +1347 -0
- package/src/cli/cmd/tui/component/prompt/stash.tsx +101 -0
- package/src/cli/cmd/tui/component/textarea-keybindings.ts +73 -0
- package/src/cli/cmd/tui/component/tips.tsx +153 -0
- package/src/cli/cmd/tui/component/todo-item.tsx +32 -0
- package/src/cli/cmd/tui/context/args.tsx +14 -0
- package/src/cli/cmd/tui/context/directory.ts +13 -0
- package/src/cli/cmd/tui/context/error-log.tsx +56 -0
- package/src/cli/cmd/tui/context/exit.tsx +26 -0
- package/src/cli/cmd/tui/context/helper.tsx +25 -0
- package/src/cli/cmd/tui/context/inspector.tsx +57 -0
- package/src/cli/cmd/tui/context/keybind.tsx +108 -0
- package/src/cli/cmd/tui/context/kv.tsx +53 -0
- package/src/cli/cmd/tui/context/layout.tsx +240 -0
- package/src/cli/cmd/tui/context/local.tsx +402 -0
- package/src/cli/cmd/tui/context/prompt.tsx +18 -0
- package/src/cli/cmd/tui/context/route.tsx +51 -0
- package/src/cli/cmd/tui/context/sdk.tsx +94 -0
- package/src/cli/cmd/tui/context/sync.tsx +449 -0
- package/src/cli/cmd/tui/context/theme/aura.json +69 -0
- package/src/cli/cmd/tui/context/theme/ayu.json +80 -0
- package/src/cli/cmd/tui/context/theme/carbonfox.json +248 -0
- package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +233 -0
- package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +233 -0
- package/src/cli/cmd/tui/context/theme/catppuccin.json +112 -0
- package/src/cli/cmd/tui/context/theme/cobalt2.json +228 -0
- package/src/cli/cmd/tui/context/theme/cursor.json +249 -0
- package/src/cli/cmd/tui/context/theme/dracula.json +219 -0
- package/src/cli/cmd/tui/context/theme/everforest.json +241 -0
- package/src/cli/cmd/tui/context/theme/flexoki.json +237 -0
- package/src/cli/cmd/tui/context/theme/github.json +233 -0
- package/src/cli/cmd/tui/context/theme/gruvbox.json +242 -0
- package/src/cli/cmd/tui/context/theme/jonsoc.json +245 -0
- package/src/cli/cmd/tui/context/theme/kanagawa.json +77 -0
- package/src/cli/cmd/tui/context/theme/lucent-orng.json +237 -0
- package/src/cli/cmd/tui/context/theme/material.json +235 -0
- package/src/cli/cmd/tui/context/theme/matrix.json +77 -0
- package/src/cli/cmd/tui/context/theme/mercury.json +252 -0
- package/src/cli/cmd/tui/context/theme/monokai.json +221 -0
- package/src/cli/cmd/tui/context/theme/nightowl.json +221 -0
- package/src/cli/cmd/tui/context/theme/nord.json +223 -0
- package/src/cli/cmd/tui/context/theme/one-dark.json +84 -0
- package/src/cli/cmd/tui/context/theme/orng.json +249 -0
- package/src/cli/cmd/tui/context/theme/osaka-jade.json +93 -0
- package/src/cli/cmd/tui/context/theme/palenight.json +222 -0
- package/src/cli/cmd/tui/context/theme/rosepine.json +234 -0
- package/src/cli/cmd/tui/context/theme/solarized.json +223 -0
- package/src/cli/cmd/tui/context/theme/synthwave84.json +226 -0
- package/src/cli/cmd/tui/context/theme/tokyonight.json +243 -0
- package/src/cli/cmd/tui/context/theme/vercel.json +245 -0
- package/src/cli/cmd/tui/context/theme/vesper.json +218 -0
- package/src/cli/cmd/tui/context/theme/zenburn.json +223 -0
- package/src/cli/cmd/tui/context/theme.tsx +1153 -0
- package/src/cli/cmd/tui/event.ts +48 -0
- package/src/cli/cmd/tui/hooks/use-command-registry.tsx +184 -0
- package/src/cli/cmd/tui/routes/home.tsx +198 -0
- package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +64 -0
- package/src/cli/cmd/tui/routes/session/dialog-message.tsx +109 -0
- package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +26 -0
- package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +47 -0
- package/src/cli/cmd/tui/routes/session/footer.tsx +91 -0
- package/src/cli/cmd/tui/routes/session/git-commit.tsx +59 -0
- package/src/cli/cmd/tui/routes/session/git-history.tsx +122 -0
- package/src/cli/cmd/tui/routes/session/header.tsx +185 -0
- package/src/cli/cmd/tui/routes/session/index.tsx +2363 -0
- package/src/cli/cmd/tui/routes/session/navigator-ui.tsx +214 -0
- package/src/cli/cmd/tui/routes/session/navigator.tsx +1124 -0
- package/src/cli/cmd/tui/routes/session/panel-explorer.tsx +553 -0
- package/src/cli/cmd/tui/routes/session/panel-viewer.tsx +386 -0
- package/src/cli/cmd/tui/routes/session/permission.tsx +501 -0
- package/src/cli/cmd/tui/routes/session/question.tsx +507 -0
- package/src/cli/cmd/tui/routes/session/sidebar.tsx +365 -0
- package/src/cli/cmd/tui/routes/session/vcs-diff-viewer.tsx +37 -0
- package/src/cli/cmd/tui/routes/ui-settings.tsx +449 -0
- package/src/cli/cmd/tui/thread.ts +172 -0
- package/src/cli/cmd/tui/ui/dialog-alert.tsx +90 -0
- package/src/cli/cmd/tui/ui/dialog-confirm.tsx +83 -0
- package/src/cli/cmd/tui/ui/dialog-export-options.tsx +204 -0
- package/src/cli/cmd/tui/ui/dialog-help.tsx +38 -0
- package/src/cli/cmd/tui/ui/dialog-prompt.tsx +77 -0
- package/src/cli/cmd/tui/ui/dialog-select.tsx +384 -0
- package/src/cli/cmd/tui/ui/dialog.tsx +170 -0
- package/src/cli/cmd/tui/ui/link.tsx +28 -0
- package/src/cli/cmd/tui/ui/spinner.ts +375 -0
- package/src/cli/cmd/tui/ui/toast.tsx +100 -0
- package/src/cli/cmd/tui/util/clipboard.ts +255 -0
- package/src/cli/cmd/tui/util/editor.ts +32 -0
- package/src/cli/cmd/tui/util/signal.ts +7 -0
- package/src/cli/cmd/tui/util/terminal.ts +114 -0
- package/src/cli/cmd/tui/util/transcript.ts +98 -0
- package/src/cli/cmd/tui/worker.ts +152 -0
- package/src/cli/cmd/uninstall.ts +362 -0
- package/src/cli/cmd/upgrade.ts +73 -0
- package/src/cli/cmd/web.ts +81 -0
- package/src/cli/error.ts +57 -0
- package/src/cli/network.ts +53 -0
- package/src/cli/ui.ts +119 -0
- package/src/cli/upgrade.ts +25 -0
- package/src/command/index.ts +131 -0
- package/src/command/template/initialize.txt +10 -0
- package/src/command/template/review.txt +99 -0
- package/src/config/config.ts +1404 -0
- package/src/config/markdown.ts +93 -0
- package/src/env/index.ts +26 -0
- package/src/file/ignore.ts +83 -0
- package/src/file/index.ts +432 -0
- package/src/file/ripgrep.ts +407 -0
- package/src/file/time.ts +69 -0
- package/src/file/watcher.ts +127 -0
- package/src/flag/flag.ts +80 -0
- package/src/format/formatter.ts +357 -0
- package/src/format/index.ts +137 -0
- package/src/global/index.ts +58 -0
- package/src/id/id.ts +83 -0
- package/src/ide/index.ts +76 -0
- package/src/index.ts +208 -0
- package/src/installation/index.ts +258 -0
- package/src/lsp/client.ts +252 -0
- package/src/lsp/index.ts +485 -0
- package/src/lsp/language.ts +119 -0
- package/src/lsp/server.ts +2046 -0
- package/src/mcp/auth.ts +135 -0
- package/src/mcp/index.ts +934 -0
- package/src/mcp/oauth-callback.ts +200 -0
- package/src/mcp/oauth-provider.ts +155 -0
- package/src/patch/index.ts +680 -0
- package/src/permission/arity.ts +163 -0
- package/src/permission/index.ts +210 -0
- package/src/permission/next.ts +280 -0
- package/src/plugin/codex.ts +500 -0
- package/src/plugin/copilot.ts +283 -0
- package/src/plugin/index.ts +135 -0
- package/src/project/bootstrap.ts +35 -0
- package/src/project/instance.ts +91 -0
- package/src/project/project.ts +371 -0
- package/src/project/state.ts +66 -0
- package/src/project/vcs.ts +151 -0
- package/src/provider/auth.ts +147 -0
- package/src/provider/models-macro.ts +14 -0
- package/src/provider/models.ts +114 -0
- package/src/provider/provider.ts +1220 -0
- package/src/provider/sdk/openai-compatible/src/README.md +5 -0
- package/src/provider/sdk/openai-compatible/src/index.ts +2 -0
- package/src/provider/sdk/openai-compatible/src/openai-compatible-provider.ts +100 -0
- package/src/provider/sdk/openai-compatible/src/responses/convert-to-openai-responses-input.ts +303 -0
- package/src/provider/sdk/openai-compatible/src/responses/map-openai-responses-finish-reason.ts +22 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-config.ts +18 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-error.ts +22 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-api-types.ts +207 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-language-model.ts +1732 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-prepare-tools.ts +177 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-settings.ts +1 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/code-interpreter.ts +88 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/file-search.ts +128 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/image-generation.ts +115 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/local-shell.ts +65 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/web-search-preview.ts +104 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/web-search.ts +103 -0
- package/src/provider/transform.ts +742 -0
- package/src/pty/index.ts +241 -0
- package/src/question/index.ts +176 -0
- package/src/scheduler/index.ts +61 -0
- package/src/server/error.ts +36 -0
- package/src/server/event.ts +7 -0
- package/src/server/mdns.ts +59 -0
- package/src/server/routes/config.ts +92 -0
- package/src/server/routes/experimental.ts +208 -0
- package/src/server/routes/file.ts +227 -0
- package/src/server/routes/global.ts +135 -0
- package/src/server/routes/mcp.ts +225 -0
- package/src/server/routes/permission.ts +68 -0
- package/src/server/routes/project.ts +82 -0
- package/src/server/routes/provider.ts +165 -0
- package/src/server/routes/pty.ts +169 -0
- package/src/server/routes/question.ts +98 -0
- package/src/server/routes/session.ts +939 -0
- package/src/server/routes/tui.ts +379 -0
- package/src/server/server.ts +663 -0
- package/src/session/compaction.ts +225 -0
- package/src/session/index.ts +498 -0
- package/src/session/llm.ts +288 -0
- package/src/session/message-v2.ts +740 -0
- package/src/session/message.ts +189 -0
- package/src/session/processor.ts +406 -0
- package/src/session/prompt/anthropic-20250930.txt +168 -0
- package/src/session/prompt/anthropic.txt +172 -0
- package/src/session/prompt/anthropic_spoof.txt +1 -0
- package/src/session/prompt/beast.txt +149 -0
- package/src/session/prompt/build-switch.txt +5 -0
- package/src/session/prompt/codex_header.txt +81 -0
- package/src/session/prompt/copilot-gpt-5.txt +145 -0
- package/src/session/prompt/gemini.txt +157 -0
- package/src/session/prompt/max-steps.txt +16 -0
- package/src/session/prompt/plan-reminder-anthropic.txt +67 -0
- package/src/session/prompt/plan.txt +26 -0
- package/src/session/prompt/qwen.txt +111 -0
- package/src/session/prompt.ts +1815 -0
- package/src/session/retry.ts +90 -0
- package/src/session/revert.ts +121 -0
- package/src/session/status.ts +76 -0
- package/src/session/summary.ts +150 -0
- package/src/session/system.ts +156 -0
- package/src/session/todo.ts +37 -0
- package/src/share/share-next.ts +204 -0
- package/src/share/share.ts +95 -0
- package/src/shell/shell.ts +67 -0
- package/src/skill/index.ts +1 -0
- package/src/skill/skill.ts +135 -0
- package/src/snapshot/index.ts +236 -0
- package/src/storage/storage.ts +227 -0
- package/src/tool/apply_patch.ts +279 -0
- package/src/tool/apply_patch.txt +33 -0
- package/src/tool/bash.ts +258 -0
- package/src/tool/bash.txt +115 -0
- package/src/tool/batch.ts +175 -0
- package/src/tool/batch.txt +24 -0
- package/src/tool/codesearch.ts +132 -0
- package/src/tool/codesearch.txt +12 -0
- package/src/tool/edit.ts +645 -0
- package/src/tool/edit.txt +10 -0
- package/src/tool/external-directory.ts +32 -0
- package/src/tool/glob.ts +77 -0
- package/src/tool/glob.txt +6 -0
- package/src/tool/grep.ts +154 -0
- package/src/tool/grep.txt +8 -0
- package/src/tool/invalid.ts +17 -0
- package/src/tool/ls.ts +121 -0
- package/src/tool/ls.txt +1 -0
- package/src/tool/lsp.ts +96 -0
- package/src/tool/lsp.txt +19 -0
- package/src/tool/multiedit.ts +46 -0
- package/src/tool/multiedit.txt +41 -0
- package/src/tool/plan-enter.txt +14 -0
- package/src/tool/plan-exit.txt +13 -0
- package/src/tool/plan.ts +130 -0
- package/src/tool/question.ts +33 -0
- package/src/tool/question.txt +10 -0
- package/src/tool/read.ts +202 -0
- package/src/tool/read.txt +12 -0
- package/src/tool/registry.ts +162 -0
- package/src/tool/skill.ts +82 -0
- package/src/tool/task.ts +188 -0
- package/src/tool/task.txt +60 -0
- package/src/tool/todo.ts +53 -0
- package/src/tool/todoread.txt +14 -0
- package/src/tool/todowrite.txt +167 -0
- package/src/tool/tool.ts +88 -0
- package/src/tool/truncation.ts +106 -0
- package/src/tool/webfetch.ts +182 -0
- package/src/tool/webfetch.txt +13 -0
- package/src/tool/websearch.ts +150 -0
- package/src/tool/websearch.txt +14 -0
- package/src/tool/write.ts +80 -0
- package/src/tool/write.txt +8 -0
- package/src/util/archive.ts +16 -0
- package/src/util/color.ts +19 -0
- package/src/util/context.ts +25 -0
- package/src/util/defer.ts +12 -0
- package/src/util/eventloop.ts +20 -0
- package/src/util/filesystem.ts +93 -0
- package/src/util/fn.ts +11 -0
- package/src/util/format.ts +20 -0
- package/src/util/iife.ts +3 -0
- package/src/util/keybind.ts +103 -0
- package/src/util/lazy.ts +18 -0
- package/src/util/locale.ts +81 -0
- package/src/util/lock.ts +98 -0
- package/src/util/log.ts +180 -0
- package/src/util/queue.ts +32 -0
- package/src/util/rpc.ts +66 -0
- package/src/util/scrap.ts +10 -0
- package/src/util/signal.ts +12 -0
- package/src/util/timeout.ts +14 -0
- package/src/util/token.ts +7 -0
- package/src/util/wildcard.ts +56 -0
- package/src/worktree/index.ts +524 -0
- package/sst-env.d.ts +9 -0
- package/test/acp/agent-interface.test.ts +51 -0
- package/test/acp/event-subscription.test.ts +436 -0
- package/test/agent/agent.test.ts +638 -0
- package/test/bun.test.ts +53 -0
- package/test/cli/cmd/tui/fileref.test.ts +30 -0
- package/test/cli/github-action.test.ts +129 -0
- package/test/cli/github-remote.test.ts +80 -0
- package/test/cli/tui/navigator_logic.test.ts +99 -0
- package/test/cli/tui/transcript.test.ts +297 -0
- package/test/cli/ui.test.ts +80 -0
- package/test/config/agent-color.test.ts +66 -0
- package/test/config/config.test.ts +1613 -0
- package/test/config/fixtures/empty-frontmatter.md +4 -0
- package/test/config/fixtures/frontmatter.md +28 -0
- package/test/config/fixtures/no-frontmatter.md +1 -0
- package/test/config/markdown.test.ts +192 -0
- package/test/file/ignore.test.ts +10 -0
- package/test/file/path-traversal.test.ts +198 -0
- package/test/fixture/fixture.ts +45 -0
- package/test/fixture/lsp/fake-lsp-server.js +77 -0
- package/test/ide/ide.test.ts +82 -0
- package/test/keybind.test.ts +421 -0
- package/test/lsp/client.test.ts +95 -0
- package/test/mcp/headers.test.ts +153 -0
- package/test/mcp/oauth-browser.test.ts +261 -0
- package/test/patch/patch.test.ts +348 -0
- package/test/permission/arity.test.ts +33 -0
- package/test/permission/next.test.ts +690 -0
- package/test/permission-task.test.ts +319 -0
- package/test/plugin/codex.test.ts +123 -0
- package/test/preload.ts +67 -0
- package/test/project/project.test.ts +120 -0
- package/test/provider/amazon-bedrock.test.ts +268 -0
- package/test/provider/gitlab-duo.test.ts +286 -0
- package/test/provider/provider.test.ts +2149 -0
- package/test/provider/transform.test.ts +1631 -0
- package/test/question/question.test.ts +300 -0
- package/test/scheduler.test.ts +73 -0
- package/test/server/session-list.test.ts +39 -0
- package/test/server/session-select.test.ts +78 -0
- package/test/session/compaction.test.ts +293 -0
- package/test/session/llm.test.ts +90 -0
- package/test/session/message-v2.test.ts +786 -0
- package/test/session/retry.test.ts +131 -0
- package/test/session/revert-compact.test.ts +285 -0
- package/test/session/session.test.ts +71 -0
- package/test/skill/skill.test.ts +185 -0
- package/test/snapshot/snapshot.test.ts +939 -0
- package/test/tool/__snapshots__/tool.test.ts.snap +9 -0
- package/test/tool/apply_patch.test.ts +499 -0
- package/test/tool/bash.test.ts +320 -0
- package/test/tool/external-directory.test.ts +126 -0
- package/test/tool/fixtures/large-image.png +0 -0
- package/test/tool/fixtures/models-api.json +33453 -0
- package/test/tool/grep.test.ts +109 -0
- package/test/tool/question.test.ts +105 -0
- package/test/tool/read.test.ts +332 -0
- package/test/tool/registry.test.ts +76 -0
- package/test/tool/truncation.test.ts +159 -0
- package/test/util/filesystem.test.ts +39 -0
- package/test/util/format.test.ts +59 -0
- package/test/util/iife.test.ts +36 -0
- package/test/util/lazy.test.ts +50 -0
- package/test/util/lock.test.ts +72 -0
- package/test/util/timeout.test.ts +21 -0
- package/test/util/wildcard.test.ts +75 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,1124 @@
|
|
|
1
|
+
import {
|
|
2
|
+
batch,
|
|
3
|
+
createEffect,
|
|
4
|
+
createMemo,
|
|
5
|
+
createResource,
|
|
6
|
+
createSignal,
|
|
7
|
+
For,
|
|
8
|
+
Match,
|
|
9
|
+
on,
|
|
10
|
+
onCleanup,
|
|
11
|
+
Show,
|
|
12
|
+
Switch,
|
|
13
|
+
untrack,
|
|
14
|
+
} from "solid-js"
|
|
15
|
+
import { createStore } from "solid-js/store"
|
|
16
|
+
import path from "path"
|
|
17
|
+
import type { ScrollBoxRenderable, TextareaRenderable, InputRenderable, ScrollAcceleration } from "@opentui/core"
|
|
18
|
+
import { TextAttributes } from "@opentui/core"
|
|
19
|
+
import { useKeyboard, useTerminalDimensions } from "@opentui/solid"
|
|
20
|
+
import { selectedForeground, useTheme } from "@tui/context/theme"
|
|
21
|
+
import { useSDK } from "@tui/context/sdk"
|
|
22
|
+
import { useToast } from "@tui/ui/toast"
|
|
23
|
+
import { useDialog } from "@tui/ui/dialog"
|
|
24
|
+
import { DialogAlert } from "@tui/ui/dialog-alert"
|
|
25
|
+
import { DialogPrompt } from "@tui/ui/dialog-prompt"
|
|
26
|
+
import { DialogSelect } from "@tui/ui/dialog-select"
|
|
27
|
+
import { usePromptRef } from "@tui/context/prompt"
|
|
28
|
+
import { useSync } from "@tui/context/sync"
|
|
29
|
+
import { SplitBorder } from "@tui/component/border"
|
|
30
|
+
import { useKV } from "@tui/context/kv"
|
|
31
|
+
import { useErrorLog } from "@tui/context/error-log"
|
|
32
|
+
import { useKeybind } from "@tui/context/keybind"
|
|
33
|
+
import { Filesystem } from "@/util/filesystem"
|
|
34
|
+
import { Locale } from "@/util/locale"
|
|
35
|
+
import { Global } from "@/global"
|
|
36
|
+
import { LANGUAGE_EXTENSIONS } from "@/lsp/language"
|
|
37
|
+
import type { File as FileStatus, FileContent, FileNode, VcsHistoryLine } from "@jonsoc/sdk/v2"
|
|
38
|
+
import { GitCommit } from "./git-commit"
|
|
39
|
+
import { GitHistory } from "./git-history"
|
|
40
|
+
import { VcsDiffViewer } from "./vcs-diff-viewer"
|
|
41
|
+
import { NavigatorBorderChars, Tab, ActionButton, ExplorerRow, GitRow, fileType, BinaryPreview } from "./navigator-ui"
|
|
42
|
+
|
|
43
|
+
type ExplorerEntry = {
|
|
44
|
+
node: FileNode
|
|
45
|
+
depth: number
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type NavigatorProps = {
|
|
49
|
+
width: number
|
|
50
|
+
onClose: () => void
|
|
51
|
+
open: boolean
|
|
52
|
+
side: "left" | "right"
|
|
53
|
+
wrapMode?: "word" | "none"
|
|
54
|
+
promptRef?: { focused: boolean; focus: () => void } | undefined
|
|
55
|
+
onOpenFile?: (path: string, line?: number) => void
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
type NavigatorTab = "explorer" | "git"
|
|
59
|
+
|
|
60
|
+
const STATUS_LABELS: Record<string, string> = {
|
|
61
|
+
added: "A",
|
|
62
|
+
deleted: "D",
|
|
63
|
+
modified: "M",
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
class CustomSpeedScroll implements ScrollAcceleration {
|
|
67
|
+
constructor(private speed: number) {}
|
|
68
|
+
|
|
69
|
+
tick(_now?: number): number {
|
|
70
|
+
return this.speed
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
reset(): void {}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function Navigator(props: NavigatorProps) {
|
|
77
|
+
const theme = useTheme()
|
|
78
|
+
const sdk = useSDK()
|
|
79
|
+
const toast = useToast()
|
|
80
|
+
const dialog = useDialog()
|
|
81
|
+
const promptRef = usePromptRef()
|
|
82
|
+
const sync = useSync()
|
|
83
|
+
const kv = useKV()
|
|
84
|
+
const errorLog = useErrorLog()
|
|
85
|
+
const keybind = useKeybind()
|
|
86
|
+
const term = useTerminalDimensions()
|
|
87
|
+
const [loaded, setLoaded] = createSignal(false)
|
|
88
|
+
const [tab, setTab] = kv.signal<NavigatorTab>("navigator_tab", "explorer")
|
|
89
|
+
const [selectedExplorer, setSelectedExplorer] = kv.signal("navigator_explorer_index", 0)
|
|
90
|
+
const [selectedGit, setSelectedGit] = kv.signal("navigator_git_index", 0)
|
|
91
|
+
const [activePath, setActivePath] = kv.signal<string | null>("navigator_active_path", null)
|
|
92
|
+
const [listRatio, setListRatio] = kv.signal<number>("navigator_list_ratio", 0.35)
|
|
93
|
+
const [tree, setTree] = createStore<Record<string, FileNode[]>>({})
|
|
94
|
+
const [loading, setLoading] = createStore<Record<string, boolean>>({})
|
|
95
|
+
const [showScrollbar] = kv.signal("scrollbar_enabled", true)
|
|
96
|
+
const readExpanded = () => {
|
|
97
|
+
const stored = kv.get("navigator_expanded")
|
|
98
|
+
if (!stored) return {}
|
|
99
|
+
if (typeof stored !== "object") return {}
|
|
100
|
+
if (Array.isArray(stored)) return {}
|
|
101
|
+
const next: Record<string, boolean> = {}
|
|
102
|
+
for (const [key, value] of Object.entries(stored)) {
|
|
103
|
+
if (typeof value !== "boolean") continue
|
|
104
|
+
next[key] = value
|
|
105
|
+
}
|
|
106
|
+
return next
|
|
107
|
+
}
|
|
108
|
+
const [expanded, setExpanded] = createStore<Record<string, boolean>>(readExpanded())
|
|
109
|
+
const [explorerScroll, setExplorerScroll] = createSignal<ScrollBoxRenderable | undefined>(undefined)
|
|
110
|
+
const [gitScroll, setGitScroll] = createSignal<ScrollBoxRenderable | undefined>(undefined)
|
|
111
|
+
const [commitMessage, setCommitMessage] = createSignal("")
|
|
112
|
+
|
|
113
|
+
const [status, { refetch: refreshStatus }] = createResource(
|
|
114
|
+
() => (loaded() ? "open" : undefined),
|
|
115
|
+
async () => {
|
|
116
|
+
const result = await sdk.client.file.status().catch(() => undefined)
|
|
117
|
+
if (!result?.data) return []
|
|
118
|
+
return result.data
|
|
119
|
+
},
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
const historyLimit = 60
|
|
123
|
+
const [history, { refetch: refreshHistory }] = createResource(
|
|
124
|
+
() => (loaded() ? "open" : undefined),
|
|
125
|
+
async () => {
|
|
126
|
+
const result = await sdk.client.vcs.history({ limit: historyLimit }).catch(() => undefined)
|
|
127
|
+
if (!result?.data) return []
|
|
128
|
+
return result.data
|
|
129
|
+
},
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
const [fileContent, setFileContent] = createSignal<FileContent | undefined>(undefined)
|
|
133
|
+
const [fileLoading, setFileLoading] = createSignal(false)
|
|
134
|
+
const [fileError, setFileError] = createSignal(false)
|
|
135
|
+
const [cache, setCache] = createStore<Record<string, FileContent>>({})
|
|
136
|
+
const [targetLine, setTargetLine] = createSignal<number | undefined>(undefined)
|
|
137
|
+
const [openFileInfo, setOpenFileInfo] = kv.signal<{ path: string; line: number } | undefined>(
|
|
138
|
+
"navigator_open_file",
|
|
139
|
+
undefined,
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
// Editing state - manual save only
|
|
143
|
+
const [isDirty, setIsDirty] = createSignal(false)
|
|
144
|
+
const [saveStatus, setSaveStatus] = createSignal<"idle" | "saving" | "saved" | "error">("idle")
|
|
145
|
+
let editorRef: TextareaRenderable | undefined
|
|
146
|
+
const [currentFilePath, setCurrentFilePath] = createSignal<string | null>(null)
|
|
147
|
+
|
|
148
|
+
const saveFile = async () => {
|
|
149
|
+
const filePath = activePath()
|
|
150
|
+
if (!filePath || !editorRef || !isDirty() || saveStatus() === "saving") return
|
|
151
|
+
|
|
152
|
+
const content = editorRef.plainText
|
|
153
|
+
setSaveStatus("saving")
|
|
154
|
+
try {
|
|
155
|
+
const directory = sync.data.path.directory
|
|
156
|
+
const fullPath = path.isAbsolute(filePath) ? filePath : path.join(directory, filePath)
|
|
157
|
+
|
|
158
|
+
await Bun.write(fullPath, content)
|
|
159
|
+
|
|
160
|
+
setIsDirty(false)
|
|
161
|
+
setSaveStatus("saved")
|
|
162
|
+
// Update cache with new content
|
|
163
|
+
setCache(filePath, { type: "text", content })
|
|
164
|
+
setFileContent({ type: "text", content })
|
|
165
|
+
setTimeout(() => setSaveStatus("idle"), 2000)
|
|
166
|
+
} catch (err: any) {
|
|
167
|
+
const fullMessage = `Failed to save ${filePath}\n\n${err.message || "FileSystem error"}`
|
|
168
|
+
setSaveStatus("error")
|
|
169
|
+
errorLog.add(fullMessage, "Navigator")
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const handleEditorChange = () => {
|
|
174
|
+
setIsDirty(true)
|
|
175
|
+
setSaveStatus("idle")
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
onCleanup(() => {
|
|
179
|
+
if (isDirty()) {
|
|
180
|
+
void saveFile()
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
const listWidth = createMemo(() => {
|
|
185
|
+
if (!props.open) return 0
|
|
186
|
+
const available = Math.max(0, props.width)
|
|
187
|
+
const min = Math.min(20, available)
|
|
188
|
+
const max = Math.max(min, available - 20)
|
|
189
|
+
const width = Math.floor(available * listRatio())
|
|
190
|
+
return Math.min(max, Math.max(min, width))
|
|
191
|
+
})
|
|
192
|
+
const viewerWidth = createMemo(() => (props.open ? Math.max(0, props.width - listWidth()) : 0))
|
|
193
|
+
|
|
194
|
+
const displayRoot = createMemo(() => {
|
|
195
|
+
const directory = sync.data.path.directory || process.cwd()
|
|
196
|
+
const replaced = directory.replace(Global.Path.home, "~")
|
|
197
|
+
return Locale.truncateMiddle(replaced, 36)
|
|
198
|
+
})
|
|
199
|
+
const branch = createMemo(() => sync.data.vcs?.branch)
|
|
200
|
+
|
|
201
|
+
const statusEntries = createMemo(() => status() ?? [])
|
|
202
|
+
const statusMap = createMemo(() => {
|
|
203
|
+
const map = new Map<string, FileStatus>()
|
|
204
|
+
for (const entry of statusEntries()) {
|
|
205
|
+
map.set(entry.path, entry)
|
|
206
|
+
}
|
|
207
|
+
return map
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
const explorerEntries = createMemo(() => {
|
|
211
|
+
const result: ExplorerEntry[] = []
|
|
212
|
+
|
|
213
|
+
const add = (dir: string, depth: number) => {
|
|
214
|
+
const nodes = tree[dir] ?? []
|
|
215
|
+
for (const node of nodes) {
|
|
216
|
+
result.push({ node, depth })
|
|
217
|
+
if (node.type !== "directory") continue
|
|
218
|
+
if (!expanded[node.path]) continue
|
|
219
|
+
add(node.path, depth + 1)
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
add("", 0)
|
|
224
|
+
return result
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
const gitEntries = createMemo(() => {
|
|
228
|
+
const entries = [...statusEntries()]
|
|
229
|
+
const order = {
|
|
230
|
+
added: 0,
|
|
231
|
+
modified: 1,
|
|
232
|
+
deleted: 2,
|
|
233
|
+
}
|
|
234
|
+
return entries.toSorted((a, b) => {
|
|
235
|
+
const orderDiff = order[a.status] - order[b.status]
|
|
236
|
+
if (orderDiff !== 0) return orderDiff
|
|
237
|
+
return a.path.localeCompare(b.path)
|
|
238
|
+
})
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
// Auto-refresh Git status periodically and on save
|
|
242
|
+
createEffect(() => {
|
|
243
|
+
if (tab() !== "git" || !props.open) return
|
|
244
|
+
const id = setInterval(refreshGit, 10000)
|
|
245
|
+
onCleanup(() => clearInterval(id))
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
createEffect(
|
|
249
|
+
on(saveStatus, (status) => {
|
|
250
|
+
if (status === "saved") {
|
|
251
|
+
refreshGit()
|
|
252
|
+
}
|
|
253
|
+
}),
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
const activeStatus = createMemo(() => {
|
|
257
|
+
const file = activePath()
|
|
258
|
+
if (!file) return undefined
|
|
259
|
+
return statusMap().get(file)
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
const viewTitle = createMemo(() => {
|
|
263
|
+
const file = activePath()
|
|
264
|
+
if (!file) return "File Viewer"
|
|
265
|
+
const statusEntry = activeStatus()
|
|
266
|
+
const filename = path.basename(file)
|
|
267
|
+
const dirname = path.dirname(file)
|
|
268
|
+
const displayPath = dirname === "." ? "./ " : `${dirname}/ `
|
|
269
|
+
const prefix = statusEntry ? `${STATUS_LABELS[statusEntry.status]} ` : ""
|
|
270
|
+
return `${prefix}${displayPath}${filename}`
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
const hasExplorerEntries = createMemo(() => explorerEntries().length > 0)
|
|
274
|
+
const hasGitEntries = createMemo(() => gitEntries().length > 0)
|
|
275
|
+
const historyEntries = createMemo(() => history() ?? [])
|
|
276
|
+
const historyHeight = createMemo(() => Math.max(8, Math.floor(term().height * 0.35)))
|
|
277
|
+
|
|
278
|
+
const viewportOptions = createMemo(() => ({
|
|
279
|
+
paddingLeft: 1,
|
|
280
|
+
paddingRight: showScrollbar() ? 2 : 1,
|
|
281
|
+
}))
|
|
282
|
+
const verticalScrollbarOptions = createMemo(() => ({
|
|
283
|
+
paddingLeft: 1,
|
|
284
|
+
visible: showScrollbar(),
|
|
285
|
+
trackOptions: {
|
|
286
|
+
backgroundColor: theme.theme.backgroundElement,
|
|
287
|
+
foregroundColor: theme.theme.border,
|
|
288
|
+
},
|
|
289
|
+
}))
|
|
290
|
+
|
|
291
|
+
createEffect(() => {
|
|
292
|
+
const next: Record<string, boolean> = {}
|
|
293
|
+
for (const [key, value] of Object.entries(expanded)) {
|
|
294
|
+
next[key] = value
|
|
295
|
+
}
|
|
296
|
+
kv.set("navigator_expanded", next)
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
createEffect(() => {
|
|
300
|
+
const scroll = explorerScroll()
|
|
301
|
+
const entry = selectedExplorerEntry()
|
|
302
|
+
if (!scroll || !entry) return
|
|
303
|
+
ensureVisible(scroll, entry.node.path)
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
createEffect(() => {
|
|
307
|
+
const scroll = gitScroll()
|
|
308
|
+
const entry = selectedGitEntry()
|
|
309
|
+
if (!scroll || !entry) return
|
|
310
|
+
ensureVisible(scroll, entry.path)
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
const selectedExplorerEntry = createMemo(() => {
|
|
314
|
+
const list = explorerEntries()
|
|
315
|
+
if (list.length === 0) return undefined
|
|
316
|
+
const index = selectedExplorer()
|
|
317
|
+
if (index < 0) return undefined
|
|
318
|
+
if (index >= list.length) return undefined
|
|
319
|
+
return list[index]
|
|
320
|
+
})
|
|
321
|
+
|
|
322
|
+
const selectedGitEntry = createMemo(() => {
|
|
323
|
+
const list = gitEntries()
|
|
324
|
+
if (list.length === 0) return undefined
|
|
325
|
+
const index = selectedGit()
|
|
326
|
+
if (index < 0) return undefined
|
|
327
|
+
if (index >= list.length) return undefined
|
|
328
|
+
return list[index]
|
|
329
|
+
})
|
|
330
|
+
|
|
331
|
+
const fileData = createMemo(() => fileContent())
|
|
332
|
+
const resizeLeft = createMemo(() => keybind.print("navigator_resize_narrow"))
|
|
333
|
+
const resizeRight = createMemo(() => keybind.print("navigator_resize_wide"))
|
|
334
|
+
const resizeLabel = createMemo(() => {
|
|
335
|
+
if (!resizeLeft() && !resizeRight()) return ""
|
|
336
|
+
return `${resizeLeft() || ""}${resizeLeft() && resizeRight() ? "/" : ""}${resizeRight() || ""} resize`
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
const ensureVisible = (scroll: ScrollBoxRenderable | undefined, id: string) => {
|
|
340
|
+
if (!scroll) return
|
|
341
|
+
const child = scroll.getChildren().find((entry) => entry.id === id)
|
|
342
|
+
if (!child) return
|
|
343
|
+
const y = child.y - scroll.y
|
|
344
|
+
if (y >= scroll.height) scroll.scrollBy(y - scroll.height + 1)
|
|
345
|
+
if (y < 0) scroll.scrollBy(y)
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const selectExplorerIndex = (index: number) => {
|
|
349
|
+
const list = explorerEntries()
|
|
350
|
+
if (list.length === 0) return
|
|
351
|
+
const next = Math.min(Math.max(index, 0), list.length - 1)
|
|
352
|
+
setSelectedExplorer(() => next)
|
|
353
|
+
const entry = list[next]
|
|
354
|
+
if (!entry) return
|
|
355
|
+
ensureVisible(explorerScroll(), entry.node.path)
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
const selectGitIndex = (index: number) => {
|
|
359
|
+
const list = gitEntries()
|
|
360
|
+
if (list.length === 0) return
|
|
361
|
+
const next = Math.min(Math.max(index, 0), list.length - 1)
|
|
362
|
+
setSelectedGit(() => next)
|
|
363
|
+
const entry = list[next]
|
|
364
|
+
if (!entry) return
|
|
365
|
+
ensureVisible(gitScroll(), entry.path)
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
const loadDirectory = async (dir: string) => {
|
|
369
|
+
if (loading[dir]) return
|
|
370
|
+
setLoading(dir, true)
|
|
371
|
+
const result = await sdk.client.file.list({ path: dir }).catch(() => undefined)
|
|
372
|
+
if (!result?.data) {
|
|
373
|
+
setLoading(dir, false)
|
|
374
|
+
toast.show({ variant: "error", message: `Failed to load ${dir || "project"} files` })
|
|
375
|
+
return
|
|
376
|
+
}
|
|
377
|
+
setTree(dir, result.data)
|
|
378
|
+
setLoading(dir, false)
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
const toggleDirectory = async (node: FileNode) => {
|
|
382
|
+
if (node.type !== "directory") return
|
|
383
|
+
const isExpanded = expanded[node.path] ?? false
|
|
384
|
+
if (isExpanded) {
|
|
385
|
+
setExpanded(node.path, false)
|
|
386
|
+
return
|
|
387
|
+
}
|
|
388
|
+
setExpanded(node.path, true)
|
|
389
|
+
if (tree[node.path]) return
|
|
390
|
+
await loadDirectory(node.path)
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
createEffect(() => {
|
|
394
|
+
if (!loaded()) return
|
|
395
|
+
for (const [key, value] of Object.entries(expanded)) {
|
|
396
|
+
if (!value) continue
|
|
397
|
+
if (!key) continue
|
|
398
|
+
if (tree[key]) continue
|
|
399
|
+
void loadDirectory(key)
|
|
400
|
+
}
|
|
401
|
+
})
|
|
402
|
+
|
|
403
|
+
const openFilePath = async (nextPath: string) => {
|
|
404
|
+
const current = activePath()
|
|
405
|
+
if (current === nextPath) {
|
|
406
|
+
if (loaded()) {
|
|
407
|
+
void loadFile(nextPath, true)
|
|
408
|
+
}
|
|
409
|
+
return
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
if (isDirty()) {
|
|
413
|
+
await saveFile()
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
batch(() => {
|
|
417
|
+
setFileLoading(true)
|
|
418
|
+
setFileError(false)
|
|
419
|
+
setIsDirty(false)
|
|
420
|
+
setSaveStatus("idle")
|
|
421
|
+
setActivePath(() => nextPath)
|
|
422
|
+
setTargetLine(undefined)
|
|
423
|
+
})
|
|
424
|
+
// Notify parent/sync navigation state
|
|
425
|
+
props.onOpenFile?.(nextPath)
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const openFile = (node: FileNode) => {
|
|
429
|
+
if (node.type !== "file") return
|
|
430
|
+
openFilePath(node.path)
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
const openFileAtLine = async (path: string, line?: number) => {
|
|
434
|
+
const current = activePath()
|
|
435
|
+
if (current !== path) {
|
|
436
|
+
batch(() => {
|
|
437
|
+
// Set loading state FIRST to prevent "No content" flash
|
|
438
|
+
setFileLoading(true)
|
|
439
|
+
setFileError(false)
|
|
440
|
+
setIsDirty(false)
|
|
441
|
+
setSaveStatus("idle")
|
|
442
|
+
setActivePath(() => path)
|
|
443
|
+
})
|
|
444
|
+
// Notify parent/sync navigation state - this will update openFileInfo via KV
|
|
445
|
+
props.onOpenFile?.(path, line)
|
|
446
|
+
// loadFile will be triggered by the effect on activePath
|
|
447
|
+
} else if (loaded()) {
|
|
448
|
+
// Force reload if path is the same
|
|
449
|
+
void loadFile(path, true)
|
|
450
|
+
}
|
|
451
|
+
if (line && line > 0) {
|
|
452
|
+
setTargetLine(line)
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
const handleExplorerSelect = async () => {
|
|
457
|
+
const entry = selectedExplorerEntry()
|
|
458
|
+
if (!entry) return
|
|
459
|
+
if (entry.node.type === "directory") {
|
|
460
|
+
await toggleDirectory(entry.node)
|
|
461
|
+
return
|
|
462
|
+
}
|
|
463
|
+
openFile(entry.node)
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
const handleGitSelect = () => {
|
|
467
|
+
const entry = selectedGitEntry()
|
|
468
|
+
if (!entry) return
|
|
469
|
+
openFilePath(entry.path)
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
const [currentLoadFile, setCurrentLoadFile] = createSignal<string | undefined>(undefined)
|
|
473
|
+
const [loadNonce, setLoadNonce] = createSignal(0)
|
|
474
|
+
|
|
475
|
+
const loadFile = async (file: string, force = false) => {
|
|
476
|
+
// Check loading state and path in a single untracked lookup to avoid loops
|
|
477
|
+
const alreadyLoading = untrack(() => fileLoading() && currentLoadFile() === file)
|
|
478
|
+
if (alreadyLoading) return
|
|
479
|
+
|
|
480
|
+
const nonce = loadNonce() + 1
|
|
481
|
+
|
|
482
|
+
batch(() => {
|
|
483
|
+
setLoadNonce(nonce)
|
|
484
|
+
setCurrentLoadFile(() => file)
|
|
485
|
+
|
|
486
|
+
// Clear previous content and state immediately before loading
|
|
487
|
+
setFileContent(undefined)
|
|
488
|
+
setFileLoading(true)
|
|
489
|
+
setFileError(false)
|
|
490
|
+
setIsDirty(false)
|
|
491
|
+
setSaveStatus("idle")
|
|
492
|
+
})
|
|
493
|
+
|
|
494
|
+
if (!force) {
|
|
495
|
+
const cached = cache[file]
|
|
496
|
+
if (cached) {
|
|
497
|
+
if (loadNonce() !== nonce) return
|
|
498
|
+
batch(() => {
|
|
499
|
+
setFileContent(cached)
|
|
500
|
+
setFileLoading(false)
|
|
501
|
+
setFileError(false)
|
|
502
|
+
setCurrentLoadFile(() => undefined)
|
|
503
|
+
})
|
|
504
|
+
return
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
const result = await sdk.client.file.read({ path: file }).catch(() => undefined)
|
|
509
|
+
if (loadNonce() !== nonce) return
|
|
510
|
+
|
|
511
|
+
batch(() => {
|
|
512
|
+
if (!result?.data) {
|
|
513
|
+
setFileContent(undefined)
|
|
514
|
+
setFileLoading(false)
|
|
515
|
+
setFileError(true)
|
|
516
|
+
setCurrentLoadFile(() => undefined)
|
|
517
|
+
return
|
|
518
|
+
}
|
|
519
|
+
setCache(file, result.data)
|
|
520
|
+
setFileContent(result.data)
|
|
521
|
+
setFileLoading(false)
|
|
522
|
+
setCurrentLoadFile(() => undefined)
|
|
523
|
+
})
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
const adjustListWidth = (delta: number) => {
|
|
527
|
+
setListRatio((prev) => {
|
|
528
|
+
const base = typeof prev === "function" ? prev(0.35) : prev
|
|
529
|
+
const next = Math.min(0.6, Math.max(0.2, base + delta))
|
|
530
|
+
return next
|
|
531
|
+
})
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
const runPrompt = (input: string, mode?: "normal" | "shell") => {
|
|
535
|
+
const ref = promptRef.current
|
|
536
|
+
if (!ref) return
|
|
537
|
+
ref.set({
|
|
538
|
+
input,
|
|
539
|
+
mode,
|
|
540
|
+
parts: [],
|
|
541
|
+
})
|
|
542
|
+
ref.focus()
|
|
543
|
+
ref.submit()
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
const runCommand = async (command: string) => {
|
|
547
|
+
if (isDirty()) await saveFile()
|
|
548
|
+
runPrompt(`/${command}`)
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
const runShell = async (command: string) => {
|
|
552
|
+
if (isDirty()) await saveFile()
|
|
553
|
+
runPrompt(command, "shell")
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
const refreshGit = () => {
|
|
557
|
+
refreshStatus()
|
|
558
|
+
refreshHistory()
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
const handleCommit = async () => {
|
|
562
|
+
const msg = commitMessage().trim()
|
|
563
|
+
if (!msg) return
|
|
564
|
+
if (isDirty()) await saveFile()
|
|
565
|
+
|
|
566
|
+
const directory = sync.data.path.directory
|
|
567
|
+
try {
|
|
568
|
+
const proc = Bun.spawn({
|
|
569
|
+
cmd: ["git", "add", "."],
|
|
570
|
+
cwd: directory,
|
|
571
|
+
stdout: "pipe",
|
|
572
|
+
stderr: "pipe",
|
|
573
|
+
})
|
|
574
|
+
await proc.exited
|
|
575
|
+
|
|
576
|
+
const commitProc = Bun.spawn({
|
|
577
|
+
cmd: ["git", "commit", "-m", msg],
|
|
578
|
+
cwd: directory,
|
|
579
|
+
stdout: "pipe",
|
|
580
|
+
stderr: "pipe",
|
|
581
|
+
})
|
|
582
|
+
const exitCode = await commitProc.exited
|
|
583
|
+
|
|
584
|
+
if (exitCode === 0) {
|
|
585
|
+
toast.show({ variant: "success", message: "Changes committed" })
|
|
586
|
+
refreshGit()
|
|
587
|
+
} else {
|
|
588
|
+
const stderr = await new Response(commitProc.stderr).text()
|
|
589
|
+
toast.show({ variant: "error", message: `Commit failed: ${stderr}` })
|
|
590
|
+
}
|
|
591
|
+
} catch (err: any) {
|
|
592
|
+
toast.show({ variant: "error", message: `Commit failed: ${err.message}` })
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
setCommitMessage("")
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
const openBranchSwitcher = async () => {
|
|
599
|
+
const list = await fetch(`${sdk.url}/vcs/branches`)
|
|
600
|
+
.then((r) => r.json())
|
|
601
|
+
.catch(() => [])
|
|
602
|
+
if (!list || !Array.isArray(list)) return
|
|
603
|
+
|
|
604
|
+
const current = branch()
|
|
605
|
+
dialog.replace(() => (
|
|
606
|
+
<DialogSelect
|
|
607
|
+
title="Switch branch"
|
|
608
|
+
options={[
|
|
609
|
+
{ title: "+ New branch...", value: "__new__" },
|
|
610
|
+
...list.map((b: string) => ({
|
|
611
|
+
title: b,
|
|
612
|
+
value: b,
|
|
613
|
+
})),
|
|
614
|
+
]}
|
|
615
|
+
current={current}
|
|
616
|
+
onSelect={async (opt) => {
|
|
617
|
+
if (opt.value === "__new__") {
|
|
618
|
+
dialog.replace(() => (
|
|
619
|
+
<DialogPrompt
|
|
620
|
+
title="Create branch"
|
|
621
|
+
placeholder="branch-name"
|
|
622
|
+
onConfirm={async (name) => {
|
|
623
|
+
dialog.clear()
|
|
624
|
+
const trimmed = name.trim()
|
|
625
|
+
if (!trimmed) return
|
|
626
|
+
await runShell(`git checkout -b ${trimmed}`)
|
|
627
|
+
refreshGit()
|
|
628
|
+
}}
|
|
629
|
+
onCancel={() => openBranchSwitcher()}
|
|
630
|
+
/>
|
|
631
|
+
))
|
|
632
|
+
return
|
|
633
|
+
}
|
|
634
|
+
dialog.clear()
|
|
635
|
+
await fetch(`${sdk.url}/vcs/checkout`, {
|
|
636
|
+
method: "POST",
|
|
637
|
+
headers: { "Content-Type": "application/json" },
|
|
638
|
+
body: JSON.stringify({ branch: opt.value }),
|
|
639
|
+
})
|
|
640
|
+
refreshGit()
|
|
641
|
+
}}
|
|
642
|
+
/>
|
|
643
|
+
))
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
const openMergeDialog = () => {
|
|
647
|
+
dialog.replace(() => (
|
|
648
|
+
<DialogPrompt
|
|
649
|
+
title="Merge branch"
|
|
650
|
+
placeholder="Branch name (e.g. main)"
|
|
651
|
+
onConfirm={(value) => {
|
|
652
|
+
dialog.clear()
|
|
653
|
+
const name = value.trim()
|
|
654
|
+
if (!name) return
|
|
655
|
+
runShell(`git merge ${name}`)
|
|
656
|
+
}}
|
|
657
|
+
onCancel={() => dialog.clear()}
|
|
658
|
+
/>
|
|
659
|
+
))
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
useKeyboard((evt) => {
|
|
663
|
+
if (!props.open) return
|
|
664
|
+
if (dialog.stack.length > 0) return
|
|
665
|
+
if (keybind.match("navigator_resize_narrow", evt)) {
|
|
666
|
+
evt.preventDefault()
|
|
667
|
+
adjustListWidth(-0.05)
|
|
668
|
+
return
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
if (keybind.match("navigator_resize_wide", evt)) {
|
|
672
|
+
evt.preventDefault()
|
|
673
|
+
adjustListWidth(0.05)
|
|
674
|
+
return
|
|
675
|
+
}
|
|
676
|
+
if (promptRef.current?.focused) return
|
|
677
|
+
if (evt.name === "escape") {
|
|
678
|
+
evt.preventDefault()
|
|
679
|
+
return
|
|
680
|
+
}
|
|
681
|
+
if (evt.name === "tab") {
|
|
682
|
+
evt.preventDefault()
|
|
683
|
+
setTab((value) => (value === "explorer" ? "git" : "explorer"))
|
|
684
|
+
return
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
if (tab() === "explorer") {
|
|
688
|
+
if (evt.name === "up") {
|
|
689
|
+
selectExplorerIndex(selectedExplorer() - 1)
|
|
690
|
+
return
|
|
691
|
+
}
|
|
692
|
+
if (evt.name === "down") {
|
|
693
|
+
selectExplorerIndex(selectedExplorer() + 1)
|
|
694
|
+
return
|
|
695
|
+
}
|
|
696
|
+
if (evt.name === "home") {
|
|
697
|
+
selectExplorerIndex(0)
|
|
698
|
+
return
|
|
699
|
+
}
|
|
700
|
+
if (evt.name === "end") {
|
|
701
|
+
selectExplorerIndex(explorerEntries().length - 1)
|
|
702
|
+
return
|
|
703
|
+
}
|
|
704
|
+
if (evt.name === "left") {
|
|
705
|
+
const entry = selectedExplorerEntry()
|
|
706
|
+
if (!entry) return
|
|
707
|
+
if (entry.node.type !== "directory") return
|
|
708
|
+
if (!expanded[entry.node.path]) return
|
|
709
|
+
setExpanded(entry.node.path, false)
|
|
710
|
+
return
|
|
711
|
+
}
|
|
712
|
+
if (evt.name === "right") {
|
|
713
|
+
handleExplorerSelect()
|
|
714
|
+
return
|
|
715
|
+
}
|
|
716
|
+
if (evt.name === "return") {
|
|
717
|
+
handleExplorerSelect()
|
|
718
|
+
return
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
if (tab() === "git") {
|
|
723
|
+
if (evt.name === "up") {
|
|
724
|
+
selectGitIndex(selectedGit() - 1)
|
|
725
|
+
return
|
|
726
|
+
}
|
|
727
|
+
if (evt.name === "down") {
|
|
728
|
+
selectGitIndex(selectedGit() + 1)
|
|
729
|
+
return
|
|
730
|
+
}
|
|
731
|
+
if (evt.name === "home") {
|
|
732
|
+
selectGitIndex(0)
|
|
733
|
+
return
|
|
734
|
+
}
|
|
735
|
+
if (evt.name === "end") {
|
|
736
|
+
selectGitIndex(gitEntries().length - 1)
|
|
737
|
+
return
|
|
738
|
+
}
|
|
739
|
+
if (evt.name === "return") {
|
|
740
|
+
handleGitSelect()
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
})
|
|
744
|
+
|
|
745
|
+
// Auto-save when closing the navigator
|
|
746
|
+
createEffect(() => {
|
|
747
|
+
if (!props.open && isDirty()) {
|
|
748
|
+
void saveFile()
|
|
749
|
+
}
|
|
750
|
+
})
|
|
751
|
+
|
|
752
|
+
createEffect(() => {
|
|
753
|
+
const list = explorerEntries()
|
|
754
|
+
if (list.length === 0) return
|
|
755
|
+
const current = selectedExplorer()
|
|
756
|
+
if (current < list.length) return
|
|
757
|
+
// Only update if out of bounds
|
|
758
|
+
setSelectedExplorer(() => list.length - 1)
|
|
759
|
+
})
|
|
760
|
+
|
|
761
|
+
// Sync selectedExplorer with activePath so the selected file is highlighted in explorer
|
|
762
|
+
createEffect(() => {
|
|
763
|
+
const path = activePath()
|
|
764
|
+
if (!path) return
|
|
765
|
+
const list = explorerEntries()
|
|
766
|
+
const index = list.findIndex((entry) => entry.node.path === path)
|
|
767
|
+
if (index === -1) return
|
|
768
|
+
// Only update if different to avoid cycle
|
|
769
|
+
if (selectedExplorer() === index) return
|
|
770
|
+
setSelectedExplorer(() => index)
|
|
771
|
+
})
|
|
772
|
+
|
|
773
|
+
createEffect(() => {
|
|
774
|
+
if (loaded()) return
|
|
775
|
+
setLoaded(true)
|
|
776
|
+
loadDirectory("")
|
|
777
|
+
})
|
|
778
|
+
|
|
779
|
+
createEffect(() => {
|
|
780
|
+
const file = activePath()
|
|
781
|
+
const fileInfo = openFileInfo()
|
|
782
|
+
const isLoaded = loaded()
|
|
783
|
+
|
|
784
|
+
if (!isLoaded) return
|
|
785
|
+
|
|
786
|
+
if (!file) {
|
|
787
|
+
untrack(() => {
|
|
788
|
+
setFileContent(undefined)
|
|
789
|
+
setFileLoading(false)
|
|
790
|
+
setFileError(false)
|
|
791
|
+
// Clear editor when no file is selected
|
|
792
|
+
if (editorRef) {
|
|
793
|
+
editorRef.setText("")
|
|
794
|
+
}
|
|
795
|
+
})
|
|
796
|
+
return
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
// Wrap state updates and loading logic in untrack to prevent recursive loops
|
|
800
|
+
// We only want this effect to trigger on activePath, openFileInfo, or loaded changes.
|
|
801
|
+
untrack(() => {
|
|
802
|
+
// Skip if already loading this file
|
|
803
|
+
if (fileLoading() && currentLoadFile() === file) return
|
|
804
|
+
|
|
805
|
+
if (fileInfo?.path === file) {
|
|
806
|
+
setTargetLine(() => fileInfo.line)
|
|
807
|
+
// Clear navigation request to avoid re-triggering this repeatedly if it fails
|
|
808
|
+
setOpenFileInfo(() => undefined)
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
void loadFile(file)
|
|
812
|
+
})
|
|
813
|
+
})
|
|
814
|
+
|
|
815
|
+
createEffect(() => {
|
|
816
|
+
const data = fileData()
|
|
817
|
+
if (!data) return
|
|
818
|
+
if (data.encoding === "base64") return
|
|
819
|
+
// Clear targetLine after file data loads
|
|
820
|
+
if (targetLine()) {
|
|
821
|
+
setTargetLine(undefined)
|
|
822
|
+
}
|
|
823
|
+
})
|
|
824
|
+
|
|
825
|
+
// Initialize edit content when file data loads - only if file changed
|
|
826
|
+
createEffect(
|
|
827
|
+
on(fileData, (data) => {
|
|
828
|
+
const path = activePath()
|
|
829
|
+
if (!data || data.encoding === "base64" || !path) return
|
|
830
|
+
setCurrentFilePath(() => path)
|
|
831
|
+
setIsDirty(false)
|
|
832
|
+
setSaveStatus("idle")
|
|
833
|
+
if (editorRef && editorRef.plainText !== data.content) {
|
|
834
|
+
editorRef.setText(data.content ?? "")
|
|
835
|
+
}
|
|
836
|
+
}),
|
|
837
|
+
)
|
|
838
|
+
|
|
839
|
+
// Compute viewer state as a discriminated union for exclusive rendering
|
|
840
|
+
const viewerState = createMemo(() => {
|
|
841
|
+
const path = activePath()
|
|
842
|
+
if (!path) return { type: "empty" as const }
|
|
843
|
+
if (fileLoading()) return { type: "loading" as const }
|
|
844
|
+
if (fileError()) return { type: "error" as const }
|
|
845
|
+
const data = fileData()
|
|
846
|
+
if (!data) return { type: "no-content" as const }
|
|
847
|
+
if (data.encoding === "base64") return { type: "binary" as const, data }
|
|
848
|
+
return { type: "text" as const, data }
|
|
849
|
+
})
|
|
850
|
+
|
|
851
|
+
// Focus editor when clicking on the editor area
|
|
852
|
+
const focusEditor = () => {
|
|
853
|
+
if (viewerState().type === "text") {
|
|
854
|
+
setTimeout(() => editorRef?.focus(), 0)
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
const fileViewer = () => (
|
|
859
|
+
<scrollbox
|
|
860
|
+
flexGrow={1}
|
|
861
|
+
height="100%"
|
|
862
|
+
paddingTop={1}
|
|
863
|
+
viewportOptions={viewportOptions()}
|
|
864
|
+
verticalScrollbarOptions={verticalScrollbarOptions()}
|
|
865
|
+
scrollAcceleration={new CustomSpeedScroll(3)}
|
|
866
|
+
>
|
|
867
|
+
<Switch>
|
|
868
|
+
<Match when={viewerState().type === "empty"}>
|
|
869
|
+
<text fg={theme.theme.textMuted}>Select a file to edit</text>
|
|
870
|
+
</Match>
|
|
871
|
+
<Match when={viewerState().type === "loading"}>
|
|
872
|
+
<text fg={theme.theme.textMuted}>Loading...</text>
|
|
873
|
+
</Match>
|
|
874
|
+
<Match when={viewerState().type === "error"}>
|
|
875
|
+
<text fg={theme.theme.textMuted}>Unable to read file</text>
|
|
876
|
+
</Match>
|
|
877
|
+
<Match when={viewerState().type === "no-content"}>
|
|
878
|
+
<text fg={theme.theme.textMuted}>No content</text>
|
|
879
|
+
</Match>
|
|
880
|
+
<Match when={viewerState().type === "binary"}>
|
|
881
|
+
<BinaryPreview content={(viewerState() as { type: "binary"; data: FileContent }).data} />
|
|
882
|
+
</Match>
|
|
883
|
+
<Match when={viewerState().type === "text"}>
|
|
884
|
+
<box flexDirection="column" flexGrow={1} onMouseUp={focusEditor}>
|
|
885
|
+
<line_number
|
|
886
|
+
fg={theme.theme.textMuted}
|
|
887
|
+
bg={theme.theme.background}
|
|
888
|
+
paddingRight={1}
|
|
889
|
+
minWidth={3}
|
|
890
|
+
showLineNumbers={true}
|
|
891
|
+
flexGrow={1}
|
|
892
|
+
>
|
|
893
|
+
<textarea
|
|
894
|
+
ref={(r: TextareaRenderable) => {
|
|
895
|
+
editorRef = r
|
|
896
|
+
// Set initial content when ref is assigned
|
|
897
|
+
const state = viewerState()
|
|
898
|
+
if (state.type === "text" && state.data.content !== undefined && r.plainText !== state.data.content) {
|
|
899
|
+
r.setText(state.data.content ?? "")
|
|
900
|
+
}
|
|
901
|
+
}}
|
|
902
|
+
textColor={theme.theme.text}
|
|
903
|
+
focusedTextColor={theme.theme.text}
|
|
904
|
+
cursorColor={theme.theme.text}
|
|
905
|
+
focusedBackgroundColor={theme.theme.background}
|
|
906
|
+
minHeight={10}
|
|
907
|
+
flexGrow={1}
|
|
908
|
+
wrapMode={props.wrapMode ?? "none"}
|
|
909
|
+
syntaxStyle={theme.syntax()}
|
|
910
|
+
onContentChange={handleEditorChange}
|
|
911
|
+
onKeyDown={(e: { name: string; ctrl?: boolean; meta?: boolean; preventDefault: () => void }) => {
|
|
912
|
+
// Ctrl+S / Cmd+S to save
|
|
913
|
+
if ((e.ctrl || e.meta) && e.name === "s") {
|
|
914
|
+
e.preventDefault()
|
|
915
|
+
saveFile()
|
|
916
|
+
}
|
|
917
|
+
// Escape to blur
|
|
918
|
+
if (e.name === "escape") {
|
|
919
|
+
editorRef?.blur()
|
|
920
|
+
}
|
|
921
|
+
}}
|
|
922
|
+
/>
|
|
923
|
+
</line_number>
|
|
924
|
+
<Show when={fileData()?.diff}>
|
|
925
|
+
<VcsDiffViewer
|
|
926
|
+
diff={() => fileData()!.diff!}
|
|
927
|
+
fileType={fileType(activePath())}
|
|
928
|
+
wrapMode={props.wrapMode ?? "none"}
|
|
929
|
+
/>
|
|
930
|
+
</Show>
|
|
931
|
+
</box>
|
|
932
|
+
</Match>
|
|
933
|
+
</Switch>
|
|
934
|
+
</scrollbox>
|
|
935
|
+
)
|
|
936
|
+
|
|
937
|
+
const historyPanel = () => (
|
|
938
|
+
<GitHistory
|
|
939
|
+
branch={branch}
|
|
940
|
+
historyEntries={historyEntries}
|
|
941
|
+
historyHeight={historyHeight}
|
|
942
|
+
onBranchSwitcher={openBranchSwitcher}
|
|
943
|
+
viewportOptions={viewportOptions()}
|
|
944
|
+
verticalScrollbarOptions={verticalScrollbarOptions()}
|
|
945
|
+
/>
|
|
946
|
+
)
|
|
947
|
+
|
|
948
|
+
const edgeBorder = createMemo<("left" | "right")[]>(() => (props.side === "left" ? ["left"] : ["right"]))
|
|
949
|
+
|
|
950
|
+
const handleNavigatorClick = () => {
|
|
951
|
+
if (props.promptRef?.focused) return
|
|
952
|
+
props.promptRef?.focus()
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
return (
|
|
956
|
+
<box
|
|
957
|
+
width={props.open ? props.width : 0}
|
|
958
|
+
height="100%"
|
|
959
|
+
flexDirection="column"
|
|
960
|
+
backgroundColor={theme.theme.background}
|
|
961
|
+
border={props.open ? edgeBorder() : undefined}
|
|
962
|
+
customBorderChars={props.open ? NavigatorBorderChars : undefined}
|
|
963
|
+
borderColor={theme.theme.border}
|
|
964
|
+
visible={props.open}
|
|
965
|
+
onMouseUp={handleNavigatorClick}
|
|
966
|
+
>
|
|
967
|
+
<box
|
|
968
|
+
paddingLeft={2}
|
|
969
|
+
paddingRight={2}
|
|
970
|
+
paddingTop={1}
|
|
971
|
+
paddingBottom={1}
|
|
972
|
+
flexDirection="row"
|
|
973
|
+
justifyContent="space-between"
|
|
974
|
+
border={["bottom"]}
|
|
975
|
+
borderColor={theme.theme.border}
|
|
976
|
+
customBorderChars={NavigatorBorderChars}
|
|
977
|
+
>
|
|
978
|
+
<box flexDirection="column">
|
|
979
|
+
<text fg={theme.theme.text}>
|
|
980
|
+
<b>Navigator</b>
|
|
981
|
+
</text>
|
|
982
|
+
<text fg={theme.theme.textMuted}>{displayRoot()}</text>
|
|
983
|
+
</box>
|
|
984
|
+
<box onMouseUp={props.onClose} paddingLeft={1} paddingRight={1} backgroundColor={theme.theme.backgroundElement}>
|
|
985
|
+
<text fg={theme.theme.text}>Close</text>
|
|
986
|
+
</box>
|
|
987
|
+
</box>
|
|
988
|
+
<box flexGrow={1} flexDirection="row">
|
|
989
|
+
<box
|
|
990
|
+
width={listWidth()}
|
|
991
|
+
border={["right"]}
|
|
992
|
+
customBorderChars={NavigatorBorderChars}
|
|
993
|
+
borderColor={theme.theme.border}
|
|
994
|
+
flexDirection="column"
|
|
995
|
+
backgroundColor={theme.theme.background}
|
|
996
|
+
>
|
|
997
|
+
<box
|
|
998
|
+
backgroundColor={theme.theme.background}
|
|
999
|
+
flexDirection="row"
|
|
1000
|
+
justifyContent="center"
|
|
1001
|
+
paddingTop={0}
|
|
1002
|
+
paddingBottom={1}
|
|
1003
|
+
flexShrink={0}
|
|
1004
|
+
>
|
|
1005
|
+
<Tab label="Explorer" active={tab() === "explorer"} onSelect={() => setTab(() => "explorer")} />
|
|
1006
|
+
<Tab label="Git" active={tab() === "git"} onSelect={() => setTab(() => "git")} />
|
|
1007
|
+
</box>
|
|
1008
|
+
|
|
1009
|
+
<Switch>
|
|
1010
|
+
<Match when={tab() === "git"}>
|
|
1011
|
+
<GitCommit commitMessage={commitMessage} setCommitMessage={setCommitMessage} onCommit={handleCommit} />
|
|
1012
|
+
<Show
|
|
1013
|
+
when={hasGitEntries()}
|
|
1014
|
+
fallback={
|
|
1015
|
+
<box paddingLeft={2} paddingRight={2} paddingTop={1} flexGrow={1}>
|
|
1016
|
+
<text fg={theme.theme.textMuted}>No git changes</text>
|
|
1017
|
+
</box>
|
|
1018
|
+
}
|
|
1019
|
+
>
|
|
1020
|
+
<scrollbox
|
|
1021
|
+
flexGrow={1}
|
|
1022
|
+
height="100%"
|
|
1023
|
+
ref={(el) => setGitScroll(el)}
|
|
1024
|
+
viewportOptions={viewportOptions()}
|
|
1025
|
+
verticalScrollbarOptions={verticalScrollbarOptions()}
|
|
1026
|
+
scrollAcceleration={new CustomSpeedScroll(3)}
|
|
1027
|
+
>
|
|
1028
|
+
<For each={gitEntries()}>
|
|
1029
|
+
{(entry, index) => (
|
|
1030
|
+
<GitRow
|
|
1031
|
+
entry={entry}
|
|
1032
|
+
width={listWidth()}
|
|
1033
|
+
active={index() === selectedGit()}
|
|
1034
|
+
onSelect={() => {
|
|
1035
|
+
setSelectedGit(() => index())
|
|
1036
|
+
openFilePath(entry.path)
|
|
1037
|
+
}}
|
|
1038
|
+
/>
|
|
1039
|
+
)}
|
|
1040
|
+
</For>
|
|
1041
|
+
</scrollbox>
|
|
1042
|
+
</Show>
|
|
1043
|
+
{historyPanel()}
|
|
1044
|
+
</Match>
|
|
1045
|
+
<Match when={true}>
|
|
1046
|
+
<Show
|
|
1047
|
+
when={hasExplorerEntries()}
|
|
1048
|
+
fallback={
|
|
1049
|
+
<box paddingLeft={2} paddingRight={2} paddingTop={1}>
|
|
1050
|
+
<text fg={theme.theme.textMuted}>{loading[""] ? "Loading files..." : "No files found"}</text>
|
|
1051
|
+
</box>
|
|
1052
|
+
}
|
|
1053
|
+
>
|
|
1054
|
+
<scrollbox
|
|
1055
|
+
flexGrow={1}
|
|
1056
|
+
height="100%"
|
|
1057
|
+
ref={(el) => setExplorerScroll(el)}
|
|
1058
|
+
viewportOptions={viewportOptions()}
|
|
1059
|
+
verticalScrollbarOptions={verticalScrollbarOptions()}
|
|
1060
|
+
scrollAcceleration={new CustomSpeedScroll(3)}
|
|
1061
|
+
>
|
|
1062
|
+
<For each={explorerEntries()}>
|
|
1063
|
+
{(entry, index) => (
|
|
1064
|
+
<ExplorerRow
|
|
1065
|
+
entry={entry}
|
|
1066
|
+
width={listWidth()}
|
|
1067
|
+
active={index() === selectedExplorer()}
|
|
1068
|
+
status={statusMap().get(entry.node.path)}
|
|
1069
|
+
expanded={expanded[entry.node.path] ?? false}
|
|
1070
|
+
onSelect={() => {
|
|
1071
|
+
setSelectedExplorer(() => index())
|
|
1072
|
+
if (entry.node.type === "directory") {
|
|
1073
|
+
toggleDirectory(entry.node)
|
|
1074
|
+
return
|
|
1075
|
+
}
|
|
1076
|
+
openFile(entry.node)
|
|
1077
|
+
}}
|
|
1078
|
+
/>
|
|
1079
|
+
)}
|
|
1080
|
+
</For>
|
|
1081
|
+
</scrollbox>
|
|
1082
|
+
</Show>
|
|
1083
|
+
</Match>
|
|
1084
|
+
</Switch>
|
|
1085
|
+
</box>
|
|
1086
|
+
<box
|
|
1087
|
+
width={viewerWidth()}
|
|
1088
|
+
flexDirection="column"
|
|
1089
|
+
paddingLeft={2}
|
|
1090
|
+
paddingRight={2}
|
|
1091
|
+
paddingTop={1}
|
|
1092
|
+
paddingBottom={1}
|
|
1093
|
+
>
|
|
1094
|
+
<box justifyContent="center" paddingTop={1} paddingBottom={1} flexShrink={0}>
|
|
1095
|
+
<text fg={theme.theme.text}>
|
|
1096
|
+
<b>{viewTitle()}</b>
|
|
1097
|
+
</text>
|
|
1098
|
+
</box>
|
|
1099
|
+
{fileViewer()}
|
|
1100
|
+
</box>
|
|
1101
|
+
</box>
|
|
1102
|
+
<box
|
|
1103
|
+
paddingLeft={2}
|
|
1104
|
+
paddingRight={2}
|
|
1105
|
+
paddingTop={1}
|
|
1106
|
+
paddingBottom={1}
|
|
1107
|
+
flexDirection="row"
|
|
1108
|
+
justifyContent="space-between"
|
|
1109
|
+
>
|
|
1110
|
+
<text fg={theme.theme.textMuted}>
|
|
1111
|
+
{(() => {
|
|
1112
|
+
const status = saveStatus()
|
|
1113
|
+
if (status === "saving") return "Saving..."
|
|
1114
|
+
if (status === "saved") return "Saved"
|
|
1115
|
+
if (status === "error") return "Save failed"
|
|
1116
|
+
if (isDirty()) return "Unsaved changes"
|
|
1117
|
+
return "Click to edit"
|
|
1118
|
+
})()}
|
|
1119
|
+
</text>
|
|
1120
|
+
<text fg={theme.theme.textMuted}>{resizeLabel() ? `${resizeLabel()} - ` : ""}Esc: chat</text>
|
|
1121
|
+
</box>
|
|
1122
|
+
</box>
|
|
1123
|
+
)
|
|
1124
|
+
}
|