nuwaxcode 1.1.32 → 1.1.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/nuwaxcode +19 -1
- package/package.json +15 -117
- package/{script/postinstall.mjs → postinstall.mjs} +18 -6
- package/AGENTS.md +0 -27
- package/Dockerfile +0 -18
- package/README.md +0 -15
- package/bunfig.toml +0 -7
- package/parsers-config.ts +0 -253
- package/script/build.ts +0 -172
- package/script/publish-registries.ts +0 -187
- package/script/publish.ts +0 -70
- package/script/schema.ts +0 -47
- package/src/acp/README.md +0 -164
- package/src/acp/agent.ts +0 -1280
- package/src/acp/session.ts +0 -111
- package/src/acp/types.ts +0 -24
- package/src/agent/agent.ts +0 -332
- package/src/agent/generate.txt +0 -75
- package/src/agent/prompt/compaction.txt +0 -12
- package/src/agent/prompt/explore.txt +0 -18
- package/src/agent/prompt/summary.txt +0 -11
- package/src/agent/prompt/title.txt +0 -43
- package/src/auth/index.ts +0 -73
- package/src/bun/index.ts +0 -134
- package/src/bus/bus-event.ts +0 -43
- package/src/bus/global.ts +0 -10
- package/src/bus/index.ts +0 -105
- package/src/cli/bootstrap.ts +0 -17
- package/src/cli/cmd/acp.ts +0 -69
- package/src/cli/cmd/agent.ts +0 -257
- package/src/cli/cmd/auth.ts +0 -400
- package/src/cli/cmd/cmd.ts +0 -7
- package/src/cli/cmd/debug/agent.ts +0 -166
- package/src/cli/cmd/debug/config.ts +0 -16
- package/src/cli/cmd/debug/file.ts +0 -97
- package/src/cli/cmd/debug/index.ts +0 -48
- package/src/cli/cmd/debug/lsp.ts +0 -52
- package/src/cli/cmd/debug/ripgrep.ts +0 -87
- package/src/cli/cmd/debug/scrap.ts +0 -16
- package/src/cli/cmd/debug/skill.ts +0 -16
- package/src/cli/cmd/debug/snapshot.ts +0 -52
- package/src/cli/cmd/export.ts +0 -88
- package/src/cli/cmd/generate.ts +0 -38
- package/src/cli/cmd/github.ts +0 -1548
- package/src/cli/cmd/import.ts +0 -98
- package/src/cli/cmd/mcp.ts +0 -755
- package/src/cli/cmd/models.ts +0 -77
- package/src/cli/cmd/pr.ts +0 -112
- package/src/cli/cmd/run.ts +0 -395
- package/src/cli/cmd/serve.ts +0 -20
- package/src/cli/cmd/session.ts +0 -135
- package/src/cli/cmd/stats.ts +0 -402
- package/src/cli/cmd/tui/app.tsx +0 -761
- package/src/cli/cmd/tui/attach.ts +0 -31
- package/src/cli/cmd/tui/component/border.tsx +0 -21
- package/src/cli/cmd/tui/component/dialog-agent.tsx +0 -31
- package/src/cli/cmd/tui/component/dialog-command.tsx +0 -148
- package/src/cli/cmd/tui/component/dialog-mcp.tsx +0 -86
- package/src/cli/cmd/tui/component/dialog-model.tsx +0 -234
- package/src/cli/cmd/tui/component/dialog-provider.tsx +0 -256
- package/src/cli/cmd/tui/component/dialog-session-list.tsx +0 -114
- package/src/cli/cmd/tui/component/dialog-session-rename.tsx +0 -31
- package/src/cli/cmd/tui/component/dialog-stash.tsx +0 -87
- package/src/cli/cmd/tui/component/dialog-status.tsx +0 -164
- package/src/cli/cmd/tui/component/dialog-tag.tsx +0 -44
- package/src/cli/cmd/tui/component/dialog-theme-list.tsx +0 -50
- package/src/cli/cmd/tui/component/logo.tsx +0 -88
- package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +0 -632
- package/src/cli/cmd/tui/component/prompt/frecency.tsx +0 -89
- package/src/cli/cmd/tui/component/prompt/history.tsx +0 -108
- package/src/cli/cmd/tui/component/prompt/index.tsx +0 -1096
- package/src/cli/cmd/tui/component/prompt/stash.tsx +0 -101
- package/src/cli/cmd/tui/component/textarea-keybindings.ts +0 -73
- package/src/cli/cmd/tui/component/tips.tsx +0 -153
- package/src/cli/cmd/tui/component/todo-item.tsx +0 -32
- package/src/cli/cmd/tui/context/args.tsx +0 -14
- package/src/cli/cmd/tui/context/directory.ts +0 -13
- package/src/cli/cmd/tui/context/exit.tsx +0 -23
- package/src/cli/cmd/tui/context/helper.tsx +0 -25
- package/src/cli/cmd/tui/context/keybind.tsx +0 -101
- package/src/cli/cmd/tui/context/kv.tsx +0 -52
- package/src/cli/cmd/tui/context/local.tsx +0 -402
- package/src/cli/cmd/tui/context/prompt.tsx +0 -18
- package/src/cli/cmd/tui/context/route.tsx +0 -46
- package/src/cli/cmd/tui/context/sdk.tsx +0 -94
- package/src/cli/cmd/tui/context/sync.tsx +0 -427
- package/src/cli/cmd/tui/context/theme/aura.json +0 -69
- package/src/cli/cmd/tui/context/theme/ayu.json +0 -80
- package/src/cli/cmd/tui/context/theme/carbonfox.json +0 -248
- package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +0 -233
- package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +0 -233
- package/src/cli/cmd/tui/context/theme/catppuccin.json +0 -112
- package/src/cli/cmd/tui/context/theme/cobalt2.json +0 -228
- package/src/cli/cmd/tui/context/theme/cursor.json +0 -249
- package/src/cli/cmd/tui/context/theme/dracula.json +0 -219
- package/src/cli/cmd/tui/context/theme/everforest.json +0 -241
- package/src/cli/cmd/tui/context/theme/flexoki.json +0 -237
- package/src/cli/cmd/tui/context/theme/github.json +0 -233
- package/src/cli/cmd/tui/context/theme/gruvbox.json +0 -95
- package/src/cli/cmd/tui/context/theme/kanagawa.json +0 -77
- package/src/cli/cmd/tui/context/theme/lucent-orng.json +0 -237
- package/src/cli/cmd/tui/context/theme/material.json +0 -235
- package/src/cli/cmd/tui/context/theme/matrix.json +0 -77
- package/src/cli/cmd/tui/context/theme/mercury.json +0 -252
- package/src/cli/cmd/tui/context/theme/monokai.json +0 -221
- package/src/cli/cmd/tui/context/theme/nightowl.json +0 -221
- package/src/cli/cmd/tui/context/theme/nord.json +0 -223
- package/src/cli/cmd/tui/context/theme/one-dark.json +0 -84
- package/src/cli/cmd/tui/context/theme/orng.json +0 -249
- package/src/cli/cmd/tui/context/theme/osaka-jade.json +0 -93
- package/src/cli/cmd/tui/context/theme/palenight.json +0 -222
- package/src/cli/cmd/tui/context/theme/rosepine.json +0 -234
- package/src/cli/cmd/tui/context/theme/solarized.json +0 -223
- package/src/cli/cmd/tui/context/theme/synthwave84.json +0 -226
- package/src/cli/cmd/tui/context/theme/tokyonight.json +0 -243
- package/src/cli/cmd/tui/context/theme/vercel.json +0 -245
- package/src/cli/cmd/tui/context/theme/vesper.json +0 -218
- package/src/cli/cmd/tui/context/theme/zenburn.json +0 -223
- package/src/cli/cmd/tui/context/theme.tsx +0 -1152
- package/src/cli/cmd/tui/event.ts +0 -48
- package/src/cli/cmd/tui/routes/home.tsx +0 -140
- package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +0 -64
- package/src/cli/cmd/tui/routes/session/dialog-message.tsx +0 -109
- package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +0 -26
- package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +0 -47
- package/src/cli/cmd/tui/routes/session/footer.tsx +0 -91
- package/src/cli/cmd/tui/routes/session/header.tsx +0 -136
- package/src/cli/cmd/tui/routes/session/index.tsx +0 -2050
- package/src/cli/cmd/tui/routes/session/permission.tsx +0 -495
- package/src/cli/cmd/tui/routes/session/question.tsx +0 -435
- package/src/cli/cmd/tui/routes/session/sidebar.tsx +0 -312
- package/src/cli/cmd/tui/thread.ts +0 -165
- package/src/cli/cmd/tui/ui/dialog-alert.tsx +0 -57
- package/src/cli/cmd/tui/ui/dialog-confirm.tsx +0 -83
- package/src/cli/cmd/tui/ui/dialog-export-options.tsx +0 -204
- package/src/cli/cmd/tui/ui/dialog-help.tsx +0 -38
- package/src/cli/cmd/tui/ui/dialog-prompt.tsx +0 -77
- package/src/cli/cmd/tui/ui/dialog-select.tsx +0 -354
- package/src/cli/cmd/tui/ui/dialog.tsx +0 -167
- package/src/cli/cmd/tui/ui/link.tsx +0 -28
- package/src/cli/cmd/tui/ui/spinner.ts +0 -368
- package/src/cli/cmd/tui/ui/toast.tsx +0 -100
- package/src/cli/cmd/tui/util/clipboard.ts +0 -160
- package/src/cli/cmd/tui/util/editor.ts +0 -32
- package/src/cli/cmd/tui/util/signal.ts +0 -7
- package/src/cli/cmd/tui/util/terminal.ts +0 -114
- package/src/cli/cmd/tui/util/transcript.ts +0 -98
- package/src/cli/cmd/tui/worker.ts +0 -152
- package/src/cli/cmd/uninstall.ts +0 -357
- package/src/cli/cmd/upgrade.ts +0 -73
- package/src/cli/cmd/web.ts +0 -81
- package/src/cli/error.ts +0 -57
- package/src/cli/network.ts +0 -53
- package/src/cli/ui.ts +0 -84
- package/src/cli/upgrade.ts +0 -25
- package/src/command/index.ts +0 -131
- package/src/command/template/initialize.txt +0 -10
- package/src/command/template/review.txt +0 -99
- package/src/config/config.ts +0 -1255
- package/src/config/markdown.ts +0 -93
- package/src/env/index.ts +0 -26
- package/src/file/ignore.ts +0 -83
- package/src/file/index.ts +0 -411
- package/src/file/ripgrep.ts +0 -409
- package/src/file/time.ts +0 -64
- package/src/file/watcher.ts +0 -118
- package/src/flag/flag.ts +0 -54
- package/src/format/formatter.ts +0 -359
- package/src/format/index.ts +0 -137
- package/src/global/index.ts +0 -55
- package/src/id/id.ts +0 -83
- package/src/ide/index.ts +0 -76
- package/src/index.ts +0 -159
- package/src/installation/index.ts +0 -246
- package/src/lsp/client.ts +0 -252
- package/src/lsp/index.ts +0 -485
- package/src/lsp/language.ts +0 -119
- package/src/lsp/server.ts +0 -2046
- package/src/mcp/auth.ts +0 -135
- package/src/mcp/index.ts +0 -926
- package/src/mcp/oauth-callback.ts +0 -200
- package/src/mcp/oauth-provider.ts +0 -154
- package/src/patch/index.ts +0 -680
- package/src/permission/arity.ts +0 -163
- package/src/permission/index.ts +0 -210
- package/src/permission/next.ts +0 -269
- package/src/plugin/codex.ts +0 -493
- package/src/plugin/copilot.ts +0 -269
- package/src/plugin/index.ts +0 -135
- package/src/project/bootstrap.ts +0 -35
- package/src/project/instance.ts +0 -91
- package/src/project/project.ts +0 -320
- package/src/project/state.ts +0 -66
- package/src/project/vcs.ts +0 -76
- package/src/provider/auth.ts +0 -147
- package/src/provider/models-macro.ts +0 -11
- package/src/provider/models.ts +0 -112
- package/src/provider/provider.ts +0 -1219
- package/src/provider/sdk/openai-compatible/src/README.md +0 -5
- package/src/provider/sdk/openai-compatible/src/index.ts +0 -2
- package/src/provider/sdk/openai-compatible/src/openai-compatible-provider.ts +0 -100
- package/src/provider/sdk/openai-compatible/src/responses/convert-to-openai-responses-input.ts +0 -303
- package/src/provider/sdk/openai-compatible/src/responses/map-openai-responses-finish-reason.ts +0 -22
- package/src/provider/sdk/openai-compatible/src/responses/openai-config.ts +0 -18
- package/src/provider/sdk/openai-compatible/src/responses/openai-error.ts +0 -22
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-api-types.ts +0 -207
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-language-model.ts +0 -1732
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-prepare-tools.ts +0 -177
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-settings.ts +0 -1
- package/src/provider/sdk/openai-compatible/src/responses/tool/code-interpreter.ts +0 -88
- package/src/provider/sdk/openai-compatible/src/responses/tool/file-search.ts +0 -128
- package/src/provider/sdk/openai-compatible/src/responses/tool/image-generation.ts +0 -115
- package/src/provider/sdk/openai-compatible/src/responses/tool/local-shell.ts +0 -65
- package/src/provider/sdk/openai-compatible/src/responses/tool/web-search-preview.ts +0 -104
- package/src/provider/sdk/openai-compatible/src/responses/tool/web-search.ts +0 -103
- package/src/provider/transform.ts +0 -724
- package/src/pty/index.ts +0 -229
- package/src/question/index.ts +0 -171
- package/src/scheduler/index.ts +0 -61
- package/src/server/error.ts +0 -36
- package/src/server/mdns.ts +0 -59
- package/src/server/routes/config.ts +0 -92
- package/src/server/routes/experimental.ts +0 -157
- package/src/server/routes/file.ts +0 -197
- package/src/server/routes/global.ts +0 -135
- package/src/server/routes/mcp.ts +0 -225
- package/src/server/routes/permission.ts +0 -68
- package/src/server/routes/project.ts +0 -82
- package/src/server/routes/provider.ts +0 -165
- package/src/server/routes/pty.ts +0 -169
- package/src/server/routes/question.ts +0 -98
- package/src/server/routes/session.ts +0 -935
- package/src/server/routes/tui.ts +0 -379
- package/src/server/server.ts +0 -578
- package/src/session/compaction.ts +0 -225
- package/src/session/index.ts +0 -488
- package/src/session/llm.ts +0 -279
- package/src/session/message-v2.ts +0 -702
- package/src/session/message.ts +0 -189
- package/src/session/processor.ts +0 -406
- package/src/session/prompt/anthropic-20250930.txt +0 -166
- package/src/session/prompt/anthropic.txt +0 -105
- package/src/session/prompt/anthropic_spoof.txt +0 -1
- package/src/session/prompt/beast.txt +0 -147
- package/src/session/prompt/build-switch.txt +0 -5
- package/src/session/prompt/codex.txt +0 -73
- package/src/session/prompt/codex_header.txt +0 -72
- package/src/session/prompt/copilot-gpt-5.txt +0 -143
- package/src/session/prompt/gemini.txt +0 -155
- package/src/session/prompt/max-steps.txt +0 -16
- package/src/session/prompt/plan-reminder-anthropic.txt +0 -67
- package/src/session/prompt/plan.txt +0 -26
- package/src/session/prompt/qwen.txt +0 -109
- package/src/session/prompt.ts +0 -1805
- package/src/session/retry.ts +0 -90
- package/src/session/revert.ts +0 -108
- package/src/session/status.ts +0 -76
- package/src/session/summary.ts +0 -150
- package/src/session/system.ts +0 -138
- package/src/session/todo.ts +0 -37
- package/src/share/share-next.ts +0 -194
- package/src/share/share.ts +0 -87
- package/src/shell/shell.ts +0 -67
- package/src/skill/index.ts +0 -1
- package/src/skill/skill.ts +0 -136
- package/src/snapshot/index.ts +0 -236
- package/src/storage/storage.ts +0 -227
- package/src/tool/apply_patch.ts +0 -277
- package/src/tool/apply_patch.txt +0 -1
- package/src/tool/bash.ts +0 -258
- package/src/tool/bash.txt +0 -115
- package/src/tool/batch.ts +0 -175
- package/src/tool/batch.txt +0 -24
- package/src/tool/codesearch.ts +0 -132
- package/src/tool/codesearch.txt +0 -12
- package/src/tool/edit.ts +0 -645
- package/src/tool/edit.txt +0 -10
- package/src/tool/external-directory.ts +0 -32
- package/src/tool/glob.ts +0 -77
- package/src/tool/glob.txt +0 -6
- package/src/tool/grep.ts +0 -154
- package/src/tool/grep.txt +0 -8
- package/src/tool/invalid.ts +0 -17
- package/src/tool/ls.ts +0 -121
- package/src/tool/ls.txt +0 -1
- package/src/tool/lsp.ts +0 -96
- package/src/tool/lsp.txt +0 -19
- package/src/tool/multiedit.ts +0 -46
- package/src/tool/multiedit.txt +0 -41
- package/src/tool/plan-enter.txt +0 -14
- package/src/tool/plan-exit.txt +0 -13
- package/src/tool/plan.ts +0 -130
- package/src/tool/question.ts +0 -33
- package/src/tool/question.txt +0 -10
- package/src/tool/read.ts +0 -202
- package/src/tool/read.txt +0 -12
- package/src/tool/registry.ts +0 -158
- package/src/tool/skill.ts +0 -75
- package/src/tool/task.ts +0 -188
- package/src/tool/task.txt +0 -60
- package/src/tool/todo.ts +0 -53
- package/src/tool/todoread.txt +0 -14
- package/src/tool/todowrite.txt +0 -167
- package/src/tool/tool.ts +0 -88
- package/src/tool/truncation.ts +0 -106
- package/src/tool/webfetch.ts +0 -182
- package/src/tool/webfetch.txt +0 -13
- package/src/tool/websearch.ts +0 -150
- package/src/tool/websearch.txt +0 -14
- package/src/tool/write.ts +0 -80
- package/src/tool/write.txt +0 -8
- package/src/util/archive.ts +0 -16
- package/src/util/color.ts +0 -19
- package/src/util/context.ts +0 -25
- package/src/util/defer.ts +0 -12
- package/src/util/eventloop.ts +0 -20
- package/src/util/filesystem.ts +0 -93
- package/src/util/fn.ts +0 -11
- package/src/util/format.ts +0 -20
- package/src/util/iife.ts +0 -3
- package/src/util/keybind.ts +0 -103
- package/src/util/lazy.ts +0 -18
- package/src/util/locale.ts +0 -81
- package/src/util/lock.ts +0 -98
- package/src/util/log.ts +0 -180
- package/src/util/queue.ts +0 -32
- package/src/util/rpc.ts +0 -66
- package/src/util/scrap.ts +0 -10
- package/src/util/signal.ts +0 -12
- package/src/util/timeout.ts +0 -14
- package/src/util/token.ts +0 -7
- package/src/util/wildcard.ts +0 -56
- package/src/worktree/index.ts +0 -217
- package/sst-env.d.ts +0 -9
- package/test/acp/event-subscription.test.ts +0 -436
- package/test/acp/system-prompt.test.ts +0 -262
- package/test/agent/agent.test.ts +0 -638
- package/test/bun.test.ts +0 -53
- package/test/cli/github-action.test.ts +0 -129
- package/test/cli/github-remote.test.ts +0 -80
- package/test/cli/tui/transcript.test.ts +0 -297
- package/test/config/agent-color.test.ts +0 -66
- package/test/config/config.test.ts +0 -1414
- package/test/config/fixtures/empty-frontmatter.md +0 -4
- package/test/config/fixtures/frontmatter.md +0 -28
- package/test/config/fixtures/no-frontmatter.md +0 -1
- package/test/config/markdown.test.ts +0 -192
- package/test/file/ignore.test.ts +0 -10
- package/test/file/path-traversal.test.ts +0 -198
- package/test/fixture/fixture.ts +0 -45
- package/test/fixture/lsp/fake-lsp-server.js +0 -77
- package/test/ide/ide.test.ts +0 -82
- package/test/keybind.test.ts +0 -421
- package/test/lsp/client.test.ts +0 -95
- package/test/mcp/headers.test.ts +0 -153
- package/test/mcp/oauth-browser.test.ts +0 -261
- package/test/patch/patch.test.ts +0 -348
- package/test/permission/arity.test.ts +0 -33
- package/test/permission/next.test.ts +0 -652
- package/test/permission-task.test.ts +0 -319
- package/test/plugin/codex.test.ts +0 -123
- package/test/preload.ts +0 -65
- package/test/project/project.test.ts +0 -120
- package/test/provider/amazon-bedrock.test.ts +0 -268
- package/test/provider/gitlab-duo.test.ts +0 -286
- package/test/provider/provider.test.ts +0 -2149
- package/test/provider/transform.test.ts +0 -1596
- package/test/question/question.test.ts +0 -300
- package/test/scheduler.test.ts +0 -73
- package/test/server/session-list.test.ts +0 -39
- package/test/server/session-select.test.ts +0 -78
- package/test/session/compaction.test.ts +0 -293
- package/test/session/llm.test.ts +0 -90
- package/test/session/message-v2.test.ts +0 -662
- package/test/session/retry.test.ts +0 -131
- package/test/session/revert-compact.test.ts +0 -285
- package/test/session/session.test.ts +0 -71
- package/test/skill/skill.test.ts +0 -185
- package/test/snapshot/snapshot.test.ts +0 -939
- package/test/tool/__snapshots__/tool.test.ts.snap +0 -9
- package/test/tool/apply_patch.test.ts +0 -515
- package/test/tool/bash.test.ts +0 -320
- package/test/tool/external-directory.test.ts +0 -126
- package/test/tool/fixtures/large-image.png +0 -0
- package/test/tool/fixtures/models-api.json +0 -33453
- package/test/tool/grep.test.ts +0 -109
- package/test/tool/question.test.ts +0 -105
- package/test/tool/read.test.ts +0 -332
- package/test/tool/registry.test.ts +0 -76
- package/test/tool/truncation.test.ts +0 -159
- package/test/util/filesystem.test.ts +0 -39
- package/test/util/format.test.ts +0 -59
- package/test/util/iife.test.ts +0 -36
- package/test/util/lazy.test.ts +0 -50
- package/test/util/lock.test.ts +0 -72
- package/test/util/timeout.test.ts +0 -21
- package/test/util/wildcard.test.ts +0 -75
- package/tsconfig.json +0 -16
package/src/config/config.ts
DELETED
|
@@ -1,1255 +0,0 @@
|
|
|
1
|
-
import { Log } from "../util/log"
|
|
2
|
-
import path from "path"
|
|
3
|
-
import { pathToFileURL } from "url"
|
|
4
|
-
import os from "os"
|
|
5
|
-
import z from "zod"
|
|
6
|
-
import { Filesystem } from "../util/filesystem"
|
|
7
|
-
import { ModelsDev } from "../provider/models"
|
|
8
|
-
import { mergeDeep, pipe, unique } from "remeda"
|
|
9
|
-
import { Global } from "../global"
|
|
10
|
-
import fs from "fs/promises"
|
|
11
|
-
import { lazy } from "../util/lazy"
|
|
12
|
-
import { NamedError } from "@opencode-ai/util/error"
|
|
13
|
-
import { Flag } from "../flag/flag"
|
|
14
|
-
import { Auth } from "../auth"
|
|
15
|
-
import { type ParseError as JsoncParseError, parse as parseJsonc, printParseErrorCode } from "jsonc-parser"
|
|
16
|
-
import { Instance } from "../project/instance"
|
|
17
|
-
import { LSPServer } from "../lsp/server"
|
|
18
|
-
import { BunProc } from "@/bun"
|
|
19
|
-
import { Installation } from "@/installation"
|
|
20
|
-
import { ConfigMarkdown } from "./markdown"
|
|
21
|
-
import { existsSync } from "fs"
|
|
22
|
-
import { Bus } from "@/bus"
|
|
23
|
-
|
|
24
|
-
export namespace Config {
|
|
25
|
-
const log = Log.create({ service: "config" })
|
|
26
|
-
|
|
27
|
-
// Custom merge function that concatenates array fields instead of replacing them
|
|
28
|
-
function mergeConfigConcatArrays(target: Info, source: Info): Info {
|
|
29
|
-
const merged = mergeDeep(target, source)
|
|
30
|
-
if (target.plugin && source.plugin) {
|
|
31
|
-
merged.plugin = Array.from(new Set([...target.plugin, ...source.plugin]))
|
|
32
|
-
}
|
|
33
|
-
if (target.instructions && source.instructions) {
|
|
34
|
-
merged.instructions = Array.from(new Set([...target.instructions, ...source.instructions]))
|
|
35
|
-
}
|
|
36
|
-
return merged
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const state = Instance.state(async () => {
|
|
40
|
-
const auth = await Auth.all()
|
|
41
|
-
|
|
42
|
-
// Load remote/well-known config first as the base layer (lowest precedence)
|
|
43
|
-
// This allows organizations to provide default configs that users can override
|
|
44
|
-
let result: Info = {}
|
|
45
|
-
for (const [key, value] of Object.entries(auth)) {
|
|
46
|
-
if (value.type === "wellknown") {
|
|
47
|
-
process.env[value.key] = value.token
|
|
48
|
-
log.debug("fetching remote config", { url: `${key}/.well-known/opencode` })
|
|
49
|
-
const response = await fetch(`${key}/.well-known/opencode`)
|
|
50
|
-
if (!response.ok) {
|
|
51
|
-
throw new Error(`failed to fetch remote config from ${key}: ${response.status}`)
|
|
52
|
-
}
|
|
53
|
-
const wellknown = (await response.json()) as any
|
|
54
|
-
const remoteConfig = wellknown.config ?? {}
|
|
55
|
-
// Add $schema to prevent load() from trying to write back to a non-existent file
|
|
56
|
-
if (!remoteConfig.$schema) remoteConfig.$schema = "https://opencode.ai/config.json"
|
|
57
|
-
result = mergeConfigConcatArrays(
|
|
58
|
-
result,
|
|
59
|
-
await load(JSON.stringify(remoteConfig), `${key}/.well-known/opencode`),
|
|
60
|
-
)
|
|
61
|
-
log.debug("loaded remote config from well-known", { url: key })
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Global user config overrides remote config
|
|
66
|
-
result = mergeConfigConcatArrays(result, await global())
|
|
67
|
-
|
|
68
|
-
// Custom config path overrides global
|
|
69
|
-
if (Flag.OPENCODE_CONFIG) {
|
|
70
|
-
result = mergeConfigConcatArrays(result, await loadFile(Flag.OPENCODE_CONFIG))
|
|
71
|
-
log.debug("loaded custom config", { path: Flag.OPENCODE_CONFIG })
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Project config has highest precedence (overrides global and remote)
|
|
75
|
-
for (const file of ["opencode.jsonc", "opencode.json"]) {
|
|
76
|
-
const found = await Filesystem.findUp(file, Instance.directory, Instance.worktree)
|
|
77
|
-
for (const resolved of found.toReversed()) {
|
|
78
|
-
result = mergeConfigConcatArrays(result, await loadFile(resolved))
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Inline config content has highest precedence
|
|
83
|
-
if (Flag.OPENCODE_CONFIG_CONTENT) {
|
|
84
|
-
result = mergeConfigConcatArrays(result, JSON.parse(Flag.OPENCODE_CONFIG_CONTENT))
|
|
85
|
-
log.debug("loaded custom config from OPENCODE_CONFIG_CONTENT")
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
result.agent = result.agent || {}
|
|
89
|
-
result.mode = result.mode || {}
|
|
90
|
-
result.plugin = result.plugin || []
|
|
91
|
-
|
|
92
|
-
const directories = [
|
|
93
|
-
Global.Path.config,
|
|
94
|
-
...(await Array.fromAsync(
|
|
95
|
-
Filesystem.up({
|
|
96
|
-
targets: [".opencode"],
|
|
97
|
-
start: Instance.directory,
|
|
98
|
-
stop: Instance.worktree,
|
|
99
|
-
}),
|
|
100
|
-
)),
|
|
101
|
-
...(await Array.fromAsync(
|
|
102
|
-
Filesystem.up({
|
|
103
|
-
targets: [".opencode"],
|
|
104
|
-
start: Global.Path.home,
|
|
105
|
-
stop: Global.Path.home,
|
|
106
|
-
}),
|
|
107
|
-
)),
|
|
108
|
-
]
|
|
109
|
-
|
|
110
|
-
if (Flag.OPENCODE_CONFIG_DIR) {
|
|
111
|
-
directories.push(Flag.OPENCODE_CONFIG_DIR)
|
|
112
|
-
log.debug("loading config from OPENCODE_CONFIG_DIR", { path: Flag.OPENCODE_CONFIG_DIR })
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
for (const dir of unique(directories)) {
|
|
116
|
-
if (dir.endsWith(".opencode") || dir === Flag.OPENCODE_CONFIG_DIR) {
|
|
117
|
-
for (const file of ["opencode.jsonc", "opencode.json"]) {
|
|
118
|
-
log.debug(`loading config from ${path.join(dir, file)}`)
|
|
119
|
-
result = mergeConfigConcatArrays(result, await loadFile(path.join(dir, file)))
|
|
120
|
-
// to satisfy the type checker
|
|
121
|
-
result.agent ??= {}
|
|
122
|
-
result.mode ??= {}
|
|
123
|
-
result.plugin ??= []
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const exists = existsSync(path.join(dir, "node_modules"))
|
|
128
|
-
const installing = installDependencies(dir)
|
|
129
|
-
if (!exists) await installing
|
|
130
|
-
|
|
131
|
-
result.command = mergeDeep(result.command ?? {}, await loadCommand(dir))
|
|
132
|
-
result.agent = mergeDeep(result.agent, await loadAgent(dir))
|
|
133
|
-
result.agent = mergeDeep(result.agent, await loadMode(dir))
|
|
134
|
-
result.plugin.push(...(await loadPlugin(dir)))
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// Migrate deprecated mode field to agent field
|
|
138
|
-
for (const [name, mode] of Object.entries(result.mode)) {
|
|
139
|
-
result.agent = mergeDeep(result.agent ?? {}, {
|
|
140
|
-
[name]: {
|
|
141
|
-
...mode,
|
|
142
|
-
mode: "primary" as const,
|
|
143
|
-
},
|
|
144
|
-
})
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (Flag.OPENCODE_PERMISSION) {
|
|
148
|
-
result.permission = mergeDeep(result.permission ?? {}, JSON.parse(Flag.OPENCODE_PERMISSION))
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// Backwards compatibility: legacy top-level `tools` config
|
|
152
|
-
if (result.tools) {
|
|
153
|
-
const perms: Record<string, Config.PermissionAction> = {}
|
|
154
|
-
for (const [tool, enabled] of Object.entries(result.tools)) {
|
|
155
|
-
const action: Config.PermissionAction = enabled ? "allow" : "deny"
|
|
156
|
-
if (tool === "write" || tool === "edit" || tool === "patch" || tool === "multiedit") {
|
|
157
|
-
perms.edit = action
|
|
158
|
-
continue
|
|
159
|
-
}
|
|
160
|
-
perms[tool] = action
|
|
161
|
-
}
|
|
162
|
-
result.permission = mergeDeep(perms, result.permission ?? {})
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (!result.username) result.username = os.userInfo().username
|
|
166
|
-
|
|
167
|
-
// Handle migration from autoshare to share field
|
|
168
|
-
if (result.autoshare === true && !result.share) {
|
|
169
|
-
result.share = "auto"
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (!result.keybinds) result.keybinds = Info.shape.keybinds.parse({})
|
|
173
|
-
|
|
174
|
-
// Apply flag overrides for compaction settings
|
|
175
|
-
if (Flag.OPENCODE_DISABLE_AUTOCOMPACT) {
|
|
176
|
-
result.compaction = { ...result.compaction, auto: false }
|
|
177
|
-
}
|
|
178
|
-
if (Flag.OPENCODE_DISABLE_PRUNE) {
|
|
179
|
-
result.compaction = { ...result.compaction, prune: false }
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
result.plugin = deduplicatePlugins(result.plugin ?? [])
|
|
183
|
-
|
|
184
|
-
return {
|
|
185
|
-
config: result,
|
|
186
|
-
directories,
|
|
187
|
-
}
|
|
188
|
-
})
|
|
189
|
-
|
|
190
|
-
export async function installDependencies(dir: string) {
|
|
191
|
-
const pkg = path.join(dir, "package.json")
|
|
192
|
-
|
|
193
|
-
if (!(await Bun.file(pkg).exists())) {
|
|
194
|
-
await Bun.write(pkg, "{}")
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const gitignore = path.join(dir, ".gitignore")
|
|
198
|
-
const hasGitIgnore = await Bun.file(gitignore).exists()
|
|
199
|
-
if (!hasGitIgnore) await Bun.write(gitignore, ["node_modules", "package.json", "bun.lock", ".gitignore"].join("\n"))
|
|
200
|
-
|
|
201
|
-
await BunProc.run(
|
|
202
|
-
["add", "@opencode-ai/plugin@" + (Installation.isLocal() ? "latest" : Installation.VERSION), "--exact"],
|
|
203
|
-
{
|
|
204
|
-
cwd: dir,
|
|
205
|
-
},
|
|
206
|
-
).catch(() => {})
|
|
207
|
-
|
|
208
|
-
// Install any additional dependencies defined in the package.json
|
|
209
|
-
// This allows local plugins and custom tools to use external packages
|
|
210
|
-
await BunProc.run(["install"], { cwd: dir }).catch(() => {})
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
function rel(item: string, patterns: string[]) {
|
|
214
|
-
for (const pattern of patterns) {
|
|
215
|
-
const index = item.indexOf(pattern)
|
|
216
|
-
if (index === -1) continue
|
|
217
|
-
return item.slice(index + pattern.length)
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
function trim(file: string) {
|
|
222
|
-
const ext = path.extname(file)
|
|
223
|
-
return ext.length ? file.slice(0, -ext.length) : file
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const COMMAND_GLOB = new Bun.Glob("{command,commands}/**/*.md")
|
|
227
|
-
async function loadCommand(dir: string) {
|
|
228
|
-
const result: Record<string, Command> = {}
|
|
229
|
-
for await (const item of COMMAND_GLOB.scan({
|
|
230
|
-
absolute: true,
|
|
231
|
-
followSymlinks: true,
|
|
232
|
-
dot: true,
|
|
233
|
-
cwd: dir,
|
|
234
|
-
})) {
|
|
235
|
-
const md = await ConfigMarkdown.parse(item).catch(async (err) => {
|
|
236
|
-
const message = ConfigMarkdown.FrontmatterError.isInstance(err)
|
|
237
|
-
? err.data.message
|
|
238
|
-
: `Failed to parse command ${item}`
|
|
239
|
-
const { Session } = await import("@/session")
|
|
240
|
-
Bus.publish(Session.Event.Error, { error: new NamedError.Unknown({ message }).toObject() })
|
|
241
|
-
log.error("failed to load command", { command: item, err })
|
|
242
|
-
return undefined
|
|
243
|
-
})
|
|
244
|
-
if (!md) continue
|
|
245
|
-
|
|
246
|
-
const patterns = ["/.opencode/command/", "/.opencode/commands/", "/command/", "/commands/"]
|
|
247
|
-
const file = rel(item, patterns) ?? path.basename(item)
|
|
248
|
-
const name = trim(file)
|
|
249
|
-
|
|
250
|
-
const config = {
|
|
251
|
-
name,
|
|
252
|
-
...md.data,
|
|
253
|
-
template: md.content.trim(),
|
|
254
|
-
}
|
|
255
|
-
const parsed = Command.safeParse(config)
|
|
256
|
-
if (parsed.success) {
|
|
257
|
-
result[config.name] = parsed.data
|
|
258
|
-
continue
|
|
259
|
-
}
|
|
260
|
-
throw new InvalidError({ path: item, issues: parsed.error.issues }, { cause: parsed.error })
|
|
261
|
-
}
|
|
262
|
-
return result
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
const AGENT_GLOB = new Bun.Glob("{agent,agents}/**/*.md")
|
|
266
|
-
async function loadAgent(dir: string) {
|
|
267
|
-
const result: Record<string, Agent> = {}
|
|
268
|
-
|
|
269
|
-
for await (const item of AGENT_GLOB.scan({
|
|
270
|
-
absolute: true,
|
|
271
|
-
followSymlinks: true,
|
|
272
|
-
dot: true,
|
|
273
|
-
cwd: dir,
|
|
274
|
-
})) {
|
|
275
|
-
const md = await ConfigMarkdown.parse(item).catch(async (err) => {
|
|
276
|
-
const message = ConfigMarkdown.FrontmatterError.isInstance(err)
|
|
277
|
-
? err.data.message
|
|
278
|
-
: `Failed to parse agent ${item}`
|
|
279
|
-
const { Session } = await import("@/session")
|
|
280
|
-
Bus.publish(Session.Event.Error, { error: new NamedError.Unknown({ message }).toObject() })
|
|
281
|
-
log.error("failed to load agent", { agent: item, err })
|
|
282
|
-
return undefined
|
|
283
|
-
})
|
|
284
|
-
if (!md) continue
|
|
285
|
-
|
|
286
|
-
const patterns = ["/.opencode/agent/", "/.opencode/agents/", "/agent/", "/agents/"]
|
|
287
|
-
const file = rel(item, patterns) ?? path.basename(item)
|
|
288
|
-
const agentName = trim(file)
|
|
289
|
-
|
|
290
|
-
const config = {
|
|
291
|
-
name: agentName,
|
|
292
|
-
...md.data,
|
|
293
|
-
prompt: md.content.trim(),
|
|
294
|
-
}
|
|
295
|
-
const parsed = Agent.safeParse(config)
|
|
296
|
-
if (parsed.success) {
|
|
297
|
-
result[config.name] = parsed.data
|
|
298
|
-
continue
|
|
299
|
-
}
|
|
300
|
-
throw new InvalidError({ path: item, issues: parsed.error.issues }, { cause: parsed.error })
|
|
301
|
-
}
|
|
302
|
-
return result
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
const MODE_GLOB = new Bun.Glob("{mode,modes}/*.md")
|
|
306
|
-
async function loadMode(dir: string) {
|
|
307
|
-
const result: Record<string, Agent> = {}
|
|
308
|
-
for await (const item of MODE_GLOB.scan({
|
|
309
|
-
absolute: true,
|
|
310
|
-
followSymlinks: true,
|
|
311
|
-
dot: true,
|
|
312
|
-
cwd: dir,
|
|
313
|
-
})) {
|
|
314
|
-
const md = await ConfigMarkdown.parse(item).catch(async (err) => {
|
|
315
|
-
const message = ConfigMarkdown.FrontmatterError.isInstance(err)
|
|
316
|
-
? err.data.message
|
|
317
|
-
: `Failed to parse mode ${item}`
|
|
318
|
-
const { Session } = await import("@/session")
|
|
319
|
-
Bus.publish(Session.Event.Error, { error: new NamedError.Unknown({ message }).toObject() })
|
|
320
|
-
log.error("failed to load mode", { mode: item, err })
|
|
321
|
-
return undefined
|
|
322
|
-
})
|
|
323
|
-
if (!md) continue
|
|
324
|
-
|
|
325
|
-
const config = {
|
|
326
|
-
name: path.basename(item, ".md"),
|
|
327
|
-
...md.data,
|
|
328
|
-
prompt: md.content.trim(),
|
|
329
|
-
}
|
|
330
|
-
const parsed = Agent.safeParse(config)
|
|
331
|
-
if (parsed.success) {
|
|
332
|
-
result[config.name] = {
|
|
333
|
-
...parsed.data,
|
|
334
|
-
mode: "primary" as const,
|
|
335
|
-
}
|
|
336
|
-
continue
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
return result
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
const PLUGIN_GLOB = new Bun.Glob("{plugin,plugins}/*.{ts,js}")
|
|
343
|
-
async function loadPlugin(dir: string) {
|
|
344
|
-
const plugins: string[] = []
|
|
345
|
-
|
|
346
|
-
for await (const item of PLUGIN_GLOB.scan({
|
|
347
|
-
absolute: true,
|
|
348
|
-
followSymlinks: true,
|
|
349
|
-
dot: true,
|
|
350
|
-
cwd: dir,
|
|
351
|
-
})) {
|
|
352
|
-
plugins.push(pathToFileURL(item).href)
|
|
353
|
-
}
|
|
354
|
-
return plugins
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* Extracts a canonical plugin name from a plugin specifier.
|
|
359
|
-
* - For file:// URLs: extracts filename without extension
|
|
360
|
-
* - For npm packages: extracts package name without version
|
|
361
|
-
*
|
|
362
|
-
* @example
|
|
363
|
-
* getPluginName("file:///path/to/plugin/foo.js") // "foo"
|
|
364
|
-
* getPluginName("oh-my-opencode@2.4.3") // "oh-my-opencode"
|
|
365
|
-
* getPluginName("@scope/pkg@1.0.0") // "@scope/pkg"
|
|
366
|
-
*/
|
|
367
|
-
export function getPluginName(plugin: string): string {
|
|
368
|
-
if (plugin.startsWith("file://")) {
|
|
369
|
-
return path.parse(new URL(plugin).pathname).name
|
|
370
|
-
}
|
|
371
|
-
const lastAt = plugin.lastIndexOf("@")
|
|
372
|
-
if (lastAt > 0) {
|
|
373
|
-
return plugin.substring(0, lastAt)
|
|
374
|
-
}
|
|
375
|
-
return plugin
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* Deduplicates plugins by name, with later entries (higher priority) winning.
|
|
380
|
-
* Priority order (highest to lowest):
|
|
381
|
-
* 1. Local plugin/ directory
|
|
382
|
-
* 2. Local opencode.json
|
|
383
|
-
* 3. Global plugin/ directory
|
|
384
|
-
* 4. Global opencode.json
|
|
385
|
-
*
|
|
386
|
-
* Since plugins are added in low-to-high priority order,
|
|
387
|
-
* we reverse, deduplicate (keeping first occurrence), then restore order.
|
|
388
|
-
*/
|
|
389
|
-
export function deduplicatePlugins(plugins: string[]): string[] {
|
|
390
|
-
// seenNames: canonical plugin names for duplicate detection
|
|
391
|
-
// e.g., "oh-my-opencode", "@scope/pkg"
|
|
392
|
-
const seenNames = new Set<string>()
|
|
393
|
-
|
|
394
|
-
// uniqueSpecifiers: full plugin specifiers to return
|
|
395
|
-
// e.g., "oh-my-opencode@2.4.3", "file:///path/to/plugin.js"
|
|
396
|
-
const uniqueSpecifiers: string[] = []
|
|
397
|
-
|
|
398
|
-
for (const specifier of plugins.toReversed()) {
|
|
399
|
-
const name = getPluginName(specifier)
|
|
400
|
-
if (!seenNames.has(name)) {
|
|
401
|
-
seenNames.add(name)
|
|
402
|
-
uniqueSpecifiers.push(specifier)
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
return uniqueSpecifiers.toReversed()
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
export const McpLocal = z
|
|
410
|
-
.object({
|
|
411
|
-
type: z.literal("local").describe("Type of MCP server connection"),
|
|
412
|
-
command: z.string().array().describe("Command and arguments to run the MCP server"),
|
|
413
|
-
environment: z
|
|
414
|
-
.record(z.string(), z.string())
|
|
415
|
-
.optional()
|
|
416
|
-
.describe("Environment variables to set when running the MCP server"),
|
|
417
|
-
enabled: z.boolean().optional().describe("Enable or disable the MCP server on startup"),
|
|
418
|
-
timeout: z
|
|
419
|
-
.number()
|
|
420
|
-
.int()
|
|
421
|
-
.positive()
|
|
422
|
-
.optional()
|
|
423
|
-
.describe("Timeout in ms for MCP server requests. Defaults to 5000 (5 seconds) if not specified."),
|
|
424
|
-
})
|
|
425
|
-
.strict()
|
|
426
|
-
.meta({
|
|
427
|
-
ref: "McpLocalConfig",
|
|
428
|
-
})
|
|
429
|
-
|
|
430
|
-
export const McpOAuth = z
|
|
431
|
-
.object({
|
|
432
|
-
clientId: z
|
|
433
|
-
.string()
|
|
434
|
-
.optional()
|
|
435
|
-
.describe("OAuth client ID. If not provided, dynamic client registration (RFC 7591) will be attempted."),
|
|
436
|
-
clientSecret: z.string().optional().describe("OAuth client secret (if required by the authorization server)"),
|
|
437
|
-
scope: z.string().optional().describe("OAuth scopes to request during authorization"),
|
|
438
|
-
})
|
|
439
|
-
.strict()
|
|
440
|
-
.meta({
|
|
441
|
-
ref: "McpOAuthConfig",
|
|
442
|
-
})
|
|
443
|
-
export type McpOAuth = z.infer<typeof McpOAuth>
|
|
444
|
-
|
|
445
|
-
export const McpRemote = z
|
|
446
|
-
.object({
|
|
447
|
-
type: z.literal("remote").describe("Type of MCP server connection"),
|
|
448
|
-
url: z.string().describe("URL of the remote MCP server"),
|
|
449
|
-
enabled: z.boolean().optional().describe("Enable or disable the MCP server on startup"),
|
|
450
|
-
headers: z.record(z.string(), z.string()).optional().describe("Headers to send with the request"),
|
|
451
|
-
oauth: z
|
|
452
|
-
.union([McpOAuth, z.literal(false)])
|
|
453
|
-
.optional()
|
|
454
|
-
.describe(
|
|
455
|
-
"OAuth authentication configuration for the MCP server. Set to false to disable OAuth auto-detection.",
|
|
456
|
-
),
|
|
457
|
-
timeout: z
|
|
458
|
-
.number()
|
|
459
|
-
.int()
|
|
460
|
-
.positive()
|
|
461
|
-
.optional()
|
|
462
|
-
.describe("Timeout in ms for MCP server requests. Defaults to 5000 (5 seconds) if not specified."),
|
|
463
|
-
})
|
|
464
|
-
.strict()
|
|
465
|
-
.meta({
|
|
466
|
-
ref: "McpRemoteConfig",
|
|
467
|
-
})
|
|
468
|
-
|
|
469
|
-
export const Mcp = z.discriminatedUnion("type", [McpLocal, McpRemote])
|
|
470
|
-
export type Mcp = z.infer<typeof Mcp>
|
|
471
|
-
|
|
472
|
-
export const PermissionAction = z.enum(["ask", "allow", "deny"]).meta({
|
|
473
|
-
ref: "PermissionActionConfig",
|
|
474
|
-
})
|
|
475
|
-
export type PermissionAction = z.infer<typeof PermissionAction>
|
|
476
|
-
|
|
477
|
-
export const PermissionObject = z.record(z.string(), PermissionAction).meta({
|
|
478
|
-
ref: "PermissionObjectConfig",
|
|
479
|
-
})
|
|
480
|
-
export type PermissionObject = z.infer<typeof PermissionObject>
|
|
481
|
-
|
|
482
|
-
export const PermissionRule = z.union([PermissionAction, PermissionObject]).meta({
|
|
483
|
-
ref: "PermissionRuleConfig",
|
|
484
|
-
})
|
|
485
|
-
export type PermissionRule = z.infer<typeof PermissionRule>
|
|
486
|
-
|
|
487
|
-
// Capture original key order before zod reorders, then rebuild in original order
|
|
488
|
-
const permissionPreprocess = (val: unknown) => {
|
|
489
|
-
if (typeof val === "object" && val !== null && !Array.isArray(val)) {
|
|
490
|
-
return { __originalKeys: Object.keys(val), ...val }
|
|
491
|
-
}
|
|
492
|
-
return val
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
const permissionTransform = (x: unknown): Record<string, PermissionRule> => {
|
|
496
|
-
if (typeof x === "string") return { "*": x as PermissionAction }
|
|
497
|
-
const obj = x as { __originalKeys?: string[] } & Record<string, unknown>
|
|
498
|
-
const { __originalKeys, ...rest } = obj
|
|
499
|
-
if (!__originalKeys) return rest as Record<string, PermissionRule>
|
|
500
|
-
const result: Record<string, PermissionRule> = {}
|
|
501
|
-
for (const key of __originalKeys) {
|
|
502
|
-
if (key in rest) result[key] = rest[key] as PermissionRule
|
|
503
|
-
}
|
|
504
|
-
return result
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
export const Permission = z
|
|
508
|
-
.preprocess(
|
|
509
|
-
permissionPreprocess,
|
|
510
|
-
z
|
|
511
|
-
.object({
|
|
512
|
-
__originalKeys: z.string().array().optional(),
|
|
513
|
-
read: PermissionRule.optional(),
|
|
514
|
-
edit: PermissionRule.optional(),
|
|
515
|
-
glob: PermissionRule.optional(),
|
|
516
|
-
grep: PermissionRule.optional(),
|
|
517
|
-
list: PermissionRule.optional(),
|
|
518
|
-
bash: PermissionRule.optional(),
|
|
519
|
-
task: PermissionRule.optional(),
|
|
520
|
-
external_directory: PermissionRule.optional(),
|
|
521
|
-
todowrite: PermissionAction.optional(),
|
|
522
|
-
todoread: PermissionAction.optional(),
|
|
523
|
-
question: PermissionAction.optional(),
|
|
524
|
-
webfetch: PermissionAction.optional(),
|
|
525
|
-
websearch: PermissionAction.optional(),
|
|
526
|
-
codesearch: PermissionAction.optional(),
|
|
527
|
-
lsp: PermissionRule.optional(),
|
|
528
|
-
doom_loop: PermissionAction.optional(),
|
|
529
|
-
})
|
|
530
|
-
.catchall(PermissionRule)
|
|
531
|
-
.or(PermissionAction),
|
|
532
|
-
)
|
|
533
|
-
.transform(permissionTransform)
|
|
534
|
-
.meta({
|
|
535
|
-
ref: "PermissionConfig",
|
|
536
|
-
})
|
|
537
|
-
export type Permission = z.infer<typeof Permission>
|
|
538
|
-
|
|
539
|
-
export const Command = z.object({
|
|
540
|
-
template: z.string(),
|
|
541
|
-
description: z.string().optional(),
|
|
542
|
-
agent: z.string().optional(),
|
|
543
|
-
model: z.string().optional(),
|
|
544
|
-
subtask: z.boolean().optional(),
|
|
545
|
-
})
|
|
546
|
-
export type Command = z.infer<typeof Command>
|
|
547
|
-
|
|
548
|
-
export const Agent = z
|
|
549
|
-
.object({
|
|
550
|
-
model: z.string().optional(),
|
|
551
|
-
temperature: z.number().optional(),
|
|
552
|
-
top_p: z.number().optional(),
|
|
553
|
-
prompt: z.string().optional(),
|
|
554
|
-
tools: z.record(z.string(), z.boolean()).optional().describe("@deprecated Use 'permission' field instead"),
|
|
555
|
-
disable: z.boolean().optional(),
|
|
556
|
-
description: z.string().optional().describe("Description of when to use the agent"),
|
|
557
|
-
mode: z.enum(["subagent", "primary", "all"]).optional(),
|
|
558
|
-
hidden: z
|
|
559
|
-
.boolean()
|
|
560
|
-
.optional()
|
|
561
|
-
.describe("Hide this subagent from the @ autocomplete menu (default: false, only applies to mode: subagent)"),
|
|
562
|
-
options: z.record(z.string(), z.any()).optional(),
|
|
563
|
-
color: z
|
|
564
|
-
.string()
|
|
565
|
-
.regex(/^#[0-9a-fA-F]{6}$/, "Invalid hex color format")
|
|
566
|
-
.optional()
|
|
567
|
-
.describe("Hex color code for the agent (e.g., #FF5733)"),
|
|
568
|
-
steps: z
|
|
569
|
-
.number()
|
|
570
|
-
.int()
|
|
571
|
-
.positive()
|
|
572
|
-
.optional()
|
|
573
|
-
.describe("Maximum number of agentic iterations before forcing text-only response"),
|
|
574
|
-
maxSteps: z.number().int().positive().optional().describe("@deprecated Use 'steps' field instead."),
|
|
575
|
-
permission: Permission.optional(),
|
|
576
|
-
})
|
|
577
|
-
.catchall(z.any())
|
|
578
|
-
.transform((agent, ctx) => {
|
|
579
|
-
const knownKeys = new Set([
|
|
580
|
-
"name",
|
|
581
|
-
"model",
|
|
582
|
-
"prompt",
|
|
583
|
-
"description",
|
|
584
|
-
"temperature",
|
|
585
|
-
"top_p",
|
|
586
|
-
"mode",
|
|
587
|
-
"hidden",
|
|
588
|
-
"color",
|
|
589
|
-
"steps",
|
|
590
|
-
"maxSteps",
|
|
591
|
-
"options",
|
|
592
|
-
"permission",
|
|
593
|
-
"disable",
|
|
594
|
-
"tools",
|
|
595
|
-
])
|
|
596
|
-
|
|
597
|
-
// Extract unknown properties into options
|
|
598
|
-
const options: Record<string, unknown> = { ...agent.options }
|
|
599
|
-
for (const [key, value] of Object.entries(agent)) {
|
|
600
|
-
if (!knownKeys.has(key)) options[key] = value
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
// Convert legacy tools config to permissions
|
|
604
|
-
const permission: Permission = {}
|
|
605
|
-
for (const [tool, enabled] of Object.entries(agent.tools ?? {})) {
|
|
606
|
-
const action = enabled ? "allow" : "deny"
|
|
607
|
-
// write, edit, patch, multiedit all map to edit permission
|
|
608
|
-
if (tool === "write" || tool === "edit" || tool === "patch" || tool === "multiedit") {
|
|
609
|
-
permission.edit = action
|
|
610
|
-
} else {
|
|
611
|
-
permission[tool] = action
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
Object.assign(permission, agent.permission)
|
|
615
|
-
|
|
616
|
-
// Convert legacy maxSteps to steps
|
|
617
|
-
const steps = agent.steps ?? agent.maxSteps
|
|
618
|
-
|
|
619
|
-
return { ...agent, options, permission, steps } as typeof agent & {
|
|
620
|
-
options?: Record<string, unknown>
|
|
621
|
-
permission?: Permission
|
|
622
|
-
steps?: number
|
|
623
|
-
}
|
|
624
|
-
})
|
|
625
|
-
.meta({
|
|
626
|
-
ref: "AgentConfig",
|
|
627
|
-
})
|
|
628
|
-
export type Agent = z.infer<typeof Agent>
|
|
629
|
-
|
|
630
|
-
export const Keybinds = z
|
|
631
|
-
.object({
|
|
632
|
-
leader: z.string().optional().default("ctrl+x").describe("Leader key for keybind combinations"),
|
|
633
|
-
app_exit: z.string().optional().default("ctrl+c,ctrl+d,<leader>q").describe("Exit the application"),
|
|
634
|
-
editor_open: z.string().optional().default("<leader>e").describe("Open external editor"),
|
|
635
|
-
theme_list: z.string().optional().default("<leader>t").describe("List available themes"),
|
|
636
|
-
sidebar_toggle: z.string().optional().default("<leader>b").describe("Toggle sidebar"),
|
|
637
|
-
scrollbar_toggle: z.string().optional().default("none").describe("Toggle session scrollbar"),
|
|
638
|
-
username_toggle: z.string().optional().default("none").describe("Toggle username visibility"),
|
|
639
|
-
status_view: z.string().optional().default("<leader>s").describe("View status"),
|
|
640
|
-
session_export: z.string().optional().default("<leader>x").describe("Export session to editor"),
|
|
641
|
-
session_new: z.string().optional().default("<leader>n").describe("Create a new session"),
|
|
642
|
-
session_list: z.string().optional().default("<leader>l").describe("List all sessions"),
|
|
643
|
-
session_timeline: z.string().optional().default("<leader>g").describe("Show session timeline"),
|
|
644
|
-
session_fork: z.string().optional().default("none").describe("Fork session from message"),
|
|
645
|
-
session_rename: z.string().optional().default("ctrl+r").describe("Rename session"),
|
|
646
|
-
session_delete: z.string().optional().default("ctrl+d").describe("Delete session"),
|
|
647
|
-
stash_delete: z.string().optional().default("ctrl+d").describe("Delete stash entry"),
|
|
648
|
-
model_provider_list: z.string().optional().default("ctrl+a").describe("Open provider list from model dialog"),
|
|
649
|
-
model_favorite_toggle: z.string().optional().default("ctrl+f").describe("Toggle model favorite status"),
|
|
650
|
-
session_share: z.string().optional().default("none").describe("Share current session"),
|
|
651
|
-
session_unshare: z.string().optional().default("none").describe("Unshare current session"),
|
|
652
|
-
session_interrupt: z.string().optional().default("escape").describe("Interrupt current session"),
|
|
653
|
-
session_compact: z.string().optional().default("<leader>c").describe("Compact the session"),
|
|
654
|
-
messages_page_up: z.string().optional().default("pageup,ctrl+alt+b").describe("Scroll messages up by one page"),
|
|
655
|
-
messages_page_down: z
|
|
656
|
-
.string()
|
|
657
|
-
.optional()
|
|
658
|
-
.default("pagedown,ctrl+alt+f")
|
|
659
|
-
.describe("Scroll messages down by one page"),
|
|
660
|
-
messages_line_up: z.string().optional().default("ctrl+alt+y").describe("Scroll messages up by one line"),
|
|
661
|
-
messages_line_down: z.string().optional().default("ctrl+alt+e").describe("Scroll messages down by one line"),
|
|
662
|
-
messages_half_page_up: z.string().optional().default("ctrl+alt+u").describe("Scroll messages up by half page"),
|
|
663
|
-
messages_half_page_down: z
|
|
664
|
-
.string()
|
|
665
|
-
.optional()
|
|
666
|
-
.default("ctrl+alt+d")
|
|
667
|
-
.describe("Scroll messages down by half page"),
|
|
668
|
-
messages_first: z.string().optional().default("ctrl+g,home").describe("Navigate to first message"),
|
|
669
|
-
messages_last: z.string().optional().default("ctrl+alt+g,end").describe("Navigate to last message"),
|
|
670
|
-
messages_next: z.string().optional().default("none").describe("Navigate to next message"),
|
|
671
|
-
messages_previous: z.string().optional().default("none").describe("Navigate to previous message"),
|
|
672
|
-
messages_last_user: z.string().optional().default("none").describe("Navigate to last user message"),
|
|
673
|
-
messages_copy: z.string().optional().default("<leader>y").describe("Copy message"),
|
|
674
|
-
messages_undo: z.string().optional().default("<leader>u").describe("Undo message"),
|
|
675
|
-
messages_redo: z.string().optional().default("<leader>r").describe("Redo message"),
|
|
676
|
-
messages_toggle_conceal: z
|
|
677
|
-
.string()
|
|
678
|
-
.optional()
|
|
679
|
-
.default("<leader>h")
|
|
680
|
-
.describe("Toggle code block concealment in messages"),
|
|
681
|
-
tool_details: z.string().optional().default("none").describe("Toggle tool details visibility"),
|
|
682
|
-
model_list: z.string().optional().default("<leader>m").describe("List available models"),
|
|
683
|
-
model_cycle_recent: z.string().optional().default("f2").describe("Next recently used model"),
|
|
684
|
-
model_cycle_recent_reverse: z.string().optional().default("shift+f2").describe("Previous recently used model"),
|
|
685
|
-
model_cycle_favorite: z.string().optional().default("none").describe("Next favorite model"),
|
|
686
|
-
model_cycle_favorite_reverse: z.string().optional().default("none").describe("Previous favorite model"),
|
|
687
|
-
command_list: z.string().optional().default("ctrl+p").describe("List available commands"),
|
|
688
|
-
agent_list: z.string().optional().default("<leader>a").describe("List agents"),
|
|
689
|
-
agent_cycle: z.string().optional().default("tab").describe("Next agent"),
|
|
690
|
-
agent_cycle_reverse: z.string().optional().default("shift+tab").describe("Previous agent"),
|
|
691
|
-
variant_cycle: z.string().optional().default("ctrl+t").describe("Cycle model variants"),
|
|
692
|
-
input_clear: z.string().optional().default("ctrl+c").describe("Clear input field"),
|
|
693
|
-
input_paste: z.string().optional().default("ctrl+v").describe("Paste from clipboard"),
|
|
694
|
-
input_submit: z.string().optional().default("return").describe("Submit input"),
|
|
695
|
-
input_newline: z
|
|
696
|
-
.string()
|
|
697
|
-
.optional()
|
|
698
|
-
.default("shift+return,ctrl+return,alt+return,ctrl+j")
|
|
699
|
-
.describe("Insert newline in input"),
|
|
700
|
-
input_move_left: z.string().optional().default("left,ctrl+b").describe("Move cursor left in input"),
|
|
701
|
-
input_move_right: z.string().optional().default("right,ctrl+f").describe("Move cursor right in input"),
|
|
702
|
-
input_move_up: z.string().optional().default("up").describe("Move cursor up in input"),
|
|
703
|
-
input_move_down: z.string().optional().default("down").describe("Move cursor down in input"),
|
|
704
|
-
input_select_left: z.string().optional().default("shift+left").describe("Select left in input"),
|
|
705
|
-
input_select_right: z.string().optional().default("shift+right").describe("Select right in input"),
|
|
706
|
-
input_select_up: z.string().optional().default("shift+up").describe("Select up in input"),
|
|
707
|
-
input_select_down: z.string().optional().default("shift+down").describe("Select down in input"),
|
|
708
|
-
input_line_home: z.string().optional().default("ctrl+a").describe("Move to start of line in input"),
|
|
709
|
-
input_line_end: z.string().optional().default("ctrl+e").describe("Move to end of line in input"),
|
|
710
|
-
input_select_line_home: z
|
|
711
|
-
.string()
|
|
712
|
-
.optional()
|
|
713
|
-
.default("ctrl+shift+a")
|
|
714
|
-
.describe("Select to start of line in input"),
|
|
715
|
-
input_select_line_end: z.string().optional().default("ctrl+shift+e").describe("Select to end of line in input"),
|
|
716
|
-
input_visual_line_home: z.string().optional().default("alt+a").describe("Move to start of visual line in input"),
|
|
717
|
-
input_visual_line_end: z.string().optional().default("alt+e").describe("Move to end of visual line in input"),
|
|
718
|
-
input_select_visual_line_home: z
|
|
719
|
-
.string()
|
|
720
|
-
.optional()
|
|
721
|
-
.default("alt+shift+a")
|
|
722
|
-
.describe("Select to start of visual line in input"),
|
|
723
|
-
input_select_visual_line_end: z
|
|
724
|
-
.string()
|
|
725
|
-
.optional()
|
|
726
|
-
.default("alt+shift+e")
|
|
727
|
-
.describe("Select to end of visual line in input"),
|
|
728
|
-
input_buffer_home: z.string().optional().default("home").describe("Move to start of buffer in input"),
|
|
729
|
-
input_buffer_end: z.string().optional().default("end").describe("Move to end of buffer in input"),
|
|
730
|
-
input_select_buffer_home: z
|
|
731
|
-
.string()
|
|
732
|
-
.optional()
|
|
733
|
-
.default("shift+home")
|
|
734
|
-
.describe("Select to start of buffer in input"),
|
|
735
|
-
input_select_buffer_end: z.string().optional().default("shift+end").describe("Select to end of buffer in input"),
|
|
736
|
-
input_delete_line: z.string().optional().default("ctrl+shift+d").describe("Delete line in input"),
|
|
737
|
-
input_delete_to_line_end: z.string().optional().default("ctrl+k").describe("Delete to end of line in input"),
|
|
738
|
-
input_delete_to_line_start: z.string().optional().default("ctrl+u").describe("Delete to start of line in input"),
|
|
739
|
-
input_backspace: z.string().optional().default("backspace,shift+backspace").describe("Backspace in input"),
|
|
740
|
-
input_delete: z.string().optional().default("ctrl+d,delete,shift+delete").describe("Delete character in input"),
|
|
741
|
-
input_undo: z.string().optional().default("ctrl+-,super+z").describe("Undo in input"),
|
|
742
|
-
input_redo: z.string().optional().default("ctrl+.,super+shift+z").describe("Redo in input"),
|
|
743
|
-
input_word_forward: z
|
|
744
|
-
.string()
|
|
745
|
-
.optional()
|
|
746
|
-
.default("alt+f,alt+right,ctrl+right")
|
|
747
|
-
.describe("Move word forward in input"),
|
|
748
|
-
input_word_backward: z
|
|
749
|
-
.string()
|
|
750
|
-
.optional()
|
|
751
|
-
.default("alt+b,alt+left,ctrl+left")
|
|
752
|
-
.describe("Move word backward in input"),
|
|
753
|
-
input_select_word_forward: z
|
|
754
|
-
.string()
|
|
755
|
-
.optional()
|
|
756
|
-
.default("alt+shift+f,alt+shift+right")
|
|
757
|
-
.describe("Select word forward in input"),
|
|
758
|
-
input_select_word_backward: z
|
|
759
|
-
.string()
|
|
760
|
-
.optional()
|
|
761
|
-
.default("alt+shift+b,alt+shift+left")
|
|
762
|
-
.describe("Select word backward in input"),
|
|
763
|
-
input_delete_word_forward: z
|
|
764
|
-
.string()
|
|
765
|
-
.optional()
|
|
766
|
-
.default("alt+d,alt+delete,ctrl+delete")
|
|
767
|
-
.describe("Delete word forward in input"),
|
|
768
|
-
input_delete_word_backward: z
|
|
769
|
-
.string()
|
|
770
|
-
.optional()
|
|
771
|
-
.default("ctrl+w,ctrl+backspace,alt+backspace")
|
|
772
|
-
.describe("Delete word backward in input"),
|
|
773
|
-
history_previous: z.string().optional().default("up").describe("Previous history item"),
|
|
774
|
-
history_next: z.string().optional().default("down").describe("Next history item"),
|
|
775
|
-
session_child_cycle: z.string().optional().default("<leader>right").describe("Next child session"),
|
|
776
|
-
session_child_cycle_reverse: z.string().optional().default("<leader>left").describe("Previous child session"),
|
|
777
|
-
session_parent: z.string().optional().default("<leader>up").describe("Go to parent session"),
|
|
778
|
-
terminal_suspend: z.string().optional().default("ctrl+z").describe("Suspend terminal"),
|
|
779
|
-
terminal_title_toggle: z.string().optional().default("none").describe("Toggle terminal title"),
|
|
780
|
-
tips_toggle: z.string().optional().default("<leader>h").describe("Toggle tips on home screen"),
|
|
781
|
-
})
|
|
782
|
-
.strict()
|
|
783
|
-
.meta({
|
|
784
|
-
ref: "KeybindsConfig",
|
|
785
|
-
})
|
|
786
|
-
|
|
787
|
-
export const TUI = z.object({
|
|
788
|
-
scroll_speed: z.number().min(0.001).optional().describe("TUI scroll speed"),
|
|
789
|
-
scroll_acceleration: z
|
|
790
|
-
.object({
|
|
791
|
-
enabled: z.boolean().describe("Enable scroll acceleration"),
|
|
792
|
-
})
|
|
793
|
-
.optional()
|
|
794
|
-
.describe("Scroll acceleration settings"),
|
|
795
|
-
diff_style: z
|
|
796
|
-
.enum(["auto", "stacked"])
|
|
797
|
-
.optional()
|
|
798
|
-
.describe("Control diff rendering style: 'auto' adapts to terminal width, 'stacked' always shows single column"),
|
|
799
|
-
})
|
|
800
|
-
|
|
801
|
-
export const Server = z
|
|
802
|
-
.object({
|
|
803
|
-
port: z.number().int().positive().optional().describe("Port to listen on"),
|
|
804
|
-
hostname: z.string().optional().describe("Hostname to listen on"),
|
|
805
|
-
mdns: z.boolean().optional().describe("Enable mDNS service discovery"),
|
|
806
|
-
cors: z.array(z.string()).optional().describe("Additional domains to allow for CORS"),
|
|
807
|
-
})
|
|
808
|
-
.strict()
|
|
809
|
-
.meta({
|
|
810
|
-
ref: "ServerConfig",
|
|
811
|
-
})
|
|
812
|
-
|
|
813
|
-
export const Layout = z.enum(["auto", "stretch"]).meta({
|
|
814
|
-
ref: "LayoutConfig",
|
|
815
|
-
})
|
|
816
|
-
export type Layout = z.infer<typeof Layout>
|
|
817
|
-
|
|
818
|
-
export const Provider = ModelsDev.Provider.partial()
|
|
819
|
-
.extend({
|
|
820
|
-
whitelist: z.array(z.string()).optional(),
|
|
821
|
-
blacklist: z.array(z.string()).optional(),
|
|
822
|
-
models: z
|
|
823
|
-
.record(
|
|
824
|
-
z.string(),
|
|
825
|
-
ModelsDev.Model.partial().extend({
|
|
826
|
-
variants: z
|
|
827
|
-
.record(
|
|
828
|
-
z.string(),
|
|
829
|
-
z
|
|
830
|
-
.object({
|
|
831
|
-
disabled: z.boolean().optional().describe("Disable this variant for the model"),
|
|
832
|
-
})
|
|
833
|
-
.catchall(z.any()),
|
|
834
|
-
)
|
|
835
|
-
.optional()
|
|
836
|
-
.describe("Variant-specific configuration"),
|
|
837
|
-
}),
|
|
838
|
-
)
|
|
839
|
-
.optional(),
|
|
840
|
-
options: z
|
|
841
|
-
.object({
|
|
842
|
-
apiKey: z.string().optional(),
|
|
843
|
-
baseURL: z.string().optional(),
|
|
844
|
-
enterpriseUrl: z.string().optional().describe("GitHub Enterprise URL for copilot authentication"),
|
|
845
|
-
setCacheKey: z.boolean().optional().describe("Enable promptCacheKey for this provider (default false)"),
|
|
846
|
-
timeout: z
|
|
847
|
-
.union([
|
|
848
|
-
z
|
|
849
|
-
.number()
|
|
850
|
-
.int()
|
|
851
|
-
.positive()
|
|
852
|
-
.describe(
|
|
853
|
-
"Timeout in milliseconds for requests to this provider. Default is 300000 (5 minutes). Set to false to disable timeout.",
|
|
854
|
-
),
|
|
855
|
-
z.literal(false).describe("Disable timeout for this provider entirely."),
|
|
856
|
-
])
|
|
857
|
-
.optional()
|
|
858
|
-
.describe(
|
|
859
|
-
"Timeout in milliseconds for requests to this provider. Default is 300000 (5 minutes). Set to false to disable timeout.",
|
|
860
|
-
),
|
|
861
|
-
})
|
|
862
|
-
.catchall(z.any())
|
|
863
|
-
.optional(),
|
|
864
|
-
})
|
|
865
|
-
.strict()
|
|
866
|
-
.meta({
|
|
867
|
-
ref: "ProviderConfig",
|
|
868
|
-
})
|
|
869
|
-
export type Provider = z.infer<typeof Provider>
|
|
870
|
-
|
|
871
|
-
export const Info = z
|
|
872
|
-
.object({
|
|
873
|
-
$schema: z.string().optional().describe("JSON schema reference for configuration validation"),
|
|
874
|
-
theme: z.string().optional().describe("Theme name to use for the interface"),
|
|
875
|
-
keybinds: Keybinds.optional().describe("Custom keybind configurations"),
|
|
876
|
-
logLevel: Log.Level.optional().describe("Log level"),
|
|
877
|
-
tui: TUI.optional().describe("TUI specific settings"),
|
|
878
|
-
server: Server.optional().describe("Server configuration for opencode serve and web commands"),
|
|
879
|
-
command: z
|
|
880
|
-
.record(z.string(), Command)
|
|
881
|
-
.optional()
|
|
882
|
-
.describe("Command configuration, see https://opencode.ai/docs/commands"),
|
|
883
|
-
watcher: z
|
|
884
|
-
.object({
|
|
885
|
-
ignore: z.array(z.string()).optional(),
|
|
886
|
-
})
|
|
887
|
-
.optional(),
|
|
888
|
-
plugin: z.string().array().optional(),
|
|
889
|
-
snapshot: z.boolean().optional(),
|
|
890
|
-
share: z
|
|
891
|
-
.enum(["manual", "auto", "disabled"])
|
|
892
|
-
.optional()
|
|
893
|
-
.describe(
|
|
894
|
-
"Control sharing behavior:'manual' allows manual sharing via commands, 'auto' enables automatic sharing, 'disabled' disables all sharing",
|
|
895
|
-
),
|
|
896
|
-
autoshare: z
|
|
897
|
-
.boolean()
|
|
898
|
-
.optional()
|
|
899
|
-
.describe("@deprecated Use 'share' field instead. Share newly created sessions automatically"),
|
|
900
|
-
autoupdate: z
|
|
901
|
-
.union([z.boolean(), z.literal("notify")])
|
|
902
|
-
.optional()
|
|
903
|
-
.describe(
|
|
904
|
-
"Automatically update to the latest version. Set to true to auto-update, false to disable, or 'notify' to show update notifications",
|
|
905
|
-
),
|
|
906
|
-
disabled_providers: z.array(z.string()).optional().describe("Disable providers that are loaded automatically"),
|
|
907
|
-
enabled_providers: z
|
|
908
|
-
.array(z.string())
|
|
909
|
-
.optional()
|
|
910
|
-
.describe("When set, ONLY these providers will be enabled. All other providers will be ignored"),
|
|
911
|
-
model: z.string().describe("Model to use in the format of provider/model, eg anthropic/claude-2").optional(),
|
|
912
|
-
small_model: z
|
|
913
|
-
.string()
|
|
914
|
-
.describe("Small model to use for tasks like title generation in the format of provider/model")
|
|
915
|
-
.optional(),
|
|
916
|
-
default_agent: z
|
|
917
|
-
.string()
|
|
918
|
-
.optional()
|
|
919
|
-
.describe(
|
|
920
|
-
"Default agent to use when none is specified. Must be a primary agent. Falls back to 'build' if not set or if the specified agent is invalid.",
|
|
921
|
-
),
|
|
922
|
-
username: z
|
|
923
|
-
.string()
|
|
924
|
-
.optional()
|
|
925
|
-
.describe("Custom username to display in conversations instead of system username"),
|
|
926
|
-
mode: z
|
|
927
|
-
.object({
|
|
928
|
-
build: Agent.optional(),
|
|
929
|
-
plan: Agent.optional(),
|
|
930
|
-
})
|
|
931
|
-
.catchall(Agent)
|
|
932
|
-
.optional()
|
|
933
|
-
.describe("@deprecated Use `agent` field instead."),
|
|
934
|
-
agent: z
|
|
935
|
-
.object({
|
|
936
|
-
// primary
|
|
937
|
-
plan: Agent.optional(),
|
|
938
|
-
build: Agent.optional(),
|
|
939
|
-
// subagent
|
|
940
|
-
general: Agent.optional(),
|
|
941
|
-
explore: Agent.optional(),
|
|
942
|
-
// specialized
|
|
943
|
-
title: Agent.optional(),
|
|
944
|
-
summary: Agent.optional(),
|
|
945
|
-
compaction: Agent.optional(),
|
|
946
|
-
})
|
|
947
|
-
.catchall(Agent)
|
|
948
|
-
.optional()
|
|
949
|
-
.describe("Agent configuration, see https://opencode.ai/docs/agents"),
|
|
950
|
-
provider: z
|
|
951
|
-
.record(z.string(), Provider)
|
|
952
|
-
.optional()
|
|
953
|
-
.describe("Custom provider configurations and model overrides"),
|
|
954
|
-
mcp: z
|
|
955
|
-
.record(
|
|
956
|
-
z.string(),
|
|
957
|
-
z.union([
|
|
958
|
-
Mcp,
|
|
959
|
-
z
|
|
960
|
-
.object({
|
|
961
|
-
enabled: z.boolean(),
|
|
962
|
-
})
|
|
963
|
-
.strict(),
|
|
964
|
-
]),
|
|
965
|
-
)
|
|
966
|
-
.optional()
|
|
967
|
-
.describe("MCP (Model Context Protocol) server configurations"),
|
|
968
|
-
formatter: z
|
|
969
|
-
.union([
|
|
970
|
-
z.literal(false),
|
|
971
|
-
z.record(
|
|
972
|
-
z.string(),
|
|
973
|
-
z.object({
|
|
974
|
-
disabled: z.boolean().optional(),
|
|
975
|
-
command: z.array(z.string()).optional(),
|
|
976
|
-
environment: z.record(z.string(), z.string()).optional(),
|
|
977
|
-
extensions: z.array(z.string()).optional(),
|
|
978
|
-
}),
|
|
979
|
-
),
|
|
980
|
-
])
|
|
981
|
-
.optional(),
|
|
982
|
-
lsp: z
|
|
983
|
-
.union([
|
|
984
|
-
z.literal(false),
|
|
985
|
-
z.record(
|
|
986
|
-
z.string(),
|
|
987
|
-
z.union([
|
|
988
|
-
z.object({
|
|
989
|
-
disabled: z.literal(true),
|
|
990
|
-
}),
|
|
991
|
-
z.object({
|
|
992
|
-
command: z.array(z.string()),
|
|
993
|
-
extensions: z.array(z.string()).optional(),
|
|
994
|
-
disabled: z.boolean().optional(),
|
|
995
|
-
env: z.record(z.string(), z.string()).optional(),
|
|
996
|
-
initialization: z.record(z.string(), z.any()).optional(),
|
|
997
|
-
}),
|
|
998
|
-
]),
|
|
999
|
-
),
|
|
1000
|
-
])
|
|
1001
|
-
.optional()
|
|
1002
|
-
.refine(
|
|
1003
|
-
(data) => {
|
|
1004
|
-
if (!data) return true
|
|
1005
|
-
if (typeof data === "boolean") return true
|
|
1006
|
-
const serverIds = new Set(Object.values(LSPServer).map((s) => s.id))
|
|
1007
|
-
|
|
1008
|
-
return Object.entries(data).every(([id, config]) => {
|
|
1009
|
-
if (config.disabled) return true
|
|
1010
|
-
if (serverIds.has(id)) return true
|
|
1011
|
-
return Boolean(config.extensions)
|
|
1012
|
-
})
|
|
1013
|
-
},
|
|
1014
|
-
{
|
|
1015
|
-
error: "For custom LSP servers, 'extensions' array is required.",
|
|
1016
|
-
},
|
|
1017
|
-
),
|
|
1018
|
-
instructions: z.array(z.string()).optional().describe("Additional instruction files or patterns to include"),
|
|
1019
|
-
layout: Layout.optional().describe("@deprecated Always uses stretch layout."),
|
|
1020
|
-
permission: Permission.optional(),
|
|
1021
|
-
tools: z.record(z.string(), z.boolean()).optional(),
|
|
1022
|
-
enterprise: z
|
|
1023
|
-
.object({
|
|
1024
|
-
url: z.string().optional().describe("Enterprise URL"),
|
|
1025
|
-
})
|
|
1026
|
-
.optional(),
|
|
1027
|
-
compaction: z
|
|
1028
|
-
.object({
|
|
1029
|
-
auto: z.boolean().optional().describe("Enable automatic compaction when context is full (default: true)"),
|
|
1030
|
-
prune: z.boolean().optional().describe("Enable pruning of old tool outputs (default: true)"),
|
|
1031
|
-
})
|
|
1032
|
-
.optional(),
|
|
1033
|
-
experimental: z
|
|
1034
|
-
.object({
|
|
1035
|
-
hook: z
|
|
1036
|
-
.object({
|
|
1037
|
-
file_edited: z
|
|
1038
|
-
.record(
|
|
1039
|
-
z.string(),
|
|
1040
|
-
z
|
|
1041
|
-
.object({
|
|
1042
|
-
command: z.string().array(),
|
|
1043
|
-
environment: z.record(z.string(), z.string()).optional(),
|
|
1044
|
-
})
|
|
1045
|
-
.array(),
|
|
1046
|
-
)
|
|
1047
|
-
.optional(),
|
|
1048
|
-
session_completed: z
|
|
1049
|
-
.object({
|
|
1050
|
-
command: z.string().array(),
|
|
1051
|
-
environment: z.record(z.string(), z.string()).optional(),
|
|
1052
|
-
})
|
|
1053
|
-
.array()
|
|
1054
|
-
.optional(),
|
|
1055
|
-
})
|
|
1056
|
-
.optional(),
|
|
1057
|
-
chatMaxRetries: z.number().optional().describe("Number of retries for chat completions on failure"),
|
|
1058
|
-
disable_paste_summary: z.boolean().optional(),
|
|
1059
|
-
batch_tool: z.boolean().optional().describe("Enable the batch tool"),
|
|
1060
|
-
openTelemetry: z
|
|
1061
|
-
.boolean()
|
|
1062
|
-
.optional()
|
|
1063
|
-
.describe("Enable OpenTelemetry spans for AI SDK calls (using the 'experimental_telemetry' flag)"),
|
|
1064
|
-
primary_tools: z
|
|
1065
|
-
.array(z.string())
|
|
1066
|
-
.optional()
|
|
1067
|
-
.describe("Tools that should only be available to primary agents."),
|
|
1068
|
-
continue_loop_on_deny: z.boolean().optional().describe("Continue the agent loop when a tool call is denied"),
|
|
1069
|
-
mcp_timeout: z
|
|
1070
|
-
.number()
|
|
1071
|
-
.int()
|
|
1072
|
-
.positive()
|
|
1073
|
-
.optional()
|
|
1074
|
-
.describe("Timeout in milliseconds for model context protocol (MCP) requests"),
|
|
1075
|
-
})
|
|
1076
|
-
.optional(),
|
|
1077
|
-
})
|
|
1078
|
-
.strict()
|
|
1079
|
-
.meta({
|
|
1080
|
-
ref: "Config",
|
|
1081
|
-
})
|
|
1082
|
-
|
|
1083
|
-
export type Info = z.output<typeof Info>
|
|
1084
|
-
|
|
1085
|
-
export const global = lazy(async () => {
|
|
1086
|
-
let result: Info = pipe(
|
|
1087
|
-
{},
|
|
1088
|
-
mergeDeep(await loadFile(path.join(Global.Path.config, "config.json"))),
|
|
1089
|
-
mergeDeep(await loadFile(path.join(Global.Path.config, "opencode.json"))),
|
|
1090
|
-
mergeDeep(await loadFile(path.join(Global.Path.config, "opencode.jsonc"))),
|
|
1091
|
-
)
|
|
1092
|
-
|
|
1093
|
-
await import(path.join(Global.Path.config, "config"), {
|
|
1094
|
-
with: {
|
|
1095
|
-
type: "toml",
|
|
1096
|
-
},
|
|
1097
|
-
})
|
|
1098
|
-
.then(async (mod) => {
|
|
1099
|
-
const { provider, model, ...rest } = mod.default
|
|
1100
|
-
if (provider && model) result.model = `${provider}/${model}`
|
|
1101
|
-
result["$schema"] = "https://opencode.ai/config.json"
|
|
1102
|
-
result = mergeDeep(result, rest)
|
|
1103
|
-
await Bun.write(path.join(Global.Path.config, "config.json"), JSON.stringify(result, null, 2))
|
|
1104
|
-
await fs.unlink(path.join(Global.Path.config, "config"))
|
|
1105
|
-
})
|
|
1106
|
-
.catch(() => {})
|
|
1107
|
-
|
|
1108
|
-
return result
|
|
1109
|
-
})
|
|
1110
|
-
|
|
1111
|
-
async function loadFile(filepath: string): Promise<Info> {
|
|
1112
|
-
log.info("loading", { path: filepath })
|
|
1113
|
-
let text = await Bun.file(filepath)
|
|
1114
|
-
.text()
|
|
1115
|
-
.catch((err) => {
|
|
1116
|
-
if (err.code === "ENOENT") return
|
|
1117
|
-
throw new JsonError({ path: filepath }, { cause: err })
|
|
1118
|
-
})
|
|
1119
|
-
if (!text) return {}
|
|
1120
|
-
return load(text, filepath)
|
|
1121
|
-
}
|
|
1122
|
-
|
|
1123
|
-
async function load(text: string, configFilepath: string) {
|
|
1124
|
-
const original = text
|
|
1125
|
-
text = text.replace(/\{env:([^}]+)\}/g, (_, varName) => {
|
|
1126
|
-
return process.env[varName] || ""
|
|
1127
|
-
})
|
|
1128
|
-
|
|
1129
|
-
const fileMatches = text.match(/\{file:[^}]+\}/g)
|
|
1130
|
-
if (fileMatches) {
|
|
1131
|
-
const configDir = path.dirname(configFilepath)
|
|
1132
|
-
const lines = text.split("\n")
|
|
1133
|
-
|
|
1134
|
-
for (const match of fileMatches) {
|
|
1135
|
-
const lineIndex = lines.findIndex((line) => line.includes(match))
|
|
1136
|
-
if (lineIndex !== -1 && lines[lineIndex].trim().startsWith("//")) {
|
|
1137
|
-
continue // Skip if line is commented
|
|
1138
|
-
}
|
|
1139
|
-
let filePath = match.replace(/^\{file:/, "").replace(/\}$/, "")
|
|
1140
|
-
if (filePath.startsWith("~/")) {
|
|
1141
|
-
filePath = path.join(os.homedir(), filePath.slice(2))
|
|
1142
|
-
}
|
|
1143
|
-
const resolvedPath = path.isAbsolute(filePath) ? filePath : path.resolve(configDir, filePath)
|
|
1144
|
-
const fileContent = (
|
|
1145
|
-
await Bun.file(resolvedPath)
|
|
1146
|
-
.text()
|
|
1147
|
-
.catch((error) => {
|
|
1148
|
-
const errMsg = `bad file reference: "${match}"`
|
|
1149
|
-
if (error.code === "ENOENT") {
|
|
1150
|
-
throw new InvalidError(
|
|
1151
|
-
{
|
|
1152
|
-
path: configFilepath,
|
|
1153
|
-
message: errMsg + ` ${resolvedPath} does not exist`,
|
|
1154
|
-
},
|
|
1155
|
-
{ cause: error },
|
|
1156
|
-
)
|
|
1157
|
-
}
|
|
1158
|
-
throw new InvalidError({ path: configFilepath, message: errMsg }, { cause: error })
|
|
1159
|
-
})
|
|
1160
|
-
).trim()
|
|
1161
|
-
// escape newlines/quotes, strip outer quotes
|
|
1162
|
-
text = text.replace(match, JSON.stringify(fileContent).slice(1, -1))
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
|
|
1166
|
-
const errors: JsoncParseError[] = []
|
|
1167
|
-
const data = parseJsonc(text, errors, { allowTrailingComma: true })
|
|
1168
|
-
if (errors.length) {
|
|
1169
|
-
const lines = text.split("\n")
|
|
1170
|
-
const errorDetails = errors
|
|
1171
|
-
.map((e) => {
|
|
1172
|
-
const beforeOffset = text.substring(0, e.offset).split("\n")
|
|
1173
|
-
const line = beforeOffset.length
|
|
1174
|
-
const column = beforeOffset[beforeOffset.length - 1].length + 1
|
|
1175
|
-
const problemLine = lines[line - 1]
|
|
1176
|
-
|
|
1177
|
-
const error = `${printParseErrorCode(e.error)} at line ${line}, column ${column}`
|
|
1178
|
-
if (!problemLine) return error
|
|
1179
|
-
|
|
1180
|
-
return `${error}\n Line ${line}: ${problemLine}\n${"".padStart(column + 9)}^`
|
|
1181
|
-
})
|
|
1182
|
-
.join("\n")
|
|
1183
|
-
|
|
1184
|
-
throw new JsonError({
|
|
1185
|
-
path: configFilepath,
|
|
1186
|
-
message: `\n--- JSONC Input ---\n${text}\n--- Errors ---\n${errorDetails}\n--- End ---`,
|
|
1187
|
-
})
|
|
1188
|
-
}
|
|
1189
|
-
|
|
1190
|
-
const parsed = Info.safeParse(data)
|
|
1191
|
-
if (parsed.success) {
|
|
1192
|
-
if (!parsed.data.$schema) {
|
|
1193
|
-
parsed.data.$schema = "https://opencode.ai/config.json"
|
|
1194
|
-
// Write the $schema to the original text to preserve variables like {env:VAR}
|
|
1195
|
-
const updated = original.replace(/^\s*\{/, '{\n "$schema": "https://opencode.ai/config.json",')
|
|
1196
|
-
await Bun.write(configFilepath, updated).catch(() => {})
|
|
1197
|
-
}
|
|
1198
|
-
const data = parsed.data
|
|
1199
|
-
if (data.plugin) {
|
|
1200
|
-
for (let i = 0; i < data.plugin.length; i++) {
|
|
1201
|
-
const plugin = data.plugin[i]
|
|
1202
|
-
try {
|
|
1203
|
-
data.plugin[i] = import.meta.resolve!(plugin, configFilepath)
|
|
1204
|
-
} catch (err) {}
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
return data
|
|
1208
|
-
}
|
|
1209
|
-
|
|
1210
|
-
throw new InvalidError({
|
|
1211
|
-
path: configFilepath,
|
|
1212
|
-
issues: parsed.error.issues,
|
|
1213
|
-
})
|
|
1214
|
-
}
|
|
1215
|
-
export const JsonError = NamedError.create(
|
|
1216
|
-
"ConfigJsonError",
|
|
1217
|
-
z.object({
|
|
1218
|
-
path: z.string(),
|
|
1219
|
-
message: z.string().optional(),
|
|
1220
|
-
}),
|
|
1221
|
-
)
|
|
1222
|
-
|
|
1223
|
-
export const ConfigDirectoryTypoError = NamedError.create(
|
|
1224
|
-
"ConfigDirectoryTypoError",
|
|
1225
|
-
z.object({
|
|
1226
|
-
path: z.string(),
|
|
1227
|
-
dir: z.string(),
|
|
1228
|
-
suggestion: z.string(),
|
|
1229
|
-
}),
|
|
1230
|
-
)
|
|
1231
|
-
|
|
1232
|
-
export const InvalidError = NamedError.create(
|
|
1233
|
-
"ConfigInvalidError",
|
|
1234
|
-
z.object({
|
|
1235
|
-
path: z.string(),
|
|
1236
|
-
issues: z.custom<z.core.$ZodIssue[]>().optional(),
|
|
1237
|
-
message: z.string().optional(),
|
|
1238
|
-
}),
|
|
1239
|
-
)
|
|
1240
|
-
|
|
1241
|
-
export async function get() {
|
|
1242
|
-
return state().then((x) => x.config)
|
|
1243
|
-
}
|
|
1244
|
-
|
|
1245
|
-
export async function update(config: Info) {
|
|
1246
|
-
const filepath = path.join(Instance.directory, "config.json")
|
|
1247
|
-
const existing = await loadFile(filepath)
|
|
1248
|
-
await Bun.write(filepath, JSON.stringify(mergeDeep(existing, config), null, 2))
|
|
1249
|
-
await Instance.dispose()
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
export async function directories() {
|
|
1253
|
-
return state().then((x) => x.directories)
|
|
1254
|
-
}
|
|
1255
|
-
}
|