rird 2.1.231 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +86 -0
- package/COMPLETED_TEST_SUITE.txt +280 -0
- package/Dockerfile +18 -0
- package/README.md +397 -6
- package/RIRD_ERROR_HANDLING_SUMMARY.md +307 -0
- package/TESTING.md +512 -0
- package/TEST_IMPLEMENTATION_REPORT.md +463 -0
- package/TEST_SUITE.md +307 -0
- package/TEST_SUMMARY.txt +380 -0
- package/bin/rird-perf.js +37 -0
- package/bin/rird.js +43 -8
- package/bunfig.toml +4 -0
- package/create-wrapper.ps1 +51 -0
- package/docs/ARCHITECTURE.md +768 -0
- package/docs/CLI_REFERENCE.md +681 -0
- package/docs/DOCUMENTATION_MANIFEST.md +392 -0
- package/docs/INDEX.md +295 -0
- package/docs/PRODUCTION_SETUP.md +633 -0
- package/docs/TROUBLESHOOTING.md +914 -0
- package/facebook_ads_library.png +0 -0
- package/nul +0 -0
- package/nul`nif +0 -0
- package/package.json +104 -15
- package/parsers-config.ts +239 -0
- package/rird-1.0.199.tgz +0 -0
- package/rird-1.0.205.tgz +0 -0
- package/script/build-windows.ts +56 -0
- package/script/build.ts +165 -0
- package/{postinstall.mjs → script/postinstall.mjs} +47 -68
- package/script/publish-registries.ts +187 -0
- package/script/publish.ts +85 -0
- package/script/schema.ts +47 -0
- package/src/acp/README.md +164 -0
- package/src/acp/agent.ts +1063 -0
- package/src/acp/session.ts +101 -0
- package/src/acp/types.ts +22 -0
- package/src/agent/agent.ts +367 -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 +10 -0
- package/src/agent/prompt/title.txt +36 -0
- package/src/auth/index.ts +70 -0
- package/src/bun/index.ts +114 -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 +104 -0
- package/src/cli/cmd/activate.ts +50 -0
- package/src/cli/cmd/agent.ts +256 -0
- package/src/cli/cmd/auth.ts +412 -0
- package/src/cli/cmd/cmd.ts +7 -0
- package/src/cli/cmd/debug/config.ts +15 -0
- package/src/cli/cmd/debug/file.ts +91 -0
- package/src/cli/cmd/debug/index.ts +43 -0
- package/src/cli/cmd/debug/lsp.ts +48 -0
- package/src/cli/cmd/debug/ripgrep.ts +83 -0
- package/src/cli/cmd/debug/scrap.ts +15 -0
- package/src/cli/cmd/debug/skill.ts +15 -0
- package/src/cli/cmd/debug/snapshot.ts +48 -0
- package/src/cli/cmd/export.ts +88 -0
- package/src/cli/cmd/generate.ts +38 -0
- package/src/cli/cmd/github.ts +1400 -0
- package/src/cli/cmd/import.ts +98 -0
- package/src/cli/cmd/mcp.ts +654 -0
- package/src/cli/cmd/models.ts +68 -0
- package/src/cli/cmd/pr.ts +112 -0
- package/src/cli/cmd/run.ts +434 -0
- package/src/cli/cmd/serve.ts +31 -0
- package/src/cli/cmd/session.ts +106 -0
- package/src/cli/cmd/stats.ts +298 -0
- package/src/cli/cmd/tui/app.tsx +694 -0
- package/src/cli/cmd/tui/attach.ts +30 -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 +124 -0
- package/src/cli/cmd/tui/component/dialog-mcp.tsx +86 -0
- package/src/cli/cmd/tui/component/dialog-model.tsx +236 -0
- package/src/cli/cmd/tui/component/dialog-provider.tsx +240 -0
- package/src/cli/cmd/tui/component/dialog-session-list.tsx +102 -0
- package/src/cli/cmd/tui/component/dialog-session-rename.tsx +31 -0
- package/src/cli/cmd/tui/component/dialog-stash.tsx +86 -0
- package/src/cli/cmd/tui/component/dialog-status.tsx +162 -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/did-you-know.tsx +85 -0
- package/src/cli/cmd/tui/component/logo.tsx +48 -0
- package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +574 -0
- package/src/cli/cmd/tui/component/prompt/history.tsx +108 -0
- package/src/cli/cmd/tui/component/prompt/index.tsx +1087 -0
- package/src/cli/cmd/tui/component/prompt/stash.tsx +101 -0
- package/src/cli/cmd/tui/component/tips.ts +27 -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 +23 -0
- package/src/cli/cmd/tui/context/helper.tsx +25 -0
- package/src/cli/cmd/tui/context/keybind.tsx +101 -0
- package/src/cli/cmd/tui/context/kv.tsx +49 -0
- package/src/cli/cmd/tui/context/local.tsx +345 -0
- package/src/cli/cmd/tui/context/prompt.tsx +18 -0
- package/src/cli/cmd/tui/context/route.tsx +46 -0
- package/src/cli/cmd/tui/context/sdk.tsx +74 -0
- package/src/cli/cmd/tui/context/sync.tsx +372 -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/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 +95 -0
- package/src/cli/cmd/tui/context/theme/kanagawa.json +77 -0
- package/src/cli/cmd/tui/context/theme/lucent-orng.json +227 -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 +245 -0
- package/src/cli/cmd/tui/context/theme/palenight.json +222 -0
- package/src/cli/cmd/tui/context/theme/rird.json +245 -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 +1109 -0
- package/src/cli/cmd/tui/event.ts +40 -0
- package/src/cli/cmd/tui/hooks/use-safe-terminal-dimensions.ts +12 -0
- package/src/cli/cmd/tui/routes/home.tsx +138 -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 +88 -0
- package/src/cli/cmd/tui/routes/session/header.tsx +125 -0
- package/src/cli/cmd/tui/routes/session/index.tsx +1876 -0
- package/src/cli/cmd/tui/routes/session/sidebar.tsx +320 -0
- package/src/cli/cmd/tui/spawn.ts +60 -0
- package/src/cli/cmd/tui/thread.ts +142 -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-help.tsx +38 -0
- package/src/cli/cmd/tui/ui/dialog-prompt.tsx +77 -0
- package/src/cli/cmd/tui/ui/dialog-select.tsx +333 -0
- package/src/cli/cmd/tui/ui/dialog.tsx +171 -0
- package/src/cli/cmd/tui/ui/spinner.ts +368 -0
- package/src/cli/cmd/tui/ui/toast.tsx +100 -0
- package/src/cli/cmd/tui/util/clipboard.ts +127 -0
- package/src/cli/cmd/tui/util/editor.ts +32 -0
- package/src/cli/cmd/tui/util/terminal.ts +146 -0
- package/src/cli/cmd/tui/worker.ts +63 -0
- package/src/cli/cmd/uninstall.ts +344 -0
- package/src/cli/cmd/upgrade.ts +127 -0
- package/src/cli/cmd/web.ts +84 -0
- package/src/cli/error.ts +69 -0
- package/src/cli/ui.ts +101 -0
- package/src/cli/upgrade.ts +28 -0
- package/src/command/index.ts +80 -0
- package/src/command/template/initialize.txt +10 -0
- package/src/command/template/review.txt +97 -0
- package/src/config/config.ts +994 -0
- package/src/config/markdown.ts +41 -0
- package/src/env/index.ts +26 -0
- package/src/file/ignore.ts +83 -0
- package/src/file/index.ts +328 -0
- package/src/file/ripgrep.ts +393 -0
- package/src/file/time.ts +64 -0
- package/src/file/watcher.ts +103 -0
- package/src/flag/flag.ts +84 -0
- package/src/format/formatter.ts +315 -0
- package/src/format/index.ts +137 -0
- package/src/global/index.ts +101 -0
- package/src/id/id.ts +73 -0
- package/src/ide/index.ts +76 -0
- package/src/index.ts +297 -0
- package/src/index.ts.backup +271 -0
- package/src/installation/index.ts +258 -0
- package/src/lib/IMPLEMENTATION_NOTES.md +345 -0
- package/src/lib/error-handler.ts +225 -0
- package/src/lib/error-testing-guide.md +258 -0
- package/src/lib/errors.ts +285 -0
- package/src/lib/performance.ts +70 -0
- package/src/lib/telemetry.ts +282 -0
- package/src/lsp/client.ts +229 -0
- package/src/lsp/index.ts +485 -0
- package/src/lsp/language.ts +116 -0
- package/src/lsp/server.ts +1895 -0
- package/src/mcp/auth.ts +135 -0
- package/src/mcp/index.ts +1117 -0
- package/src/mcp/intent-analyzer.ts +376 -0
- package/src/mcp/oauth-callback.ts +200 -0
- package/src/mcp/oauth-provider.ts +154 -0
- package/src/patch/index.ts +632 -0
- package/src/permission/index.ts +199 -0
- package/src/plugin/index.ts +91 -0
- package/src/project/bootstrap.ts +33 -0
- package/src/project/instance.ts +78 -0
- package/src/project/project.ts +236 -0
- package/src/project/state.ts +65 -0
- package/src/project/vcs.ts +76 -0
- package/src/provider/auth.ts +143 -0
- package/src/provider/models-macro.ts +55 -0
- package/src/provider/models.ts +161 -0
- package/src/provider/provider.ts +1109 -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 +1713 -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 +455 -0
- package/src/pty/index.ts +231 -0
- package/src/security/guardrails.test.ts +341 -0
- package/src/security/guardrails.ts +570 -0
- package/src/security/index.ts +19 -0
- package/src/server/error.ts +36 -0
- package/src/server/project.ts +79 -0
- package/src/server/server.ts +2641 -0
- package/src/server/tui.ts +71 -0
- package/src/session/compaction.ts +228 -0
- package/src/session/index.ts +464 -0
- package/src/session/llm.ts +201 -0
- package/src/session/message-v2.ts +695 -0
- package/src/session/message.ts +189 -0
- package/src/session/processor.ts +409 -0
- package/src/session/prompt/act-switch.txt +5 -0
- package/src/session/prompt/anthropic-20250930.txt +166 -0
- package/src/session/prompt/anthropic.txt +63 -0
- package/src/session/prompt/anthropic_spoof.txt +1 -0
- package/src/session/prompt/beast.txt +76 -0
- package/src/session/prompt/codex.txt +304 -0
- package/src/session/prompt/copilot-gpt-5.txt +137 -0
- package/src/session/prompt/gemini.txt +62 -0
- package/src/session/prompt/max-steps.txt +16 -0
- package/src/session/prompt/plan-reminder-anthropic.txt +35 -0
- package/src/session/prompt/plan.txt +24 -0
- package/src/session/prompt/polaris.txt +88 -0
- package/src/session/prompt/qwen.txt +59 -0
- package/src/session/prompt.ts +1552 -0
- package/src/session/retry.ts +86 -0
- package/src/session/revert.ts +108 -0
- package/src/session/sensitive-filter.test.ts +327 -0
- package/src/session/sensitive-filter.ts +466 -0
- package/src/session/status.ts +76 -0
- package/src/session/summary.ts +209 -0
- package/src/session/system.ts +122 -0
- package/src/session/todo.ts +37 -0
- package/src/share/share-next.ts +222 -0
- package/src/share/share.ts +87 -0
- package/src/shell/shell.ts +67 -0
- package/src/skill/index.ts +1 -0
- package/src/skill/skill.ts +83 -0
- package/src/snapshot/index.ts +197 -0
- package/src/storage/storage.ts +226 -0
- package/src/tests/agent.test.ts +308 -0
- package/src/tests/build-guards.test.ts +267 -0
- package/src/tests/config.test.ts +664 -0
- package/src/tests/tool-registry.test.ts +589 -0
- package/src/tool/bash.ts +314 -0
- package/src/tool/bash.txt +158 -0
- package/src/tool/batch.ts +175 -0
- package/src/tool/batch.txt +24 -0
- package/src/tool/codesearch.ts +184 -0
- package/src/tool/codesearch.txt +12 -0
- package/src/tool/edit.ts +675 -0
- package/src/tool/edit.txt +10 -0
- package/src/tool/glob.ts +65 -0
- package/src/tool/glob.txt +6 -0
- package/src/tool/grep.ts +121 -0
- package/src/tool/grep.txt +8 -0
- package/src/tool/invalid.ts +17 -0
- package/src/tool/ls.ts +110 -0
- package/src/tool/ls.txt +1 -0
- package/src/tool/lsp-diagnostics.ts +26 -0
- package/src/tool/lsp-diagnostics.txt +1 -0
- package/src/tool/lsp-hover.ts +31 -0
- package/src/tool/lsp-hover.txt +1 -0
- package/src/tool/lsp.ts +87 -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/patch.ts +233 -0
- package/src/tool/patch.txt +1 -0
- package/src/tool/read.ts +219 -0
- package/src/tool/read.txt +12 -0
- package/src/tool/registry.ts +162 -0
- package/src/tool/skill.ts +100 -0
- package/src/tool/task.ts +136 -0
- package/src/tool/task.txt +51 -0
- package/src/tool/todo.ts +39 -0
- package/src/tool/todoread.txt +14 -0
- package/src/tool/todowrite.txt +167 -0
- package/src/tool/tool.ts +71 -0
- package/src/tool/webfetch.ts +198 -0
- package/src/tool/webfetch.txt +13 -0
- package/src/tool/websearch.ts +268 -0
- package/src/tool/websearch.txt +13 -0
- package/src/tool/write.ts +110 -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 +83 -0
- package/src/util/fn.ts +11 -0
- package/src/util/iife.ts +3 -0
- package/src/util/keybind.ts +102 -0
- package/src/util/lazy.ts +11 -0
- package/src/util/license.ts +362 -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 +42 -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 +54 -0
- package/sst-env.d.ts +9 -0
- package/test/agent/agent.test.ts +146 -0
- package/test/bun.test.ts +53 -0
- package/test/cli/cmd/acp.test.ts +144 -0
- package/test/cli/cmd/run.test.ts +250 -0
- package/test/cli/github-remote.test.ts +80 -0
- package/test/config/agent-color.test.ts +66 -0
- package/test/config/config.test.ts +536 -0
- package/test/config/markdown.test.ts +89 -0
- package/test/file/ignore.test.ts +10 -0
- package/test/fixture/fixture.ts +37 -0
- package/test/fixture/lsp/fake-lsp-server.js +77 -0
- package/test/helpers.ts +172 -0
- package/test/ide/ide.test.ts +82 -0
- package/test/installation/installation.test.ts +143 -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/patch/patch.test.ts +348 -0
- package/test/preload.ts +57 -0
- package/test/project/project.test.ts +74 -0
- package/test/provider/provider.test.ts +74 -0
- package/test/provider/transform.test.ts +411 -0
- package/test/session/retry.test.ts +111 -0
- package/test/session/session.test.ts +71 -0
- package/test/skill/skill.test.ts +131 -0
- package/test/snapshot/snapshot.test.ts +940 -0
- package/test/tool/__snapshots__/tool.test.ts.snap +9 -0
- package/test/tool/bash.test.ts +434 -0
- package/test/tool/grep.test.ts +108 -0
- package/test/tool/patch.test.ts +259 -0
- package/test/tool/read.test.ts +42 -0
- package/test/util/iife.test.ts +36 -0
- package/test/util/lazy.test.ts +50 -0
- package/test/util/license.test.ts +235 -0
- package/test/util/timeout.test.ts +21 -0
- package/test/util/wildcard.test.ts +55 -0
- package/tsconfig.json +16 -0
- package/update-versions.ps1 +65 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Argv } from "yargs"
|
|
2
|
+
import { Instance } from "../../project/instance"
|
|
3
|
+
import { Provider } from "../../provider/provider"
|
|
4
|
+
import { cmd } from "./cmd"
|
|
5
|
+
import { UI } from "../ui"
|
|
6
|
+
import { EOL } from "os"
|
|
7
|
+
|
|
8
|
+
export const ModelsCommand = cmd({
|
|
9
|
+
command: "models [provider]",
|
|
10
|
+
describe: "list all available models",
|
|
11
|
+
builder: (yargs: Argv) => {
|
|
12
|
+
return yargs
|
|
13
|
+
.positional("provider", {
|
|
14
|
+
describe: "provider ID to filter models by",
|
|
15
|
+
type: "string",
|
|
16
|
+
array: false,
|
|
17
|
+
})
|
|
18
|
+
.option("verbose", {
|
|
19
|
+
describe: "use more verbose model output (includes metadata like costs)",
|
|
20
|
+
type: "boolean",
|
|
21
|
+
})
|
|
22
|
+
},
|
|
23
|
+
handler: async (args) => {
|
|
24
|
+
await Instance.provide({
|
|
25
|
+
directory: process.cwd(),
|
|
26
|
+
async fn() {
|
|
27
|
+
const providers = await Provider.list()
|
|
28
|
+
|
|
29
|
+
function printModels(providerID: string, verbose?: boolean) {
|
|
30
|
+
const provider = providers[providerID]
|
|
31
|
+
const sortedModels = Object.entries(provider.models).sort(([a], [b]) => a.localeCompare(b))
|
|
32
|
+
for (const [modelID, model] of sortedModels) {
|
|
33
|
+
process.stdout.write(`${providerID}/${modelID}`)
|
|
34
|
+
process.stdout.write(EOL)
|
|
35
|
+
if (verbose) {
|
|
36
|
+
process.stdout.write(JSON.stringify(model, null, 2))
|
|
37
|
+
process.stdout.write(EOL)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (args.provider) {
|
|
43
|
+
const providerID = args.provider
|
|
44
|
+
const provider = providers[providerID]
|
|
45
|
+
if (!provider) {
|
|
46
|
+
UI.error(`Provider not found: ${args.provider}`)
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
printModels(providerID, args.verbose)
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const providerIDs = Object.keys(providers).sort((a, b) => {
|
|
55
|
+
const aIsRird = a.startsWith("rird")
|
|
56
|
+
const bIsRird = b.startsWith("rird")
|
|
57
|
+
if (aIsRird && !bIsRird) return -1
|
|
58
|
+
if (!aIsRird && bIsRird) return 1
|
|
59
|
+
return a.localeCompare(b)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
for (const providerID of providerIDs) {
|
|
63
|
+
printModels(providerID, args.verbose)
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
},
|
|
68
|
+
})
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { UI } from "../ui"
|
|
2
|
+
import { cmd } from "./cmd"
|
|
3
|
+
import { Instance } from "@/project/instance"
|
|
4
|
+
import { $ } from "bun"
|
|
5
|
+
|
|
6
|
+
export const PrCommand = cmd({
|
|
7
|
+
command: "pr <number>",
|
|
8
|
+
describe: "fetch and checkout a GitHub PR branch, then run RIRD",
|
|
9
|
+
builder: (yargs) =>
|
|
10
|
+
yargs.positional("number", {
|
|
11
|
+
type: "number",
|
|
12
|
+
describe: "PR number to checkout",
|
|
13
|
+
demandOption: true,
|
|
14
|
+
}),
|
|
15
|
+
async handler(args) {
|
|
16
|
+
await Instance.provide({
|
|
17
|
+
directory: process.cwd(),
|
|
18
|
+
async fn() {
|
|
19
|
+
const project = Instance.project
|
|
20
|
+
if (project.vcs !== "git") {
|
|
21
|
+
UI.error("Could not find git repository. Please run this command from a git repository.")
|
|
22
|
+
process.exit(1)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const prNumber = args.number
|
|
26
|
+
const localBranchName = `pr/${prNumber}`
|
|
27
|
+
UI.println(`Fetching and checking out PR #${prNumber}...`)
|
|
28
|
+
|
|
29
|
+
// Use gh pr checkout with custom branch name
|
|
30
|
+
const result = await $`gh pr checkout ${prNumber} --branch ${localBranchName} --force`.nothrow()
|
|
31
|
+
|
|
32
|
+
if (result.exitCode !== 0) {
|
|
33
|
+
UI.error(`Failed to checkout PR #${prNumber}. Make sure you have gh CLI installed and authenticated.`)
|
|
34
|
+
process.exit(1)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Fetch PR info for fork handling and session link detection
|
|
38
|
+
const prInfoResult =
|
|
39
|
+
await $`gh pr view ${prNumber} --json headRepository,headRepositoryOwner,isCrossRepository,headRefName,body`.nothrow()
|
|
40
|
+
|
|
41
|
+
let sessionId: string | undefined
|
|
42
|
+
|
|
43
|
+
if (prInfoResult.exitCode === 0) {
|
|
44
|
+
const prInfoText = prInfoResult.text()
|
|
45
|
+
if (prInfoText.trim()) {
|
|
46
|
+
const prInfo = JSON.parse(prInfoText)
|
|
47
|
+
|
|
48
|
+
// Handle fork PRs
|
|
49
|
+
if (prInfo && prInfo.isCrossRepository && prInfo.headRepository && prInfo.headRepositoryOwner) {
|
|
50
|
+
const forkOwner = prInfo.headRepositoryOwner.login
|
|
51
|
+
const forkName = prInfo.headRepository.name
|
|
52
|
+
const remoteName = forkOwner
|
|
53
|
+
|
|
54
|
+
// Check if remote already exists
|
|
55
|
+
const remotes = (await $`git remote`.nothrow().text()).trim()
|
|
56
|
+
if (!remotes.split("\n").includes(remoteName)) {
|
|
57
|
+
await $`git remote add ${remoteName} https://github.com/${forkOwner}/${forkName}.git`.nothrow()
|
|
58
|
+
UI.println(`Added fork remote: ${remoteName}`)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Set upstream to the fork so pushes go there
|
|
62
|
+
const headRefName = prInfo.headRefName
|
|
63
|
+
await $`git branch --set-upstream-to=${remoteName}/${headRefName} ${localBranchName}`.nothrow()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Check for RIRD session link in PR body
|
|
67
|
+
if (prInfo && prInfo.body) {
|
|
68
|
+
const sessionMatch = prInfo.body.match(/https:\/\/opncd\.ai\/s\/([a-zA-Z0-9_-]+)/)
|
|
69
|
+
if (sessionMatch) {
|
|
70
|
+
const sessionUrl = sessionMatch[0]
|
|
71
|
+
UI.println(`Found RIRD session: ${sessionUrl}`)
|
|
72
|
+
UI.println(`Importing session...`)
|
|
73
|
+
|
|
74
|
+
const importResult = await $`rird import ${sessionUrl}`.nothrow()
|
|
75
|
+
if (importResult.exitCode === 0) {
|
|
76
|
+
const importOutput = importResult.text().trim()
|
|
77
|
+
// Extract session ID from the output (format: "Imported session: <session-id>")
|
|
78
|
+
const sessionIdMatch = importOutput.match(/Imported session: ([a-zA-Z0-9_-]+)/)
|
|
79
|
+
if (sessionIdMatch) {
|
|
80
|
+
sessionId = sessionIdMatch[1]
|
|
81
|
+
UI.println(`Session imported: ${sessionId}`)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
UI.println(`Successfully checked out PR #${prNumber} as branch '${localBranchName}'`)
|
|
90
|
+
UI.println()
|
|
91
|
+
UI.println("Starting RIRD...")
|
|
92
|
+
UI.println()
|
|
93
|
+
|
|
94
|
+
// Launch RIRD TUI with session ID if available
|
|
95
|
+
const { spawn } = await import("child_process")
|
|
96
|
+
const rirdArgs = sessionId ? ["-s", sessionId] : []
|
|
97
|
+
const rirdProcess = spawn("rird", rirdArgs, {
|
|
98
|
+
stdio: "inherit",
|
|
99
|
+
cwd: process.cwd(),
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
await new Promise<void>((resolve, reject) => {
|
|
103
|
+
rirdProcess.on("exit", (code) => {
|
|
104
|
+
if (code === 0) resolve()
|
|
105
|
+
else reject(new Error(`RIRD exited with code ${code}`))
|
|
106
|
+
})
|
|
107
|
+
rirdProcess.on("error", reject)
|
|
108
|
+
})
|
|
109
|
+
},
|
|
110
|
+
})
|
|
111
|
+
},
|
|
112
|
+
})
|
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import type { Argv } from "yargs"
|
|
2
|
+
import path from "path"
|
|
3
|
+
import { UI } from "../ui"
|
|
4
|
+
import { cmd } from "./cmd"
|
|
5
|
+
import { Flag } from "../../flag/flag"
|
|
6
|
+
import { bootstrap } from "../bootstrap"
|
|
7
|
+
import { Command } from "../../command"
|
|
8
|
+
import { EOL } from "os"
|
|
9
|
+
import { select } from "@clack/prompts"
|
|
10
|
+
import { createOpencodeClient, type OpencodeClient } from "@opencode-ai/sdk/v2"
|
|
11
|
+
import { Server } from "../../server/server"
|
|
12
|
+
import { Provider } from "../../provider/provider"
|
|
13
|
+
import { Agent } from "../../agent/agent"
|
|
14
|
+
import { Log } from "../../util/log"
|
|
15
|
+
import { ValidationError, NetworkError, ProviderError, FileSystemError } from "../../lib/errors"
|
|
16
|
+
import { handleError } from "../../lib/error-handler"
|
|
17
|
+
|
|
18
|
+
const log = Log.create({ service: "run-command" })
|
|
19
|
+
|
|
20
|
+
const FALLBACK_MODEL = "rird/qwen3:8b"
|
|
21
|
+
|
|
22
|
+
const TOOL: Record<string, [string, string]> = {
|
|
23
|
+
todowrite: ["Todo", UI.Style.TEXT_WARNING_BOLD],
|
|
24
|
+
todoread: ["Todo", UI.Style.TEXT_WARNING_BOLD],
|
|
25
|
+
bash: ["Bash", UI.Style.TEXT_DANGER_BOLD],
|
|
26
|
+
edit: ["Edit", UI.Style.TEXT_SUCCESS_BOLD],
|
|
27
|
+
glob: ["Glob", UI.Style.TEXT_INFO_BOLD],
|
|
28
|
+
grep: ["Grep", UI.Style.TEXT_INFO_BOLD],
|
|
29
|
+
list: ["List", UI.Style.TEXT_INFO_BOLD],
|
|
30
|
+
read: ["Read", UI.Style.TEXT_HIGHLIGHT_BOLD],
|
|
31
|
+
write: ["Write", UI.Style.TEXT_SUCCESS_BOLD],
|
|
32
|
+
web_search_rird: ["Search", UI.Style.TEXT_DIM_BOLD],
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function toolLabel(tool: string): [string, string] {
|
|
36
|
+
if (tool.startsWith("chrome_")) return ["Chrome", UI.Style.TEXT_INFO_BOLD]
|
|
37
|
+
return TOOL[tool] ?? [tool, UI.Style.TEXT_INFO_BOLD]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const RunCommand = cmd({
|
|
41
|
+
command: "run [message..]",
|
|
42
|
+
describe: "run rird with a message",
|
|
43
|
+
builder: (yargs: Argv) => {
|
|
44
|
+
return yargs
|
|
45
|
+
.positional("message", {
|
|
46
|
+
describe: "message to send",
|
|
47
|
+
type: "string",
|
|
48
|
+
array: true,
|
|
49
|
+
default: [],
|
|
50
|
+
})
|
|
51
|
+
.option("command", {
|
|
52
|
+
describe: "the command to run, use message for args",
|
|
53
|
+
type: "string",
|
|
54
|
+
})
|
|
55
|
+
.option("continue", {
|
|
56
|
+
alias: ["c"],
|
|
57
|
+
describe: "continue the last session",
|
|
58
|
+
type: "boolean",
|
|
59
|
+
})
|
|
60
|
+
.option("session", {
|
|
61
|
+
alias: ["s"],
|
|
62
|
+
describe: "session id to continue",
|
|
63
|
+
type: "string",
|
|
64
|
+
})
|
|
65
|
+
.option("share", {
|
|
66
|
+
type: "boolean",
|
|
67
|
+
describe: "share the session",
|
|
68
|
+
})
|
|
69
|
+
.option("model", {
|
|
70
|
+
type: "string",
|
|
71
|
+
alias: ["m"],
|
|
72
|
+
describe: "model to use in the format of provider/model",
|
|
73
|
+
})
|
|
74
|
+
.option("agent", {
|
|
75
|
+
type: "string",
|
|
76
|
+
describe: "agent to use",
|
|
77
|
+
})
|
|
78
|
+
.option("format", {
|
|
79
|
+
type: "string",
|
|
80
|
+
choices: ["default", "json"],
|
|
81
|
+
default: "default",
|
|
82
|
+
describe: "format: default (formatted) or json (raw JSON events)",
|
|
83
|
+
})
|
|
84
|
+
.option("file", {
|
|
85
|
+
alias: ["f"],
|
|
86
|
+
type: "string",
|
|
87
|
+
array: true,
|
|
88
|
+
describe: "file(s) to attach to message",
|
|
89
|
+
})
|
|
90
|
+
.option("title", {
|
|
91
|
+
type: "string",
|
|
92
|
+
describe: "title for the session (uses truncated prompt if no value provided)",
|
|
93
|
+
})
|
|
94
|
+
.option("attach", {
|
|
95
|
+
type: "string",
|
|
96
|
+
describe: "attach to a running rird server (e.g., http://localhost:4096)",
|
|
97
|
+
})
|
|
98
|
+
.option("port", {
|
|
99
|
+
type: "number",
|
|
100
|
+
describe: "port for the local server (defaults to random port if no value provided)",
|
|
101
|
+
})
|
|
102
|
+
},
|
|
103
|
+
handler: async (args) => {
|
|
104
|
+
try {
|
|
105
|
+
let message = [...args.message, ...(args["--"] || [])]
|
|
106
|
+
.map((arg) => (arg.includes(" ") ? `"${arg.replace(/"/g, '\\"')}"` : arg))
|
|
107
|
+
.join(" ")
|
|
108
|
+
|
|
109
|
+
const fileParts: any[] = []
|
|
110
|
+
if (args.file) {
|
|
111
|
+
const files = Array.isArray(args.file) ? args.file : [args.file]
|
|
112
|
+
|
|
113
|
+
for (const filePath of files) {
|
|
114
|
+
try {
|
|
115
|
+
const resolvedPath = path.resolve(process.cwd(), filePath)
|
|
116
|
+
const file = Bun.file(resolvedPath)
|
|
117
|
+
const stats = await file.stat().catch(() => {})
|
|
118
|
+
if (!stats || !(await file.exists())) {
|
|
119
|
+
throw new FileSystemError(`File not found: ${filePath}`, {
|
|
120
|
+
code: "FILE_NOT_FOUND",
|
|
121
|
+
details: { filePath, resolvedPath },
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const stat = await file.stat()
|
|
126
|
+
const mime = stat.isDirectory() ? "application/x-directory" : "text/plain"
|
|
127
|
+
|
|
128
|
+
fileParts.push({
|
|
129
|
+
type: "file",
|
|
130
|
+
url: `file://${resolvedPath}`,
|
|
131
|
+
filename: path.basename(resolvedPath),
|
|
132
|
+
mime,
|
|
133
|
+
})
|
|
134
|
+
} catch (error) {
|
|
135
|
+
if (error instanceof FileSystemError) throw error
|
|
136
|
+
throw new FileSystemError(`Failed to access file: ${filePath}`, {
|
|
137
|
+
code: "FILE_ACCESS_ERROR",
|
|
138
|
+
originalError: error as Error,
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (!process.stdin.isTTY) message += "\n" + (await Bun.stdin.text())
|
|
145
|
+
|
|
146
|
+
if (message.trim().length === 0 && !args.command) {
|
|
147
|
+
throw new ValidationError("You must provide a message or a command", {
|
|
148
|
+
code: "EMPTY_INPUT",
|
|
149
|
+
details: { hasCommand: !!args.command, messageLength: message.length },
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const isUnauthorizedError = (props: any, err: string) => {
|
|
154
|
+
const statusCode = (() => {
|
|
155
|
+
if (!props?.error) return undefined
|
|
156
|
+
if (!("data" in props.error)) return undefined
|
|
157
|
+
const data = (props.error as any).data
|
|
158
|
+
if (!data || typeof data !== "object") return undefined
|
|
159
|
+
const code = (data as any).statusCode
|
|
160
|
+
return typeof code === "number" ? code : undefined
|
|
161
|
+
})()
|
|
162
|
+
if (statusCode === 401 || statusCode === 403) return true
|
|
163
|
+
const lower = err.toLowerCase()
|
|
164
|
+
if (lower.includes("unauthorized")) return true
|
|
165
|
+
if (lower.includes("invalid api key")) return true
|
|
166
|
+
if (lower.includes("invalid token")) return true
|
|
167
|
+
return false
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const execute = async (sdk: OpencodeClient, sessionID: string, modelOverride?: string) => {
|
|
171
|
+
const printEvent = (color: string, type: string, title: string) => {
|
|
172
|
+
UI.println(
|
|
173
|
+
color + `|`,
|
|
174
|
+
UI.Style.TEXT_NORMAL + UI.Style.TEXT_DIM + ` ${type.padEnd(7, " ")}`,
|
|
175
|
+
"",
|
|
176
|
+
UI.Style.TEXT_NORMAL + title,
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const outputJsonEvent = (type: string, data: any) => {
|
|
181
|
+
if (args.format === "json") {
|
|
182
|
+
process.stdout.write(JSON.stringify({ type, timestamp: Date.now(), sessionID, ...data }) + EOL)
|
|
183
|
+
return true
|
|
184
|
+
}
|
|
185
|
+
return false
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const events = await sdk.event.subscribe()
|
|
189
|
+
let errorMsg: string | undefined
|
|
190
|
+
let hitUnauthorized = false
|
|
191
|
+
|
|
192
|
+
const eventProcessor = (async () => {
|
|
193
|
+
for await (const event of events.stream) {
|
|
194
|
+
if (event.type === "message.part.updated") {
|
|
195
|
+
const part = event.properties.part
|
|
196
|
+
if (part.sessionID !== sessionID) continue
|
|
197
|
+
|
|
198
|
+
if (part.type === "tool" && part.state.status === "completed") {
|
|
199
|
+
if (outputJsonEvent("tool_use", { part })) continue
|
|
200
|
+
const [tool, color] = toolLabel(part.tool)
|
|
201
|
+
const title =
|
|
202
|
+
part.state.title ||
|
|
203
|
+
(Object.keys(part.state.input).length > 0 ? JSON.stringify(part.state.input) : "Unknown")
|
|
204
|
+
printEvent(color, tool, title)
|
|
205
|
+
if (part.tool === "bash" && part.state.output?.trim()) {
|
|
206
|
+
UI.println()
|
|
207
|
+
UI.println(part.state.output)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (part.type === "step-start") {
|
|
212
|
+
if (outputJsonEvent("step_start", { part })) continue
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (part.type === "step-finish") {
|
|
216
|
+
if (outputJsonEvent("step_finish", { part })) continue
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (part.type === "text" && part.time?.end) {
|
|
220
|
+
if (outputJsonEvent("text", { part })) continue
|
|
221
|
+
const isPiped = !process.stdout.isTTY
|
|
222
|
+
if (!isPiped) UI.println()
|
|
223
|
+
process.stdout.write((isPiped ? part.text : UI.markdown(part.text)) + EOL)
|
|
224
|
+
if (!isPiped) UI.println()
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (event.type === "session.error") {
|
|
229
|
+
const props = event.properties
|
|
230
|
+
if (props.sessionID !== sessionID || !props.error) continue
|
|
231
|
+
let err = String(props.error.name)
|
|
232
|
+
if ("data" in props.error && props.error.data && "message" in props.error.data) {
|
|
233
|
+
err = String(props.error.data.message)
|
|
234
|
+
}
|
|
235
|
+
if (!args.model && !modelOverride && isUnauthorizedError(props, err)) {
|
|
236
|
+
hitUnauthorized = true
|
|
237
|
+
errorMsg = errorMsg ? errorMsg + EOL + err : err
|
|
238
|
+
if (outputJsonEvent("error", { error: props.error })) continue
|
|
239
|
+
continue
|
|
240
|
+
}
|
|
241
|
+
errorMsg = errorMsg ? errorMsg + EOL + err : err
|
|
242
|
+
if (outputJsonEvent("error", { error: props.error })) continue
|
|
243
|
+
UI.error(err)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (event.type === "session.idle" && event.properties.sessionID === sessionID) {
|
|
247
|
+
break
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (event.type === "permission.updated") {
|
|
251
|
+
const permission = event.properties
|
|
252
|
+
if (permission.sessionID !== sessionID) continue
|
|
253
|
+
const result = await select({
|
|
254
|
+
message: `Permission required to run: ${permission.title}`,
|
|
255
|
+
options: [
|
|
256
|
+
{ value: "once", label: "Allow once" },
|
|
257
|
+
{ value: "always", label: "Always allow" },
|
|
258
|
+
{ value: "reject", label: "Reject" },
|
|
259
|
+
],
|
|
260
|
+
initialValue: "once",
|
|
261
|
+
}).catch(() => "reject")
|
|
262
|
+
const response = (result.toString().includes("cancel") ? "reject" : result) as "once" | "always" | "reject"
|
|
263
|
+
await sdk.permission.respond({
|
|
264
|
+
sessionID,
|
|
265
|
+
permissionID: permission.id,
|
|
266
|
+
response,
|
|
267
|
+
})
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
})()
|
|
271
|
+
|
|
272
|
+
// Validate agent if specified
|
|
273
|
+
const resolvedAgent = await (async () => {
|
|
274
|
+
if (!args.agent) return undefined
|
|
275
|
+
const agent = await Agent.get(args.agent)
|
|
276
|
+
if (!agent) {
|
|
277
|
+
UI.println(
|
|
278
|
+
UI.Style.TEXT_WARNING_BOLD + "!",
|
|
279
|
+
UI.Style.TEXT_NORMAL,
|
|
280
|
+
`agent "${args.agent}" not found. Falling back to default agent`,
|
|
281
|
+
)
|
|
282
|
+
return undefined
|
|
283
|
+
}
|
|
284
|
+
if (agent.mode === "subagent") {
|
|
285
|
+
UI.println(
|
|
286
|
+
UI.Style.TEXT_WARNING_BOLD + "!",
|
|
287
|
+
UI.Style.TEXT_NORMAL,
|
|
288
|
+
`agent "${args.agent}" is a subagent, not a primary agent. Falling back to default agent`,
|
|
289
|
+
)
|
|
290
|
+
return undefined
|
|
291
|
+
}
|
|
292
|
+
return args.agent
|
|
293
|
+
})()
|
|
294
|
+
|
|
295
|
+
if (args.command) {
|
|
296
|
+
await sdk.session.command({
|
|
297
|
+
sessionID,
|
|
298
|
+
agent: resolvedAgent,
|
|
299
|
+
model: modelOverride ?? args.model,
|
|
300
|
+
command: args.command,
|
|
301
|
+
arguments: message,
|
|
302
|
+
})
|
|
303
|
+
} else {
|
|
304
|
+
const modelParam = modelOverride
|
|
305
|
+
? Provider.parseModel(modelOverride)
|
|
306
|
+
: args.model
|
|
307
|
+
? Provider.parseModel(args.model)
|
|
308
|
+
: undefined
|
|
309
|
+
await sdk.session.prompt({
|
|
310
|
+
sessionID,
|
|
311
|
+
agent: resolvedAgent,
|
|
312
|
+
model: modelParam,
|
|
313
|
+
parts: [...fileParts, { type: "text", text: message }],
|
|
314
|
+
})
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
await eventProcessor
|
|
318
|
+
return { errorMsg, hitUnauthorized }
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (args.attach) {
|
|
322
|
+
const sdk = createOpencodeClient({ baseUrl: args.attach })
|
|
323
|
+
|
|
324
|
+
const sessionID = await (async () => {
|
|
325
|
+
if (args.continue) {
|
|
326
|
+
const result = await sdk.session.list()
|
|
327
|
+
return result.data?.find((s) => !s.parentID)?.id
|
|
328
|
+
}
|
|
329
|
+
if (args.session) return args.session
|
|
330
|
+
|
|
331
|
+
const title =
|
|
332
|
+
args.title !== undefined
|
|
333
|
+
? args.title === ""
|
|
334
|
+
? message.slice(0, 50) + (message.length > 50 ? "..." : "")
|
|
335
|
+
: args.title
|
|
336
|
+
: undefined
|
|
337
|
+
|
|
338
|
+
const result = await sdk.session.create(title ? { title } : {})
|
|
339
|
+
return result.data?.id
|
|
340
|
+
})()
|
|
341
|
+
|
|
342
|
+
if (!sessionID) {
|
|
343
|
+
UI.error("Session not found")
|
|
344
|
+
process.exit(1)
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const cfgResult = await sdk.config.get()
|
|
348
|
+
if (cfgResult.data && (cfgResult.data.share === "auto" || Flag.OPENCODE_AUTO_SHARE || args.share)) {
|
|
349
|
+
const shareResult = await sdk.session.share({ sessionID }).catch((error) => {
|
|
350
|
+
if (error instanceof Error && error.message.includes("disabled")) {
|
|
351
|
+
UI.println(UI.Style.TEXT_DANGER_BOLD + "! " + error.message)
|
|
352
|
+
}
|
|
353
|
+
return { error }
|
|
354
|
+
})
|
|
355
|
+
if (!shareResult.error && "data" in shareResult && shareResult.data?.share?.url) {
|
|
356
|
+
UI.println(UI.Style.TEXT_INFO_BOLD + "~ " + shareResult.data.share.url)
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const result = await execute(sdk, sessionID)
|
|
361
|
+
if (!args.model && result.hitUnauthorized) {
|
|
362
|
+
const retry = await execute(sdk, sessionID, FALLBACK_MODEL)
|
|
363
|
+
if (retry.errorMsg) process.exit(1)
|
|
364
|
+
return
|
|
365
|
+
}
|
|
366
|
+
if (result.errorMsg) process.exit(1)
|
|
367
|
+
return
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
await bootstrap(process.cwd(), async () => {
|
|
371
|
+
const server = Server.listen({ port: args.port ?? 0, hostname: "127.0.0.1" })
|
|
372
|
+
const sdk = createOpencodeClient({ baseUrl: `http://${server.hostname}:${server.port}` })
|
|
373
|
+
|
|
374
|
+
try {
|
|
375
|
+
if (args.command) {
|
|
376
|
+
const exists = await Command.get(args.command)
|
|
377
|
+
if (!exists) {
|
|
378
|
+
UI.error(`Command "${args.command}" not found`)
|
|
379
|
+
process.exit(1)
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const sessionID = await (async () => {
|
|
384
|
+
if (args.continue) {
|
|
385
|
+
const result = await sdk.session.list()
|
|
386
|
+
return result.data?.find((s) => !s.parentID)?.id
|
|
387
|
+
}
|
|
388
|
+
if (args.session) return args.session
|
|
389
|
+
|
|
390
|
+
const title =
|
|
391
|
+
args.title !== undefined
|
|
392
|
+
? args.title === ""
|
|
393
|
+
? message.slice(0, 50) + (message.length > 50 ? "..." : "")
|
|
394
|
+
: args.title
|
|
395
|
+
: undefined
|
|
396
|
+
|
|
397
|
+
const result = await sdk.session.create(title ? { title } : {})
|
|
398
|
+
return result.data?.id
|
|
399
|
+
})()
|
|
400
|
+
|
|
401
|
+
if (!sessionID) {
|
|
402
|
+
UI.error("Session not found")
|
|
403
|
+
process.exit(1)
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const cfgResult = await sdk.config.get()
|
|
407
|
+
if (cfgResult.data && (cfgResult.data.share === "auto" || Flag.OPENCODE_AUTO_SHARE || args.share)) {
|
|
408
|
+
const shareResult = await sdk.session.share({ sessionID }).catch((error) => {
|
|
409
|
+
if (error instanceof Error && error.message.includes("disabled")) {
|
|
410
|
+
UI.println(UI.Style.TEXT_DANGER_BOLD + "! " + error.message)
|
|
411
|
+
}
|
|
412
|
+
return { error }
|
|
413
|
+
})
|
|
414
|
+
if (!shareResult.error && "data" in shareResult && shareResult.data?.share?.url) {
|
|
415
|
+
UI.println(UI.Style.TEXT_INFO_BOLD + "~ " + shareResult.data.share.url)
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const result = await execute(sdk, sessionID)
|
|
420
|
+
if (!args.model && result.hitUnauthorized) {
|
|
421
|
+
const retry = await execute(sdk, sessionID, FALLBACK_MODEL)
|
|
422
|
+
if (retry.errorMsg) process.exit(1)
|
|
423
|
+
return
|
|
424
|
+
}
|
|
425
|
+
if (result.errorMsg) process.exit(1)
|
|
426
|
+
} finally {
|
|
427
|
+
server.stop()
|
|
428
|
+
}
|
|
429
|
+
})
|
|
430
|
+
} catch (error) {
|
|
431
|
+
await handleError(error, "run-command", { exitOnError: true })
|
|
432
|
+
}
|
|
433
|
+
},
|
|
434
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Server } from "../../server/server"
|
|
2
|
+
import { cmd } from "./cmd"
|
|
3
|
+
|
|
4
|
+
export const ServeCommand = cmd({
|
|
5
|
+
command: "serve",
|
|
6
|
+
builder: (yargs) =>
|
|
7
|
+
yargs
|
|
8
|
+
.option("port", {
|
|
9
|
+
alias: ["p"],
|
|
10
|
+
type: "number",
|
|
11
|
+
describe: "port to listen on",
|
|
12
|
+
default: 0,
|
|
13
|
+
})
|
|
14
|
+
.option("hostname", {
|
|
15
|
+
type: "string",
|
|
16
|
+
describe: "hostname to listen on",
|
|
17
|
+
default: "127.0.0.1",
|
|
18
|
+
}),
|
|
19
|
+
describe: "starts a headless rird server",
|
|
20
|
+
handler: async (args) => {
|
|
21
|
+
const hostname = args.hostname
|
|
22
|
+
const port = args.port
|
|
23
|
+
const server = Server.listen({
|
|
24
|
+
port,
|
|
25
|
+
hostname,
|
|
26
|
+
})
|
|
27
|
+
console.log(`rird server listening on http://${server.hostname}:${server.port}`)
|
|
28
|
+
await new Promise(() => {})
|
|
29
|
+
await server.stop()
|
|
30
|
+
},
|
|
31
|
+
})
|