nikcli 0.0.6
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/.turbo/turbo-typecheck.log +1 -0
- package/AGENTS.md +27 -0
- package/Dockerfile +18 -0
- package/README.md +15 -0
- package/bin/nikcli +84 -0
- package/config.json +13 -0
- package/docs/tailscale-mobile/01-tailscale-setup.md +94 -0
- package/docs/tailscale-mobile/02-host-setup.md +115 -0
- package/docs/tailscale-mobile/03-phone-and-serve.md +134 -0
- package/docs/tailscale-mobile/README.md +59 -0
- package/examples/README.md +54 -0
- package/package.json +147 -0
- package/parsers-config.ts +253 -0
- package/script/build.ts +179 -0
- package/script/postinstall.mjs +125 -0
- package/script/publish-registries.ts +187 -0
- package/script/publish.ts +100 -0
- package/script/schema.ts +47 -0
- package/script/seed-e2e.ts +50 -0
- package/sequential-prancing-forest.md +373 -0
- package/src/acp/README.md +164 -0
- package/src/acp/agent.ts +1303 -0
- package/src/acp/session.ts +105 -0
- package/src/acp/types.ts +22 -0
- package/src/agent/agent.ts +528 -0
- package/src/agent/generate.txt +32 -0
- package/src/agent/prompt/compaction.txt +14 -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/bun/index.ts +119 -0
- package/src/bun/registry.ts +54 -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/chatbot/handlers.ts +150 -0
- package/src/chatbot/index.ts +132 -0
- package/src/cli/bootstrap.ts +17 -0
- package/src/cli/cmd/acp.ts +69 -0
- package/src/cli/cmd/ads.ts +377 -0
- package/src/cli/cmd/agent.ts +259 -0
- package/src/cli/cmd/auth.ts +400 -0
- package/src/cli/cmd/chatbot.ts +420 -0
- package/src/cli/cmd/cmd.ts +7 -0
- package/src/cli/cmd/companion.ts +81 -0
- package/src/cli/cmd/connectors.ts +593 -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 +412 -0
- package/src/cli/cmd/image-model.ts +128 -0
- package/src/cli/cmd/import.ts +201 -0
- package/src/cli/cmd/lovable.ts +128 -0
- package/src/cli/cmd/mcp.ts +738 -0
- package/src/cli/cmd/mobile.ts +223 -0
- package/src/cli/cmd/models.ts +77 -0
- package/src/cli/cmd/plug.ts +231 -0
- package/src/cli/cmd/pr.ts +104 -0
- package/src/cli/cmd/rag-model.ts +167 -0
- package/src/cli/cmd/remote.ts +416 -0
- package/src/cli/cmd/run.ts +589 -0
- package/src/cli/cmd/serve.ts +51 -0
- package/src/cli/cmd/session.ts +133 -0
- package/src/cli/cmd/speak-model.ts +204 -0
- package/src/cli/cmd/stats.ts +402 -0
- package/src/cli/cmd/tui/app.tsx +841 -0
- package/src/cli/cmd/tui/attach.ts +31 -0
- package/src/cli/cmd/tui/component/border.tsx +75 -0
- package/src/cli/cmd/tui/component/dialog-agent.tsx +31 -0
- package/src/cli/cmd/tui/component/dialog-command.tsx +172 -0
- package/src/cli/cmd/tui/component/dialog-config.tsx +291 -0
- package/src/cli/cmd/tui/component/dialog-connectors.tsx +440 -0
- package/src/cli/cmd/tui/component/dialog-image-model.tsx +97 -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 +260 -0
- package/src/cli/cmd/tui/component/dialog-rag-model.tsx +217 -0
- package/src/cli/cmd/tui/component/dialog-remote.tsx +489 -0
- package/src/cli/cmd/tui/component/dialog-session-list.tsx +170 -0
- package/src/cli/cmd/tui/component/dialog-session-rename.tsx +31 -0
- package/src/cli/cmd/tui/component/dialog-settings/index.tsx +59 -0
- package/src/cli/cmd/tui/component/dialog-settings/prompt.tsx +40 -0
- package/src/cli/cmd/tui/component/dialog-settings/sidebar.tsx +39 -0
- package/src/cli/cmd/tui/component/dialog-settings/spinner.tsx +62 -0
- package/src/cli/cmd/tui/component/dialog-settings/ui.tsx +58 -0
- package/src/cli/cmd/tui/component/dialog-skills.tsx +117 -0
- package/src/cli/cmd/tui/component/dialog-speak-model.tsx +304 -0
- package/src/cli/cmd/tui/component/dialog-stash.tsx +87 -0
- package/src/cli/cmd/tui/component/dialog-status.tsx +165 -0
- package/src/cli/cmd/tui/component/dialog-tag.tsx +44 -0
- package/src/cli/cmd/tui/component/dialog-theme-create.tsx +717 -0
- package/src/cli/cmd/tui/component/dialog-theme-list.tsx +52 -0
- package/src/cli/cmd/tui/component/dialog-workspace-list.tsx +350 -0
- package/src/cli/cmd/tui/component/error-component.tsx +91 -0
- package/src/cli/cmd/tui/component/logo.tsx +103 -0
- package/src/cli/cmd/tui/component/plugin-route-missing.tsx +14 -0
- package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +669 -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 +2165 -0
- package/src/cli/cmd/tui/component/prompt/stash.tsx +63 -0
- package/src/cli/cmd/tui/component/spinner.tsx +24 -0
- package/src/cli/cmd/tui/component/startup-loading.tsx +63 -0
- package/src/cli/cmd/tui/component/table/markdown-table.tsx +267 -0
- package/src/cli/cmd/tui/component/table-db/db/connections.ts +75 -0
- package/src/cli/cmd/tui/component/table-db/db/db-connection.ts +223 -0
- package/src/cli/cmd/tui/component/table-db/db/db-preview.ts +202 -0
- package/src/cli/cmd/tui/component/table-db/db/factory.ts +77 -0
- package/src/cli/cmd/tui/component/table-db/db/index.ts +9 -0
- package/src/cli/cmd/tui/component/table-db/db/mysql-connection.ts +330 -0
- package/src/cli/cmd/tui/component/table-db/db/postgres-connection.ts +338 -0
- package/src/cli/cmd/tui/component/table-db/db/sqlite-connection.ts +302 -0
- package/src/cli/cmd/tui/component/table-db/db/types.ts +108 -0
- package/src/cli/cmd/tui/component/table-db/table/dbedit-hooks.ts +74 -0
- package/src/cli/cmd/tui/component/table-db/table/index.ts +15 -0
- package/src/cli/cmd/tui/component/table-db/table/table-events.ts +54 -0
- package/src/cli/cmd/tui/component/table-db/table/table-formatters.ts +191 -0
- package/src/cli/cmd/tui/component/table-db/table/table-hooks.ts +105 -0
- package/src/cli/cmd/tui/component/table-db/table/table-keyboard-handler.ts +255 -0
- package/src/cli/cmd/tui/component/table-db/table/table-layout-engine.ts +208 -0
- package/src/cli/cmd/tui/component/table-db/table/table-renderable.ts +486 -0
- package/src/cli/cmd/tui/component/table-db/table/table-selection-manager.ts +136 -0
- package/src/cli/cmd/tui/component/table-db/table/table-state.ts +198 -0
- package/src/cli/cmd/tui/component/table-db/table/types.ts +69 -0
- package/src/cli/cmd/tui/component/table-db/ui/db-visualizer.tsx +71 -0
- package/src/cli/cmd/tui/component/table-db/ui/index.ts +2 -0
- package/src/cli/cmd/tui/component/table-db/ui/table-renderer.ts +607 -0
- package/src/cli/cmd/tui/component/textarea-keybindings.ts +73 -0
- package/src/cli/cmd/tui/component/tips.tsx +195 -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/exit.tsx +24 -0
- package/src/cli/cmd/tui/context/helper.tsx +25 -0
- package/src/cli/cmd/tui/context/keybind.tsx +102 -0
- package/src/cli/cmd/tui/context/kv.tsx +52 -0
- package/src/cli/cmd/tui/context/local.tsx +458 -0
- package/src/cli/cmd/tui/context/plugin-keybinds.ts +41 -0
- package/src/cli/cmd/tui/context/prompt.tsx +18 -0
- package/src/cli/cmd/tui/context/route.tsx +54 -0
- package/src/cli/cmd/tui/context/sdk.tsx +128 -0
- package/src/cli/cmd/tui/context/server.tsx +8 -0
- package/src/cli/cmd/tui/context/sync.tsx +510 -0
- package/src/cli/cmd/tui/context/theme/abyss.json +233 -0
- package/src/cli/cmd/tui/context/theme/apple.json +235 -0
- package/src/cli/cmd/tui/context/theme/arctic.json +232 -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/ayuai.json +229 -0
- package/src/cli/cmd/tui/context/theme/blood.json +229 -0
- package/src/cli/cmd/tui/context/theme/carbonfox.json +248 -0
- package/src/cli/cmd/tui/context/theme/catmoe.json +235 -0
- package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +233 -0
- package/src/cli/cmd/tui/context/theme/catppuccin-latte.json +233 -0
- package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +233 -0
- package/src/cli/cmd/tui/context/theme/catppuccin.json +259 -0
- package/src/cli/cmd/tui/context/theme/charcoal.json +230 -0
- package/src/cli/cmd/tui/context/theme/chromatic.json +235 -0
- package/src/cli/cmd/tui/context/theme/cobalt2.json +228 -0
- package/src/cli/cmd/tui/context/theme/cosmic.json +234 -0
- package/src/cli/cmd/tui/context/theme/cursor.json +249 -0
- package/src/cli/cmd/tui/context/theme/cyber.json +235 -0
- package/src/cli/cmd/tui/context/theme/dawnfox.json +229 -0
- package/src/cli/cmd/tui/context/theme/dimension.json +235 -0
- package/src/cli/cmd/tui/context/theme/dracula-official.json +222 -0
- package/src/cli/cmd/tui/context/theme/dracula.json +219 -0
- package/src/cli/cmd/tui/context/theme/dream.json +235 -0
- package/src/cli/cmd/tui/context/theme/duo.json +235 -0
- package/src/cli/cmd/tui/context/theme/dusk.json +235 -0
- package/src/cli/cmd/tui/context/theme/ebony.json +232 -0
- package/src/cli/cmd/tui/context/theme/equilibrium.json +232 -0
- package/src/cli/cmd/tui/context/theme/ethereal.json +235 -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/fusion.json +235 -0
- package/src/cli/cmd/tui/context/theme/ghost.json +235 -0
- package/src/cli/cmd/tui/context/theme/github-dark.json +229 -0
- package/src/cli/cmd/tui/context/theme/github-dimmed.json +231 -0
- package/src/cli/cmd/tui/context/theme/github-light.json +229 -0
- package/src/cli/cmd/tui/context/theme/github.json +233 -0
- package/src/cli/cmd/tui/context/theme/glass.json +235 -0
- package/src/cli/cmd/tui/context/theme/gold.json +235 -0
- package/src/cli/cmd/tui/context/theme/gone.json +234 -0
- package/src/cli/cmd/tui/context/theme/greyscale.json +229 -0
- package/src/cli/cmd/tui/context/theme/gruvbox.json +242 -0
- package/src/cli/cmd/tui/context/theme/hacker.json +229 -0
- package/src/cli/cmd/tui/context/theme/holo.json +235 -0
- package/src/cli/cmd/tui/context/theme/ink.json +235 -0
- package/src/cli/cmd/tui/context/theme/jet.json +233 -0
- package/src/cli/cmd/tui/context/theme/kanagawa.json +227 -0
- package/src/cli/cmd/tui/context/theme/lavender.json +236 -0
- package/src/cli/cmd/tui/context/theme/lightph.json +235 -0
- package/src/cli/cmd/tui/context/theme/lucent-orng.json +237 -0
- package/src/cli/cmd/tui/context/theme/material-ocean.json +230 -0
- package/src/cli/cmd/tui/context/theme/material.json +235 -0
- package/src/cli/cmd/tui/context/theme/matrix.json +227 -0
- package/src/cli/cmd/tui/context/theme/mercury.json +245 -0
- package/src/cli/cmd/tui/context/theme/midnight.json +235 -0
- package/src/cli/cmd/tui/context/theme/modern.json +235 -0
- package/src/cli/cmd/tui/context/theme/monokai.json +221 -0
- package/src/cli/cmd/tui/context/theme/muted.json +229 -0
- package/src/cli/cmd/tui/context/theme/neon.json +229 -0
- package/src/cli/cmd/tui/context/theme/neonfusion.json +235 -0
- package/src/cli/cmd/tui/context/theme/neutral.json +235 -0
- package/src/cli/cmd/tui/context/theme/nightowl.json +221 -0
- package/src/cli/cmd/tui/context/theme/nikcli.json +245 -0
- package/src/cli/cmd/tui/context/theme/nord.json +223 -0
- package/src/cli/cmd/tui/context/theme/nordic.json +235 -0
- package/src/cli/cmd/tui/context/theme/nova.json +235 -0
- package/src/cli/cmd/tui/context/theme/obsidian.json +234 -0
- package/src/cli/cmd/tui/context/theme/one-dark.json +231 -0
- package/src/cli/cmd/tui/context/theme/one-pro.json +229 -0
- package/src/cli/cmd/tui/context/theme/onyx.json +233 -0
- package/src/cli/cmd/tui/context/theme/orng.json +249 -0
- package/src/cli/cmd/tui/context/theme/osaka-jade.json +240 -0
- package/src/cli/cmd/tui/context/theme/oxocarbon.json +229 -0
- package/src/cli/cmd/tui/context/theme/palenight.json +222 -0
- package/src/cli/cmd/tui/context/theme/poimandres.json +230 -0
- package/src/cli/cmd/tui/context/theme/prism.json +235 -0
- package/src/cli/cmd/tui/context/theme/radiant.json +235 -0
- package/src/cli/cmd/tui/context/theme/rosepine.json +234 -0
- package/src/cli/cmd/tui/context/theme/shadow.json +235 -0
- package/src/cli/cmd/tui/context/theme/silicon.json +235 -0
- package/src/cli/cmd/tui/context/theme/slate.json +233 -0
- package/src/cli/cmd/tui/context/theme/soft.json +235 -0
- package/src/cli/cmd/tui/context/theme/solarized.json +223 -0
- package/src/cli/cmd/tui/context/theme/spectrum.json +235 -0
- package/src/cli/cmd/tui/context/theme/starlight.json +233 -0
- package/src/cli/cmd/tui/context/theme/sunrise.json +235 -0
- package/src/cli/cmd/tui/context/theme/synthwave84.json +226 -0
- package/src/cli/cmd/tui/context/theme/tech.json +235 -0
- package/src/cli/cmd/tui/context/theme/tokyonight-storm.json +245 -0
- package/src/cli/cmd/tui/context/theme/tokyonight.json +243 -0
- package/src/cli/cmd/tui/context/theme/vapor.json +235 -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/vivid.json +232 -0
- package/src/cli/cmd/tui/context/theme/void.json +235 -0
- package/src/cli/cmd/tui/context/theme/vscode.json +235 -0
- package/src/cli/cmd/tui/context/theme/zenburn.json +223 -0
- package/src/cli/cmd/tui/context/theme/zinc.json +236 -0
- package/src/cli/cmd/tui/context/theme.tsx +1303 -0
- package/src/cli/cmd/tui/event.ts +48 -0
- package/src/cli/cmd/tui/feature-plugins/home/tips-view.tsx +152 -0
- package/src/cli/cmd/tui/feature-plugins/home/tips.tsx +50 -0
- package/src/cli/cmd/tui/feature-plugins/sidebar/context.tsx +63 -0
- package/src/cli/cmd/tui/feature-plugins/sidebar/files.tsx +62 -0
- package/src/cli/cmd/tui/feature-plugins/sidebar/footer.tsx +93 -0
- package/src/cli/cmd/tui/feature-plugins/sidebar/lsp.tsx +66 -0
- package/src/cli/cmd/tui/feature-plugins/sidebar/mcp.tsx +96 -0
- package/src/cli/cmd/tui/feature-plugins/sidebar/todo.tsx +48 -0
- package/src/cli/cmd/tui/feature-plugins/system/plugins.tsx +288 -0
- package/src/cli/cmd/tui/plugin/api.tsx +407 -0
- package/src/cli/cmd/tui/plugin/index.ts +3 -0
- package/src/cli/cmd/tui/plugin/internal.ts +25 -0
- package/src/cli/cmd/tui/plugin/runtime.ts +1048 -0
- package/src/cli/cmd/tui/plugin/slots.tsx +61 -0
- package/src/cli/cmd/tui/routes/home.tsx +153 -0
- package/src/cli/cmd/tui/routes/session/dbedit.tsx +474 -0
- package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +65 -0
- package/src/cli/cmd/tui/routes/session/dialog-message.tsx +110 -0
- package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +105 -0
- package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +47 -0
- package/src/cli/cmd/tui/routes/session/footer.tsx +75 -0
- package/src/cli/cmd/tui/routes/session/header.tsx +177 -0
- package/src/cli/cmd/tui/routes/session/index.tsx +2280 -0
- package/src/cli/cmd/tui/routes/session/permission.tsx +540 -0
- package/src/cli/cmd/tui/routes/session/question.tsx +435 -0
- package/src/cli/cmd/tui/routes/session/sidebar.tsx +313 -0
- package/src/cli/cmd/tui/thread.ts +174 -0
- package/src/cli/cmd/tui/ui/dialog-alert.tsx +57 -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 +102 -0
- package/src/cli/cmd/tui/ui/dialog-select.tsx +389 -0
- package/src/cli/cmd/tui/ui/dialog.tsx +180 -0
- package/src/cli/cmd/tui/ui/link.tsx +34 -0
- package/src/cli/cmd/tui/ui/spinner.ts +368 -0
- package/src/cli/cmd/tui/ui/toast.tsx +138 -0
- package/src/cli/cmd/tui/util/clipboard.ts +154 -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/win32.ts +110 -0
- package/src/cli/cmd/tui/worker.ts +156 -0
- package/src/cli/cmd/uninstall.ts +357 -0
- package/src/cli/cmd/upgrade.ts +72 -0
- package/src/cli/cmd/web.ts +87 -0
- package/src/cli/cmd/workspace-serve.ts +16 -0
- package/src/cli/error.ts +57 -0
- package/src/cli/network.ts +55 -0
- package/src/cli/remote/index.ts +36 -0
- package/src/cli/remote/notifications.ts +104 -0
- package/src/cli/remote/qr-renderer.ts +86 -0
- package/src/cli/remote/remote-service.ts +757 -0
- package/src/cli/remote/session-manager.ts +284 -0
- package/src/cli/remote/subagent-hooks.ts +151 -0
- package/src/cli/remote/types.ts +121 -0
- package/src/cli/ui.ts +96 -0
- package/src/cli/upgrade.ts +25 -0
- package/src/command/index.ts +174 -0
- package/src/command/template/initialize.txt +10 -0
- package/src/command/template/review.txt +99 -0
- package/src/config/config.ts +1760 -0
- package/src/config/markdown.ts +88 -0
- package/src/config/migrate-tui-config.ts +155 -0
- package/src/config/paths.ts +174 -0
- package/src/config/tui-schema.ts +36 -0
- package/src/config/tui.ts +209 -0
- package/src/connectors/api/base.ts +75 -0
- package/src/connectors/api/figma.ts +103 -0
- package/src/connectors/api/github.ts +247 -0
- package/src/connectors/api/lovable.ts +126 -0
- package/src/connectors/api/slack.ts +137 -0
- package/src/connectors/auth.ts +68 -0
- package/src/connectors/cache.ts +119 -0
- package/src/connectors/credentials.ts +81 -0
- package/src/connectors/index.ts +202 -0
- package/src/connectors/registry.ts +358 -0
- package/src/docs/context.ts +120 -0
- package/src/docs/library.ts +189 -0
- package/src/env/index.ts +26 -0
- package/src/file/ignore.ts +83 -0
- package/src/file/index.ts +411 -0
- package/src/file/ripgrep.ts +402 -0
- package/src/file/time.ts +65 -0
- package/src/file/watcher.ts +127 -0
- package/src/flag/flag.ts +128 -0
- package/src/format/formatter.ts +356 -0
- package/src/format/index.ts +137 -0
- package/src/global/index.ts +57 -0
- package/src/id/id.ts +83 -0
- package/src/ide/index.ts +76 -0
- package/src/index.ts +184 -0
- package/src/installation/index.ts +246 -0
- package/src/lsp/client.ts +250 -0
- package/src/lsp/index.ts +483 -0
- package/src/lsp/language.ts +119 -0
- package/src/lsp/server.ts +2046 -0
- package/src/mcp/auth.ts +121 -0
- package/src/mcp/index.ts +860 -0
- package/src/mcp/oauth-callback.ts +198 -0
- package/src/mcp/oauth-provider.ts +148 -0
- package/src/mobile/auth.ts +97 -0
- package/src/mobile/github-repo.ts +185 -0
- package/src/patch/index.ts +631 -0
- package/src/permission/arity.ts +150 -0
- package/src/permission/dbedit.ts +236 -0
- package/src/permission/index.ts +210 -0
- package/src/permission/next.ts +287 -0
- package/src/plugin/codex.ts +493 -0
- package/src/plugin/copilot.ts +261 -0
- package/src/plugin/index.ts +714 -0
- package/src/plugin/install.ts +379 -0
- package/src/plugin/meta.ts +165 -0
- package/src/plugin/shared.ts +188 -0
- package/src/project/bootstrap.ts +35 -0
- package/src/project/instance.ts +84 -0
- package/src/project/project.ts +373 -0
- package/src/project/state.ts +66 -0
- package/src/project/vcs.ts +76 -0
- package/src/prompt/stash-store.ts +93 -0
- package/src/provider/auth.ts +147 -0
- package/src/provider/models-macro.ts +22 -0
- package/src/provider/models.ts +216 -0
- package/src/provider/provider.ts +1483 -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 +828 -0
- package/src/pty/index.ts +241 -0
- package/src/question/index.ts +171 -0
- package/src/rag/chunk.ts +43 -0
- package/src/rag/embed.ts +179 -0
- package/src/rag/index.ts +376 -0
- package/src/rag/storage.ts +76 -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/chatbot.ts +205 -0
- package/src/server/routes/companion.ts +729 -0
- package/src/server/routes/config.ts +92 -0
- package/src/server/routes/connectors.ts +121 -0
- package/src/server/routes/dbedit.ts +76 -0
- package/src/server/routes/experimental.ts +210 -0
- package/src/server/routes/file.ts +197 -0
- package/src/server/routes/global.ts +135 -0
- package/src/server/routes/mcp.ts +225 -0
- package/src/server/routes/mobile.ts +2044 -0
- package/src/server/routes/permission.ts +68 -0
- package/src/server/routes/project.ts +82 -0
- package/src/server/routes/provider.ts +235 -0
- package/src/server/routes/pty.ts +169 -0
- package/src/server/routes/question.ts +98 -0
- package/src/server/routes/session.ts +968 -0
- package/src/server/routes/tui.ts +379 -0
- package/src/server/routes/workspace.ts +104 -0
- package/src/server/server.ts +761 -0
- package/src/server/ssh.ts +207 -0
- package/src/session/auth.ts +402 -0
- package/src/session/compaction.ts +253 -0
- package/src/session/generate.ts +38 -0
- package/src/session/index.ts +598 -0
- package/src/session/llm.ts +273 -0
- package/src/session/message-v2.ts +836 -0
- package/src/session/message.ts +189 -0
- package/src/session/processor.ts +408 -0
- package/src/session/prompt/anthropic-20250930.txt +165 -0
- package/src/session/prompt/anthropic.txt +105 -0
- package/src/session/prompt/anthropic_spoof.txt +1 -0
- package/src/session/prompt/beast.txt +147 -0
- package/src/session/prompt/build-switch.txt +5 -0
- package/src/session/prompt/codex_header.txt +79 -0
- package/src/session/prompt/copilot-gpt-5.txt +143 -0
- package/src/session/prompt/gemini.txt +155 -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 +25 -0
- package/src/session/prompt/qwen.txt +108 -0
- package/src/session/prompt.ts +1942 -0
- package/src/session/retry.ts +90 -0
- package/src/session/revert.ts +120 -0
- package/src/session/stats.ts +404 -0
- package/src/session/status.ts +84 -0
- package/src/session/summary.ts +184 -0
- package/src/session/system.ts +195 -0
- package/src/session/toast.tsx +105 -0
- package/src/session/todo.ts +258 -0
- package/src/session/uninstall.ts +357 -0
- package/src/share/share-next.ts +421 -0
- package/src/share/share.ts +92 -0
- package/src/shell/shell.ts +65 -0
- package/src/skill/index.ts +1 -0
- package/src/skill/skill.ts +232 -0
- package/src/snapshot/index.ts +297 -0
- package/src/storage/storage.ts +227 -0
- package/src/tool/apply_patch.ts +288 -0
- package/src/tool/apply_patch.txt +33 -0
- package/src/tool/bash.ts +252 -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/context_collect.ts +152 -0
- package/src/tool/context_collect.txt +9 -0
- package/src/tool/context_diagnostics.ts +81 -0
- package/src/tool/context_diagnostics.txt +5 -0
- package/src/tool/context_related.ts +117 -0
- package/src/tool/context_related.txt +5 -0
- package/src/tool/context_search.ts +108 -0
- package/src/tool/context_search.txt +8 -0
- package/src/tool/db-diff.ts +434 -0
- package/src/tool/db-table.txt +15 -0
- package/src/tool/docs_add.ts +50 -0
- package/src/tool/docs_add.txt +5 -0
- package/src/tool/docs_context.ts +56 -0
- package/src/tool/docs_context.txt +4 -0
- package/src/tool/docs_gap_report.ts +79 -0
- package/src/tool/docs_gap_report.txt +7 -0
- package/src/tool/docs_load.ts +41 -0
- package/src/tool/docs_load.txt +4 -0
- package/src/tool/docs_request.ts +129 -0
- package/src/tool/docs_request.txt +7 -0
- package/src/tool/docs_search.ts +51 -0
- package/src/tool/docs_search.txt +6 -0
- package/src/tool/docs_unload.ts +38 -0
- package/src/tool/docs_unload.txt +5 -0
- package/src/tool/edit.ts +614 -0
- package/src/tool/edit.txt +10 -0
- package/src/tool/external-directory.ts +32 -0
- package/src/tool/generate_image.ts +174 -0
- package/src/tool/generate_image.txt +12 -0
- package/src/tool/glob.ts +79 -0
- package/src/tool/glob.txt +6 -0
- package/src/tool/grep.ts +153 -0
- package/src/tool/grep.txt +8 -0
- package/src/tool/invalid.ts +17 -0
- package/src/tool/ls.ts +116 -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/memory_search.ts +141 -0
- package/src/tool/memory_search.txt +8 -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/rag_index.ts +77 -0
- package/src/tool/rag_index.txt +10 -0
- package/src/tool/rag_reset.ts +26 -0
- package/src/tool/rag_reset.txt +4 -0
- package/src/tool/rag_search.ts +62 -0
- package/src/tool/rag_search.txt +6 -0
- package/src/tool/rag_status.ts +45 -0
- package/src/tool/rag_status.txt +4 -0
- package/src/tool/read.ts +203 -0
- package/src/tool/read.txt +12 -0
- package/src/tool/registry.ts +214 -0
- package/src/tool/skill.ts +169 -0
- package/src/tool/skill.txt +3 -0
- package/src/tool/smart_docs.ts +74 -0
- package/src/tool/smart_docs.txt +7 -0
- package/src/tool/speak/elevenlabs.ts +201 -0
- package/src/tool/speak/openrouter.ts +240 -0
- package/src/tool/speak/provider.ts +83 -0
- package/src/tool/speak.ts +440 -0
- package/src/tool/task.ts +194 -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 +87 -0
- package/src/tool/tree.ts +218 -0
- package/src/tool/tree.txt +8 -0
- package/src/tool/truncation.ts +106 -0
- package/src/tool/use-connector.ts +47 -0
- package/src/tool/voice.ts +188 -0
- package/src/tool/webfetch.ts +205 -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/error.ts +77 -0
- package/src/util/eventloop.ts +20 -0
- package/src/util/filesystem.ts +125 -0
- package/src/util/flock.ts +329 -0
- package/src/util/fn.ts +11 -0
- package/src/util/format.ts +20 -0
- package/src/util/hash.ts +7 -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/network.ts +9 -0
- package/src/util/process.ts +15 -0
- package/src/util/queue.ts +32 -0
- package/src/util/record.ts +3 -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/workspace/adaptors/index.ts +271 -0
- package/src/workspace/adaptors/types.ts +14 -0
- package/src/workspace/adaptors/worktree.ts +31 -0
- package/src/workspace/config.ts +19 -0
- package/src/workspace/index.ts +223 -0
- package/src/workspace/session-proxy-middleware.ts +97 -0
- package/src/workspace/sse.ts +66 -0
- package/src/workspace/workspace-context.ts +23 -0
- package/src/workspace/workspace-server/routes.ts +33 -0
- package/src/workspace/workspace-server/server.ts +47 -0
- package/src/worktree/index.ts +487 -0
- package/sst-env.d.ts +10 -0
- package/test/benchmark.test.ts +121 -0
- package/test/build-optimizations.test.ts +124 -0
- package/test/id-benchmark.test.ts +132 -0
- package/test/optimizations.test.ts +302 -0
- package/test/preload.ts +1 -0
- package/test/solidjs-benchmark.test.ts +262 -0
- package/test/solidjs-optimizations.test.ts +259 -0
- package/test/tui-benchmark.test.ts +230 -0
- package/test/wildcard-benchmark.test.ts +180 -0
- package/tsconfig.json +26 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { NamedError } from "@nikcli-ai/util/error"
|
|
2
|
+
import { MessageV2 } from "./message-v2"
|
|
3
|
+
|
|
4
|
+
export namespace SessionRetry {
|
|
5
|
+
export const RETRY_INITIAL_DELAY = 2000
|
|
6
|
+
export const RETRY_BACKOFF_FACTOR = 2
|
|
7
|
+
export const RETRY_MAX_DELAY_NO_HEADERS = 30_000
|
|
8
|
+
export const RETRY_MAX_DELAY = 2_147_483_647
|
|
9
|
+
|
|
10
|
+
export async function sleep(ms: number, signal: AbortSignal): Promise<void> {
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
const abortHandler = () => {
|
|
13
|
+
clearTimeout(timeout)
|
|
14
|
+
reject(new DOMException("Aborted", "AbortError"))
|
|
15
|
+
}
|
|
16
|
+
const timeout = setTimeout(
|
|
17
|
+
() => {
|
|
18
|
+
signal.removeEventListener("abort", abortHandler)
|
|
19
|
+
resolve()
|
|
20
|
+
},
|
|
21
|
+
Math.min(ms, RETRY_MAX_DELAY),
|
|
22
|
+
)
|
|
23
|
+
signal.addEventListener("abort", abortHandler, { once: true })
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function delay(attempt: number, error?: MessageV2.APIError) {
|
|
28
|
+
if (error) {
|
|
29
|
+
const headers = error.data.responseHeaders
|
|
30
|
+
if (headers) {
|
|
31
|
+
const retryAfterMs = headers["retry-after-ms"]
|
|
32
|
+
if (retryAfterMs) {
|
|
33
|
+
const parsedMs = Number.parseFloat(retryAfterMs)
|
|
34
|
+
if (!Number.isNaN(parsedMs)) {
|
|
35
|
+
return parsedMs
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const retryAfter = headers["retry-after"]
|
|
40
|
+
if (retryAfter) {
|
|
41
|
+
const parsedSeconds = Number.parseFloat(retryAfter)
|
|
42
|
+
if (!Number.isNaN(parsedSeconds)) {
|
|
43
|
+
return Math.ceil(parsedSeconds * 1000)
|
|
44
|
+
}
|
|
45
|
+
const parsed = Date.parse(retryAfter) - Date.now()
|
|
46
|
+
if (!Number.isNaN(parsed) && parsed > 0) {
|
|
47
|
+
return Math.ceil(parsed)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return RETRY_INITIAL_DELAY * Math.pow(RETRY_BACKOFF_FACTOR, attempt - 1)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return Math.min(RETRY_INITIAL_DELAY * Math.pow(RETRY_BACKOFF_FACTOR, attempt - 1), RETRY_MAX_DELAY_NO_HEADERS)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function retryable(error: ReturnType<NamedError["toObject"]>) {
|
|
59
|
+
if (MessageV2.APIError.isInstance(error)) {
|
|
60
|
+
if (!error.data.isRetryable) return undefined
|
|
61
|
+
if (error.data.responseBody?.includes("FreeUsageLimitError"))
|
|
62
|
+
return `Free usage exceeded, add credits https://opencode.ai/zen`
|
|
63
|
+
return error.data.message.includes("Overloaded") ? "Provider is overloaded" : error.data.message
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (typeof error.data?.message === "string") {
|
|
67
|
+
try {
|
|
68
|
+
const json = JSON.parse(error.data.message)
|
|
69
|
+
if (json.type === "error" && json.error?.type === "too_many_requests") {
|
|
70
|
+
return "Too Many Requests"
|
|
71
|
+
}
|
|
72
|
+
if (json.code.includes("exhausted") || json.code.includes("unavailable")) {
|
|
73
|
+
return "Provider is overloaded"
|
|
74
|
+
}
|
|
75
|
+
if (json.type === "error" && json.error?.code?.includes("rate_limit")) {
|
|
76
|
+
return "Rate Limited"
|
|
77
|
+
}
|
|
78
|
+
if (
|
|
79
|
+
json.error?.message?.includes("no_kv_space") ||
|
|
80
|
+
(json.type === "error" && json.error?.type === "server_error") ||
|
|
81
|
+
!!json.error
|
|
82
|
+
) {
|
|
83
|
+
return "Provider Server Error"
|
|
84
|
+
}
|
|
85
|
+
} catch {}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return undefined
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import z from "zod"
|
|
2
|
+
import { Identifier } from "../id/id"
|
|
3
|
+
import { Snapshot } from "../snapshot"
|
|
4
|
+
import { MessageV2 } from "./message-v2"
|
|
5
|
+
import { Session } from "."
|
|
6
|
+
import { Log } from "../util/log"
|
|
7
|
+
import { splitWhen } from "remeda"
|
|
8
|
+
import { Storage } from "../storage/storage"
|
|
9
|
+
import { Bus } from "../bus"
|
|
10
|
+
import { SessionPrompt } from "./prompt"
|
|
11
|
+
import { SessionSummary } from "./summary"
|
|
12
|
+
|
|
13
|
+
export namespace SessionRevert {
|
|
14
|
+
const log = Log.create({ service: "session.revert" })
|
|
15
|
+
|
|
16
|
+
export const RevertInput = z.object({
|
|
17
|
+
sessionID: Identifier.schema("session"),
|
|
18
|
+
messageID: Identifier.schema("message"),
|
|
19
|
+
partID: Identifier.schema("part").optional(),
|
|
20
|
+
})
|
|
21
|
+
export type RevertInput = z.infer<typeof RevertInput>
|
|
22
|
+
|
|
23
|
+
export async function revert(input: RevertInput) {
|
|
24
|
+
SessionPrompt.assertNotBusy(input.sessionID)
|
|
25
|
+
const all = await Session.messages({ sessionID: input.sessionID })
|
|
26
|
+
let lastUser: MessageV2.User | undefined
|
|
27
|
+
const session = await Session.get(input.sessionID)
|
|
28
|
+
|
|
29
|
+
let revert: Session.Info["revert"]
|
|
30
|
+
const patches: Snapshot.Patch[] = []
|
|
31
|
+
for (const msg of all) {
|
|
32
|
+
if (msg.info.role === "user") lastUser = msg.info
|
|
33
|
+
const remaining = []
|
|
34
|
+
for (const part of msg.parts) {
|
|
35
|
+
if (revert) {
|
|
36
|
+
if (part.type === "patch") {
|
|
37
|
+
patches.push(part)
|
|
38
|
+
}
|
|
39
|
+
continue
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!revert) {
|
|
43
|
+
if ((msg.info.id === input.messageID && !input.partID) || part.id === input.partID) {
|
|
44
|
+
const partID = remaining.some((item) => ["text", "tool"].includes(item.type)) ? input.partID : undefined
|
|
45
|
+
revert = {
|
|
46
|
+
messageID: !partID && lastUser ? lastUser.id : msg.info.id,
|
|
47
|
+
partID,
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
remaining.push(part)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (revert) {
|
|
56
|
+
const session = await Session.get(input.sessionID)
|
|
57
|
+
revert.snapshot = session.revert?.snapshot ?? (await Snapshot.track())
|
|
58
|
+
await Snapshot.revert(patches)
|
|
59
|
+
if (revert.snapshot) revert.diff = await Snapshot.diff(revert.snapshot)
|
|
60
|
+
const rangeMessages = all.filter((msg) => msg.info.id >= revert!.messageID)
|
|
61
|
+
const diffs = await SessionSummary.computeDiff({ messages: rangeMessages })
|
|
62
|
+
await Storage.write(["session_diff", input.sessionID], diffs)
|
|
63
|
+
Bus.publish(Session.Event.Diff, {
|
|
64
|
+
sessionID: input.sessionID,
|
|
65
|
+
diff: diffs,
|
|
66
|
+
})
|
|
67
|
+
return Session.update(input.sessionID, (draft) => {
|
|
68
|
+
draft.revert = revert
|
|
69
|
+
draft.summary = {
|
|
70
|
+
additions: diffs.reduce((sum, x) => sum + x.additions, 0),
|
|
71
|
+
deletions: diffs.reduce((sum, x) => sum + x.deletions, 0),
|
|
72
|
+
files: diffs.length,
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
return session
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export async function unrevert(input: { sessionID: string }) {
|
|
80
|
+
log.info("unreverting", input)
|
|
81
|
+
SessionPrompt.assertNotBusy(input.sessionID)
|
|
82
|
+
const session = await Session.get(input.sessionID)
|
|
83
|
+
if (!session.revert) return session
|
|
84
|
+
if (session.revert.snapshot) await Snapshot.restore(session.revert.snapshot)
|
|
85
|
+
const next = await Session.update(input.sessionID, (draft) => {
|
|
86
|
+
draft.revert = undefined
|
|
87
|
+
})
|
|
88
|
+
return next
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export async function cleanup(session: Session.Info) {
|
|
92
|
+
if (!session.revert) return
|
|
93
|
+
const sessionID = session.id
|
|
94
|
+
let msgs = await Session.messages({ sessionID })
|
|
95
|
+
const messageID = session.revert.messageID
|
|
96
|
+
const [preserve, remove] = splitWhen(msgs, (x) => x.info.id === messageID)
|
|
97
|
+
msgs = preserve
|
|
98
|
+
for (const msg of remove) {
|
|
99
|
+
await Storage.remove(["message", sessionID, msg.info.id])
|
|
100
|
+
await Bus.publish(MessageV2.Event.Removed, { sessionID: sessionID, messageID: msg.info.id })
|
|
101
|
+
}
|
|
102
|
+
const last = preserve.at(-1)
|
|
103
|
+
if (session.revert.partID && last) {
|
|
104
|
+
const partID = session.revert.partID
|
|
105
|
+
const [preserveParts, removeParts] = splitWhen(last.parts, (x) => x.id === partID)
|
|
106
|
+
last.parts = preserveParts
|
|
107
|
+
for (const part of removeParts) {
|
|
108
|
+
await Storage.remove(["part", last.info.id, part.id])
|
|
109
|
+
await Bus.publish(MessageV2.Event.PartRemoved, {
|
|
110
|
+
sessionID: sessionID,
|
|
111
|
+
messageID: last.info.id,
|
|
112
|
+
partID: part.id,
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
await Session.update(sessionID, (draft) => {
|
|
117
|
+
draft.revert = undefined
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
import type { Argv } from "yargs"
|
|
2
|
+
|
|
3
|
+
import { Session } from "../session"
|
|
4
|
+
|
|
5
|
+
import { Storage } from "../storage/storage"
|
|
6
|
+
import { Project } from "../project/project"
|
|
7
|
+
import { Instance } from "../project/instance"
|
|
8
|
+
import { bootstrap } from "@/cli/bootstrap"
|
|
9
|
+
import { cmd } from "@/cli/cmd/cmd"
|
|
10
|
+
|
|
11
|
+
interface SessionStats {
|
|
12
|
+
totalSessions: number
|
|
13
|
+
totalMessages: number
|
|
14
|
+
totalCost: number
|
|
15
|
+
totalTokens: {
|
|
16
|
+
input: number
|
|
17
|
+
output: number
|
|
18
|
+
reasoning: number
|
|
19
|
+
cache: {
|
|
20
|
+
read: number
|
|
21
|
+
write: number
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
toolUsage: Record<string, number>
|
|
25
|
+
modelUsage: Record<
|
|
26
|
+
string,
|
|
27
|
+
{
|
|
28
|
+
messages: number
|
|
29
|
+
tokens: {
|
|
30
|
+
input: number
|
|
31
|
+
output: number
|
|
32
|
+
}
|
|
33
|
+
cost: number
|
|
34
|
+
}
|
|
35
|
+
>
|
|
36
|
+
dateRange: {
|
|
37
|
+
earliest: number
|
|
38
|
+
latest: number
|
|
39
|
+
}
|
|
40
|
+
days: number
|
|
41
|
+
costPerDay: number
|
|
42
|
+
tokensPerSession: number
|
|
43
|
+
medianTokensPerSession: number
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const StatsCommand = cmd({
|
|
47
|
+
command: "stats",
|
|
48
|
+
describe: "show token usage and cost statistics",
|
|
49
|
+
builder: (yargs: Argv) => {
|
|
50
|
+
return yargs
|
|
51
|
+
.option("days", {
|
|
52
|
+
describe: "show stats for the last N days (default: all time)",
|
|
53
|
+
type: "number",
|
|
54
|
+
})
|
|
55
|
+
.option("tools", {
|
|
56
|
+
describe: "number of tools to show (default: all)",
|
|
57
|
+
type: "number",
|
|
58
|
+
})
|
|
59
|
+
.option("models", {
|
|
60
|
+
describe: "show model statistics (default: hidden). Pass a number to show top N, otherwise shows all",
|
|
61
|
+
})
|
|
62
|
+
.option("project", {
|
|
63
|
+
describe: "filter by project (default: all projects, empty string: current project)",
|
|
64
|
+
type: "string",
|
|
65
|
+
})
|
|
66
|
+
},
|
|
67
|
+
handler: async (args) => {
|
|
68
|
+
await bootstrap(process.cwd(), async () => {
|
|
69
|
+
const stats = await aggregateSessionStats(args.days, args.project)
|
|
70
|
+
|
|
71
|
+
let modelLimit: number | undefined
|
|
72
|
+
if (args.models === true) {
|
|
73
|
+
modelLimit = Infinity
|
|
74
|
+
} else if (typeof args.models === "number") {
|
|
75
|
+
modelLimit = args.models
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
displayStats(stats, args.tools, modelLimit)
|
|
79
|
+
})
|
|
80
|
+
},
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
async function getCurrentProject(): Promise<Project.Info> {
|
|
84
|
+
return Instance.project
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function getAllSessions(): Promise<Session.Info[]> {
|
|
88
|
+
const sessions: Session.Info[] = []
|
|
89
|
+
|
|
90
|
+
const projectKeys = await Storage.list(["project"])
|
|
91
|
+
const projects = await Promise.all(projectKeys.map((key) => Storage.read<Project.Info>(key)))
|
|
92
|
+
|
|
93
|
+
for (const project of projects) {
|
|
94
|
+
if (!project) continue
|
|
95
|
+
|
|
96
|
+
const sessionKeys = await Storage.list(["session", project.id])
|
|
97
|
+
const projectSessions = await Promise.all(sessionKeys.map((key) => Storage.read<Session.Info>(key)))
|
|
98
|
+
|
|
99
|
+
for (const session of projectSessions) {
|
|
100
|
+
if (session) {
|
|
101
|
+
sessions.push(session)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return sessions
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export async function aggregateSessionStats(days?: number, projectFilter?: string): Promise<SessionStats> {
|
|
110
|
+
const sessions = await getAllSessions()
|
|
111
|
+
const MS_IN_DAY = 24 * 60 * 60 * 1000
|
|
112
|
+
|
|
113
|
+
const cutoffTime = (() => {
|
|
114
|
+
if (days === undefined) return 0
|
|
115
|
+
if (days === 0) {
|
|
116
|
+
const now = new Date()
|
|
117
|
+
now.setHours(0, 0, 0, 0)
|
|
118
|
+
return now.getTime()
|
|
119
|
+
}
|
|
120
|
+
return Date.now() - days * MS_IN_DAY
|
|
121
|
+
})()
|
|
122
|
+
|
|
123
|
+
const windowDays = (() => {
|
|
124
|
+
if (days === undefined) return
|
|
125
|
+
if (days === 0) return 1
|
|
126
|
+
return days
|
|
127
|
+
})()
|
|
128
|
+
|
|
129
|
+
let filteredSessions = cutoffTime > 0 ? sessions.filter((session) => session.time.updated >= cutoffTime) : sessions
|
|
130
|
+
|
|
131
|
+
if (projectFilter !== undefined) {
|
|
132
|
+
if (projectFilter === "") {
|
|
133
|
+
const currentProject = await getCurrentProject()
|
|
134
|
+
filteredSessions = filteredSessions.filter((session) => session.projectID === currentProject.id)
|
|
135
|
+
} else {
|
|
136
|
+
filteredSessions = filteredSessions.filter((session) => session.projectID === projectFilter)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const stats: SessionStats = {
|
|
141
|
+
totalSessions: filteredSessions.length,
|
|
142
|
+
totalMessages: 0,
|
|
143
|
+
totalCost: 0,
|
|
144
|
+
totalTokens: {
|
|
145
|
+
input: 0,
|
|
146
|
+
output: 0,
|
|
147
|
+
reasoning: 0,
|
|
148
|
+
cache: {
|
|
149
|
+
read: 0,
|
|
150
|
+
write: 0,
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
toolUsage: {},
|
|
154
|
+
modelUsage: {},
|
|
155
|
+
dateRange: {
|
|
156
|
+
earliest: Date.now(),
|
|
157
|
+
latest: Date.now(),
|
|
158
|
+
},
|
|
159
|
+
days: 0,
|
|
160
|
+
costPerDay: 0,
|
|
161
|
+
tokensPerSession: 0,
|
|
162
|
+
medianTokensPerSession: 0,
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (filteredSessions.length > 1000) {
|
|
166
|
+
console.log(`Large dataset detected (${filteredSessions.length} sessions). This may take a while...`)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (filteredSessions.length === 0) {
|
|
170
|
+
stats.days = windowDays ?? 0
|
|
171
|
+
return stats
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
let earliestTime = Date.now()
|
|
175
|
+
let latestTime = 0
|
|
176
|
+
|
|
177
|
+
const sessionTotalTokens: number[] = []
|
|
178
|
+
|
|
179
|
+
const BATCH_SIZE = 20
|
|
180
|
+
for (let i = 0; i < filteredSessions.length; i += BATCH_SIZE) {
|
|
181
|
+
const batch = filteredSessions.slice(i, i + BATCH_SIZE)
|
|
182
|
+
|
|
183
|
+
const batchPromises = batch.map(async (session) => {
|
|
184
|
+
const messages = await Session.messages({ sessionID: session.id })
|
|
185
|
+
|
|
186
|
+
let sessionCost = 0
|
|
187
|
+
let sessionTokens = { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } }
|
|
188
|
+
let sessionToolUsage: Record<string, number> = {}
|
|
189
|
+
let sessionModelUsage: Record<
|
|
190
|
+
string,
|
|
191
|
+
{
|
|
192
|
+
messages: number
|
|
193
|
+
tokens: {
|
|
194
|
+
input: number
|
|
195
|
+
output: number
|
|
196
|
+
}
|
|
197
|
+
cost: number
|
|
198
|
+
}
|
|
199
|
+
> = {}
|
|
200
|
+
|
|
201
|
+
for (const message of messages) {
|
|
202
|
+
if (message.info.role === "assistant") {
|
|
203
|
+
sessionCost += message.info.cost || 0
|
|
204
|
+
|
|
205
|
+
const modelKey = `${message.info.providerID}/${message.info.modelID}`
|
|
206
|
+
if (!sessionModelUsage[modelKey]) {
|
|
207
|
+
sessionModelUsage[modelKey] = {
|
|
208
|
+
messages: 0,
|
|
209
|
+
tokens: { input: 0, output: 0 },
|
|
210
|
+
cost: 0,
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
sessionModelUsage[modelKey].messages++
|
|
214
|
+
sessionModelUsage[modelKey].cost += message.info.cost || 0
|
|
215
|
+
|
|
216
|
+
if (message.info.tokens) {
|
|
217
|
+
sessionTokens.input += message.info.tokens.input || 0
|
|
218
|
+
sessionTokens.output += message.info.tokens.output || 0
|
|
219
|
+
sessionTokens.reasoning += message.info.tokens.reasoning || 0
|
|
220
|
+
sessionTokens.cache.read += message.info.tokens.cache?.read || 0
|
|
221
|
+
sessionTokens.cache.write += message.info.tokens.cache?.write || 0
|
|
222
|
+
|
|
223
|
+
sessionModelUsage[modelKey].tokens.input += message.info.tokens.input || 0
|
|
224
|
+
sessionModelUsage[modelKey].tokens.output +=
|
|
225
|
+
(message.info.tokens.output || 0) + (message.info.tokens.reasoning || 0)
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
for (const part of message.parts) {
|
|
230
|
+
if (part.type === "tool" && part.tool) {
|
|
231
|
+
sessionToolUsage[part.tool] = (sessionToolUsage[part.tool] || 0) + 1
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return {
|
|
237
|
+
messageCount: messages.length,
|
|
238
|
+
sessionCost,
|
|
239
|
+
sessionTokens,
|
|
240
|
+
sessionTotalTokens: sessionTokens.input + sessionTokens.output + sessionTokens.reasoning,
|
|
241
|
+
sessionToolUsage,
|
|
242
|
+
sessionModelUsage,
|
|
243
|
+
earliestTime: cutoffTime > 0 ? session.time.updated : session.time.created,
|
|
244
|
+
latestTime: session.time.updated,
|
|
245
|
+
}
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
const batchResults = await Promise.all(batchPromises)
|
|
249
|
+
|
|
250
|
+
for (const result of batchResults) {
|
|
251
|
+
earliestTime = Math.min(earliestTime, result.earliestTime)
|
|
252
|
+
latestTime = Math.max(latestTime, result.latestTime)
|
|
253
|
+
sessionTotalTokens.push(result.sessionTotalTokens)
|
|
254
|
+
|
|
255
|
+
stats.totalMessages += result.messageCount
|
|
256
|
+
stats.totalCost += result.sessionCost
|
|
257
|
+
stats.totalTokens.input += result.sessionTokens.input
|
|
258
|
+
stats.totalTokens.output += result.sessionTokens.output
|
|
259
|
+
stats.totalTokens.reasoning += result.sessionTokens.reasoning
|
|
260
|
+
stats.totalTokens.cache.read += result.sessionTokens.cache.read
|
|
261
|
+
stats.totalTokens.cache.write += result.sessionTokens.cache.write
|
|
262
|
+
|
|
263
|
+
for (const [tool, count] of Object.entries(result.sessionToolUsage)) {
|
|
264
|
+
stats.toolUsage[tool] = (stats.toolUsage[tool] || 0) + count
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
for (const [model, usage] of Object.entries(result.sessionModelUsage)) {
|
|
268
|
+
if (!stats.modelUsage[model]) {
|
|
269
|
+
stats.modelUsage[model] = {
|
|
270
|
+
messages: 0,
|
|
271
|
+
tokens: { input: 0, output: 0 },
|
|
272
|
+
cost: 0,
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
stats.modelUsage[model].messages += usage.messages
|
|
276
|
+
stats.modelUsage[model].tokens.input += usage.tokens.input
|
|
277
|
+
stats.modelUsage[model].tokens.output += usage.tokens.output
|
|
278
|
+
stats.modelUsage[model].cost += usage.cost
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const rangeDays = Math.max(1, Math.ceil((latestTime - earliestTime) / MS_IN_DAY))
|
|
284
|
+
const effectiveDays = windowDays ?? rangeDays
|
|
285
|
+
stats.dateRange = {
|
|
286
|
+
earliest: earliestTime,
|
|
287
|
+
latest: latestTime,
|
|
288
|
+
}
|
|
289
|
+
stats.days = effectiveDays
|
|
290
|
+
stats.costPerDay = stats.totalCost / effectiveDays
|
|
291
|
+
const totalTokens = stats.totalTokens.input + stats.totalTokens.output + stats.totalTokens.reasoning
|
|
292
|
+
stats.tokensPerSession = filteredSessions.length > 0 ? totalTokens / filteredSessions.length : 0
|
|
293
|
+
sessionTotalTokens.sort((a, b) => a - b)
|
|
294
|
+
const mid = Math.floor(sessionTotalTokens.length / 2)
|
|
295
|
+
stats.medianTokensPerSession =
|
|
296
|
+
sessionTotalTokens.length === 0
|
|
297
|
+
? 0
|
|
298
|
+
: sessionTotalTokens.length % 2 === 0
|
|
299
|
+
? (sessionTotalTokens[mid - 1] + sessionTotalTokens[mid]) / 2
|
|
300
|
+
: sessionTotalTokens[mid]
|
|
301
|
+
|
|
302
|
+
return stats
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export function displayStats(stats: SessionStats, toolLimit?: number, modelLimit?: number) {
|
|
306
|
+
const width = 56
|
|
307
|
+
|
|
308
|
+
function renderRow(label: string, value: string): string {
|
|
309
|
+
const availableWidth = width - 1
|
|
310
|
+
const paddingNeeded = availableWidth - label.length - value.length
|
|
311
|
+
const padding = Math.max(0, paddingNeeded)
|
|
312
|
+
return `│${label}${" ".repeat(padding)}${value} │`
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// Overview section
|
|
316
|
+
console.log("┌────────────────────────────────────────────────────────┐")
|
|
317
|
+
console.log("│ OVERVIEW │")
|
|
318
|
+
console.log("├────────────────────────────────────────────────────────┤")
|
|
319
|
+
console.log(renderRow("Sessions", stats.totalSessions.toLocaleString()))
|
|
320
|
+
console.log(renderRow("Messages", stats.totalMessages.toLocaleString()))
|
|
321
|
+
console.log(renderRow("Days", stats.days.toString()))
|
|
322
|
+
console.log("└────────────────────────────────────────────────────────┘")
|
|
323
|
+
console.log()
|
|
324
|
+
|
|
325
|
+
// Cost & Tokens section
|
|
326
|
+
console.log("┌────────────────────────────────────────────────────────┐")
|
|
327
|
+
console.log("│ COST & TOKENS │")
|
|
328
|
+
console.log("├────────────────────────────────────────────────────────┤")
|
|
329
|
+
const cost = isNaN(stats.totalCost) ? 0 : stats.totalCost
|
|
330
|
+
const costPerDay = isNaN(stats.costPerDay) ? 0 : stats.costPerDay
|
|
331
|
+
const tokensPerSession = isNaN(stats.tokensPerSession) ? 0 : stats.tokensPerSession
|
|
332
|
+
console.log(renderRow("Total Cost", `$${cost.toFixed(2)}`))
|
|
333
|
+
console.log(renderRow("Avg Cost/Day", `$${costPerDay.toFixed(2)}`))
|
|
334
|
+
console.log(renderRow("Avg Tokens/Session", formatNumber(Math.round(tokensPerSession))))
|
|
335
|
+
const medianTokensPerSession = isNaN(stats.medianTokensPerSession) ? 0 : stats.medianTokensPerSession
|
|
336
|
+
console.log(renderRow("Median Tokens/Session", formatNumber(Math.round(medianTokensPerSession))))
|
|
337
|
+
console.log(renderRow("Input", formatNumber(stats.totalTokens.input)))
|
|
338
|
+
console.log(renderRow("Output", formatNumber(stats.totalTokens.output)))
|
|
339
|
+
console.log(renderRow("Cache Read", formatNumber(stats.totalTokens.cache.read)))
|
|
340
|
+
console.log(renderRow("Cache Write", formatNumber(stats.totalTokens.cache.write)))
|
|
341
|
+
console.log("└────────────────────────────────────────────────────────┘")
|
|
342
|
+
console.log()
|
|
343
|
+
|
|
344
|
+
// Model Usage section
|
|
345
|
+
if (modelLimit !== undefined && Object.keys(stats.modelUsage).length > 0) {
|
|
346
|
+
const sortedModels = Object.entries(stats.modelUsage).sort(([, a], [, b]) => b.messages - a.messages)
|
|
347
|
+
const modelsToDisplay = modelLimit === Infinity ? sortedModels : sortedModels.slice(0, modelLimit)
|
|
348
|
+
|
|
349
|
+
console.log("┌────────────────────────────────────────────────────────┐")
|
|
350
|
+
console.log("│ MODEL USAGE │")
|
|
351
|
+
console.log("├────────────────────────────────────────────────────────┤")
|
|
352
|
+
|
|
353
|
+
for (const [model, usage] of modelsToDisplay) {
|
|
354
|
+
console.log(`│ ${model.padEnd(54)} │`)
|
|
355
|
+
console.log(renderRow(" Messages", usage.messages.toLocaleString()))
|
|
356
|
+
console.log(renderRow(" Input Tokens", formatNumber(usage.tokens.input)))
|
|
357
|
+
console.log(renderRow(" Output Tokens", formatNumber(usage.tokens.output)))
|
|
358
|
+
console.log(renderRow(" Cost", `$${usage.cost.toFixed(4)}`))
|
|
359
|
+
console.log("├────────────────────────────────────────────────────────┤")
|
|
360
|
+
}
|
|
361
|
+
// Remove last separator and add bottom border
|
|
362
|
+
process.stdout.write("\x1B[1A") // Move up one line
|
|
363
|
+
console.log("└────────────────────────────────────────────────────────┘")
|
|
364
|
+
}
|
|
365
|
+
console.log()
|
|
366
|
+
|
|
367
|
+
// Tool Usage section
|
|
368
|
+
if (Object.keys(stats.toolUsage).length > 0) {
|
|
369
|
+
const sortedTools = Object.entries(stats.toolUsage).sort(([, a], [, b]) => b - a)
|
|
370
|
+
const toolsToDisplay = toolLimit ? sortedTools.slice(0, toolLimit) : sortedTools
|
|
371
|
+
|
|
372
|
+
console.log("┌────────────────────────────────────────────────────────┐")
|
|
373
|
+
console.log("│ TOOL USAGE │")
|
|
374
|
+
console.log("├────────────────────────────────────────────────────────┤")
|
|
375
|
+
|
|
376
|
+
const maxCount = Math.max(...toolsToDisplay.map(([, count]) => count))
|
|
377
|
+
const totalToolUsage = Object.values(stats.toolUsage).reduce((a, b) => a + b, 0)
|
|
378
|
+
|
|
379
|
+
for (const [tool, count] of toolsToDisplay) {
|
|
380
|
+
const barLength = Math.max(1, Math.floor((count / maxCount) * 20))
|
|
381
|
+
const bar = "█".repeat(barLength)
|
|
382
|
+
const percentage = ((count / totalToolUsage) * 100).toFixed(1)
|
|
383
|
+
|
|
384
|
+
const maxToolLength = 18
|
|
385
|
+
const truncatedTool = tool.length > maxToolLength ? tool.substring(0, maxToolLength - 2) + ".." : tool
|
|
386
|
+
const toolName = truncatedTool.padEnd(maxToolLength)
|
|
387
|
+
|
|
388
|
+
const content = ` ${toolName} ${bar.padEnd(20)} ${count.toString().padStart(3)} (${percentage.padStart(4)}%)`
|
|
389
|
+
const padding = Math.max(0, width - content.length - 1)
|
|
390
|
+
console.log(`│${content}${" ".repeat(padding)} │`)
|
|
391
|
+
}
|
|
392
|
+
console.log("└────────────────────────────────────────────────────────┘")
|
|
393
|
+
}
|
|
394
|
+
console.log()
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function formatNumber(num: number): string {
|
|
398
|
+
if (num >= 1000000) {
|
|
399
|
+
return (num / 1000000).toFixed(1) + "M"
|
|
400
|
+
} else if (num >= 1000) {
|
|
401
|
+
return (num / 1000).toFixed(1) + "K"
|
|
402
|
+
}
|
|
403
|
+
return num.toString()
|
|
404
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { BusEvent } from "@/bus/bus-event"
|
|
2
|
+
import { Bus } from "@/bus"
|
|
3
|
+
import { Instance } from "@/project/instance"
|
|
4
|
+
import z from "zod"
|
|
5
|
+
|
|
6
|
+
export namespace SessionStatus {
|
|
7
|
+
export const Info = z
|
|
8
|
+
.union([
|
|
9
|
+
z.object({
|
|
10
|
+
type: z.literal("idle"),
|
|
11
|
+
}),
|
|
12
|
+
z.object({
|
|
13
|
+
type: z.literal("retry"),
|
|
14
|
+
attempt: z.number(),
|
|
15
|
+
message: z.string(),
|
|
16
|
+
next: z.number(),
|
|
17
|
+
}),
|
|
18
|
+
z.object({
|
|
19
|
+
type: z.literal("busy"),
|
|
20
|
+
}),
|
|
21
|
+
])
|
|
22
|
+
.meta({
|
|
23
|
+
ref: "SessionStatus",
|
|
24
|
+
})
|
|
25
|
+
export type Info = z.infer<typeof Info>
|
|
26
|
+
|
|
27
|
+
export const Event = {
|
|
28
|
+
Status: BusEvent.define(
|
|
29
|
+
"session.status",
|
|
30
|
+
z.object({
|
|
31
|
+
sessionID: z.string(),
|
|
32
|
+
status: Info,
|
|
33
|
+
}),
|
|
34
|
+
),
|
|
35
|
+
// deprecated
|
|
36
|
+
Idle: BusEvent.define(
|
|
37
|
+
"session.idle",
|
|
38
|
+
z.object({
|
|
39
|
+
sessionID: z.string(),
|
|
40
|
+
}),
|
|
41
|
+
),
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const state = Instance.state(() => {
|
|
45
|
+
const data: Record<string, Info> = {}
|
|
46
|
+
return data
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
export function get(sessionID: string) {
|
|
50
|
+
return (
|
|
51
|
+
state()[sessionID] ?? {
|
|
52
|
+
type: "idle",
|
|
53
|
+
}
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function list() {
|
|
58
|
+
return state()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function set(sessionID: string, status: Info) {
|
|
62
|
+
Bus.publish(Event.Status, {
|
|
63
|
+
sessionID,
|
|
64
|
+
status,
|
|
65
|
+
})
|
|
66
|
+
if (status.type === "idle") {
|
|
67
|
+
// deprecated
|
|
68
|
+
Bus.publish(Event.Idle, {
|
|
69
|
+
sessionID,
|
|
70
|
+
})
|
|
71
|
+
delete state()[sessionID]
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
state()[sessionID] = status
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function hydrate(sessionID: string, status: Info) {
|
|
78
|
+
if (status.type === "idle") {
|
|
79
|
+
delete state()[sessionID]
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
state()[sessionID] = status
|
|
83
|
+
}
|
|
84
|
+
}
|