anymous 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/bin/anymous.cjs +45 -0
- package/package.json +155 -0
- package/src/account/account.ts +473 -0
- package/src/account/repo.ts +171 -0
- package/src/account/schema.ts +99 -0
- package/src/account/url.ts +8 -0
- package/src/acp/agent.ts +95 -0
- package/src/acp/config-option.ts +203 -0
- package/src/acp/content.ts +269 -0
- package/src/acp/directory.ts +212 -0
- package/src/acp/error.ts +97 -0
- package/src/acp/event.ts +342 -0
- package/src/acp/permission.ts +254 -0
- package/src/acp/profile.ts +42 -0
- package/src/acp/service.ts +1097 -0
- package/src/acp/session.ts +232 -0
- package/src/acp/tool.ts +364 -0
- package/src/acp/usage.ts +239 -0
- package/src/agent/agent.ts +581 -0
- package/src/agent/generate.txt +75 -0
- package/src/agent/prompt/compaction.txt +9 -0
- package/src/agent/prompt/debug-tools.txt +41 -0
- package/src/agent/prompt/exe-extractor.txt +37 -0
- package/src/agent/prompt/explore.txt +18 -0
- package/src/agent/prompt/memory-dump.txt +34 -0
- package/src/agent/prompt/reverser-automator.txt +24 -0
- package/src/agent/prompt/reverser-binary.txt +25 -0
- package/src/agent/prompt/reverser-dynamic.txt +29 -0
- package/src/agent/prompt/reverser-source.txt +22 -0
- package/src/agent/prompt/reverser-static.txt +28 -0
- package/src/agent/prompt/summary.txt +11 -0
- package/src/agent/prompt/title.txt +44 -0
- package/src/agent/subagent-permissions.ts +27 -0
- package/src/audio.d.ts +14 -0
- package/src/auth/index.ts +97 -0
- package/src/background/job.ts +37 -0
- package/src/bus/global.ts +22 -0
- package/src/cli/bootstrap.ts +11 -0
- package/src/cli/cmd/account.ts +264 -0
- package/src/cli/cmd/acp.ts +73 -0
- package/src/cli/cmd/agent.ts +259 -0
- package/src/cli/cmd/attach.ts +148 -0
- package/src/cli/cmd/cmd.ts +7 -0
- package/src/cli/cmd/db.ts +62 -0
- package/src/cli/cmd/debug/agent.handler.ts +193 -0
- package/src/cli/cmd/debug/agent.ts +27 -0
- package/src/cli/cmd/debug/config.ts +14 -0
- package/src/cli/cmd/debug/file.ts +73 -0
- package/src/cli/cmd/debug/index.ts +87 -0
- package/src/cli/cmd/debug/lsp.ts +50 -0
- package/src/cli/cmd/debug/ripgrep.ts +79 -0
- package/src/cli/cmd/debug/scrap.ts +16 -0
- package/src/cli/cmd/debug/skill.ts +15 -0
- package/src/cli/cmd/debug/snapshot.ts +50 -0
- package/src/cli/cmd/debug/startup.ts +11 -0
- package/src/cli/cmd/debug/v2.ts +42 -0
- package/src/cli/cmd/export.ts +292 -0
- package/src/cli/cmd/generate.ts +54 -0
- package/src/cli/cmd/github.handler.ts +1593 -0
- package/src/cli/cmd/github.shared.ts +30 -0
- package/src/cli/cmd/github.ts +42 -0
- package/src/cli/cmd/import.ts +230 -0
- package/src/cli/cmd/mcp.ts +840 -0
- package/src/cli/cmd/models.ts +66 -0
- package/src/cli/cmd/plug.ts +230 -0
- package/src/cli/cmd/pr.ts +115 -0
- package/src/cli/cmd/prompt-display.ts +1 -0
- package/src/cli/cmd/providers.ts +534 -0
- package/src/cli/cmd/run/demo.ts +1274 -0
- package/src/cli/cmd/run/entry.body.ts +205 -0
- package/src/cli/cmd/run/footer.command.tsx +1070 -0
- package/src/cli/cmd/run/footer.menu.tsx +351 -0
- package/src/cli/cmd/run/footer.permission.tsx +472 -0
- package/src/cli/cmd/run/footer.prompt.tsx +1315 -0
- package/src/cli/cmd/run/footer.question.tsx +573 -0
- package/src/cli/cmd/run/footer.subagent.tsx +175 -0
- package/src/cli/cmd/run/footer.ts +1129 -0
- package/src/cli/cmd/run/footer.view.tsx +945 -0
- package/src/cli/cmd/run/footer.width.ts +27 -0
- package/src/cli/cmd/run/permission.shared.ts +256 -0
- package/src/cli/cmd/run/prompt.editor.ts +157 -0
- package/src/cli/cmd/run/prompt.shared.ts +153 -0
- package/src/cli/cmd/run/question.shared.ts +340 -0
- package/src/cli/cmd/run/runtime.boot.ts +202 -0
- package/src/cli/cmd/run/runtime.lifecycle.ts +406 -0
- package/src/cli/cmd/run/runtime.queue.ts +349 -0
- package/src/cli/cmd/run/runtime.shared.ts +17 -0
- package/src/cli/cmd/run/runtime.stdin.ts +37 -0
- package/src/cli/cmd/run/runtime.ts +814 -0
- package/src/cli/cmd/run/scrollback.shared.ts +92 -0
- package/src/cli/cmd/run/scrollback.surface.ts +431 -0
- package/src/cli/cmd/run/scrollback.writer.tsx +352 -0
- package/src/cli/cmd/run/session-data.ts +1113 -0
- package/src/cli/cmd/run/session-replay.ts +374 -0
- package/src/cli/cmd/run/session.shared.ts +196 -0
- package/src/cli/cmd/run/splash.ts +280 -0
- package/src/cli/cmd/run/stream.transport.ts +1462 -0
- package/src/cli/cmd/run/stream.ts +175 -0
- package/src/cli/cmd/run/subagent-data.ts +876 -0
- package/src/cli/cmd/run/theme.ts +690 -0
- package/src/cli/cmd/run/tool.ts +1486 -0
- package/src/cli/cmd/run/trace.ts +94 -0
- package/src/cli/cmd/run/turn-summary.ts +47 -0
- package/src/cli/cmd/run/types.ts +350 -0
- package/src/cli/cmd/run/variant.shared.ts +216 -0
- package/src/cli/cmd/run.ts +1011 -0
- package/src/cli/cmd/serve.ts +24 -0
- package/src/cli/cmd/session.ts +147 -0
- package/src/cli/cmd/stats.ts +393 -0
- package/src/cli/cmd/tui.ts +309 -0
- package/src/cli/cmd/uninstall.ts +353 -0
- package/src/cli/cmd/upgrade.ts +74 -0
- package/src/cli/cmd/web.ts +84 -0
- package/src/cli/effect/prompt.ts +37 -0
- package/src/cli/effect-cmd.ts +96 -0
- package/src/cli/error.ts +130 -0
- package/src/cli/heap.ts +45 -0
- package/src/cli/logo.ts +1 -0
- package/src/cli/network.ts +80 -0
- package/src/cli/tui/layer.ts +8 -0
- package/src/cli/tui/validate-session.ts +29 -0
- package/src/cli/tui/worker.ts +80 -0
- package/src/cli/ui.ts +132 -0
- package/src/cli/upgrade.ts +53 -0
- package/src/command/index.ts +177 -0
- package/src/command/template/initialize.txt +66 -0
- package/src/command/template/review.txt +101 -0
- package/src/config/agent.ts +59 -0
- package/src/config/command.ts +39 -0
- package/src/config/config.ts +681 -0
- package/src/config/entry-name.ts +19 -0
- package/src/config/managed.ts +69 -0
- package/src/config/markdown.ts +36 -0
- package/src/config/parse.ts +79 -0
- package/src/config/paths.ts +45 -0
- package/src/config/plugin.ts +79 -0
- package/src/config/tui-cwd.ts +5 -0
- package/src/config/tui-host-attention.ts +21 -0
- package/src/config/tui-migrate.ts +132 -0
- package/src/config/tui.ts +276 -0
- package/src/config/variable.ts +91 -0
- package/src/control-plane/adapters/index.ts +41 -0
- package/src/control-plane/adapters/worktree.ts +96 -0
- package/src/control-plane/dev/README.md +19 -0
- package/src/control-plane/dev/debug-workspace-plugin.ts +73 -0
- package/src/control-plane/types.ts +59 -0
- package/src/control-plane/util.ts +39 -0
- package/src/control-plane/workspace-adapter-runtime.ts +51 -0
- package/src/control-plane/workspace-context.ts +26 -0
- package/src/control-plane/workspace.ts +964 -0
- package/src/effect/app-node-builder-v1.ts +12 -0
- package/src/effect/app-runtime.ts +135 -0
- package/src/effect/bootstrap-runtime.ts +19 -0
- package/src/effect/bridge.ts +84 -0
- package/src/effect/config-service.ts +67 -0
- package/src/effect/instance-ref.ts +11 -0
- package/src/effect/instance-registry.ts +12 -0
- package/src/effect/instance-state.ts +69 -0
- package/src/effect/promise.ts +17 -0
- package/src/effect/run-service.ts +47 -0
- package/src/effect/runner.ts +217 -0
- package/src/effect/runtime-flags.ts +78 -0
- package/src/env/index.ts +41 -0
- package/src/event-manifest.ts +3 -0
- package/src/event-v2-bridge.ts +71 -0
- package/src/format/formatter.ts +404 -0
- package/src/format/index.ts +203 -0
- package/src/git/index.ts +348 -0
- package/src/id/id.ts +80 -0
- package/src/ide/index.ts +54 -0
- package/src/image/image.ts +172 -0
- package/src/index.ts +142 -0
- package/src/installation/index.ts +336 -0
- package/src/lsp/client.ts +650 -0
- package/src/lsp/diagnostic.ts +29 -0
- package/src/lsp/language.ts +121 -0
- package/src/lsp/launch.ts +21 -0
- package/src/lsp/lsp.ts +507 -0
- package/src/lsp/server.ts +1983 -0
- package/src/markdown.d.ts +4 -0
- package/src/mcp/auth.ts +163 -0
- package/src/mcp/browser.ts +37 -0
- package/src/mcp/catalog.ts +170 -0
- package/src/mcp/index.ts +1004 -0
- package/src/mcp/oauth-callback.ts +194 -0
- package/src/mcp/oauth-provider.ts +259 -0
- package/src/node.ts +4 -0
- package/src/patch/index.ts +686 -0
- package/src/permission/arity.ts +163 -0
- package/src/permission/evaluate.ts +1 -0
- package/src/permission/index.ts +229 -0
- package/src/plugin/azure.ts +26 -0
- package/src/plugin/cloudflare.ts +76 -0
- package/src/plugin/digitalocean.ts +325 -0
- package/src/plugin/github-copilot/copilot.ts +414 -0
- package/src/plugin/github-copilot/models.ts +258 -0
- package/src/plugin/index.ts +314 -0
- package/src/plugin/install.ts +439 -0
- package/src/plugin/loader.ts +237 -0
- package/src/plugin/meta.ts +188 -0
- package/src/plugin/openai/README.md +31 -0
- package/src/plugin/openai/codex.ts +565 -0
- package/src/plugin/openai/ws-pool.ts +270 -0
- package/src/plugin/openai/ws.ts +381 -0
- package/src/plugin/pty-environment.ts +24 -0
- package/src/plugin/shared.ts +323 -0
- package/src/plugin/snowflake-cortex.ts +507 -0
- package/src/plugin/tui/internal.ts +10 -0
- package/src/plugin/tui/runtime.ts +1131 -0
- package/src/plugin/xai.ts +626 -0
- package/src/project/bootstrap-service.ts +9 -0
- package/src/project/bootstrap.ts +58 -0
- package/src/project/instance-context.ts +24 -0
- package/src/project/instance-runtime.ts +16 -0
- package/src/project/instance-store.ts +213 -0
- package/src/project/project.ts +483 -0
- package/src/project/vcs.ts +423 -0
- package/src/provider/auth.ts +229 -0
- package/src/provider/error.ts +188 -0
- package/src/provider/model-status.ts +8 -0
- package/src/provider/provider.ts +2006 -0
- package/src/provider/transform.ts +1832 -0
- package/src/question/index.ts +161 -0
- package/src/question/schema.ts +4 -0
- package/src/server/auth.ts +48 -0
- package/src/server/event.ts +10 -0
- package/src/server/global-lifecycle.ts +28 -0
- package/src/server/init-projectors.ts +3 -0
- package/src/server/mdns.ts +47 -0
- package/src/server/projectors.ts +1 -0
- package/src/server/proxy-util.ts +48 -0
- package/src/server/routes/instance/httpapi/AGENTS.md +39 -0
- package/src/server/routes/instance/httpapi/api.ts +97 -0
- package/src/server/routes/instance/httpapi/errors.ts +193 -0
- package/src/server/routes/instance/httpapi/groups/config.ts +65 -0
- package/src/server/routes/instance/httpapi/groups/control-plane.ts +35 -0
- package/src/server/routes/instance/httpapi/groups/control.ts +76 -0
- package/src/server/routes/instance/httpapi/groups/event.ts +29 -0
- package/src/server/routes/instance/httpapi/groups/experimental.ts +275 -0
- package/src/server/routes/instance/httpapi/groups/file.ts +185 -0
- package/src/server/routes/instance/httpapi/groups/global.ts +136 -0
- package/src/server/routes/instance/httpapi/groups/instance.ts +206 -0
- package/src/server/routes/instance/httpapi/groups/mcp.ts +156 -0
- package/src/server/routes/instance/httpapi/groups/metadata.ts +18 -0
- package/src/server/routes/instance/httpapi/groups/permission.ts +61 -0
- package/src/server/routes/instance/httpapi/groups/project-copy.ts +32 -0
- package/src/server/routes/instance/httpapi/groups/project.ts +93 -0
- package/src/server/routes/instance/httpapi/groups/provider.ts +101 -0
- package/src/server/routes/instance/httpapi/groups/pty.ts +172 -0
- package/src/server/routes/instance/httpapi/groups/query.ts +12 -0
- package/src/server/routes/instance/httpapi/groups/question.ts +74 -0
- package/src/server/routes/instance/httpapi/groups/session.ts +462 -0
- package/src/server/routes/instance/httpapi/groups/sync.ts +113 -0
- package/src/server/routes/instance/httpapi/groups/tui.ts +208 -0
- package/src/server/routes/instance/httpapi/groups/workspace.ts +141 -0
- package/src/server/routes/instance/httpapi/handlers/config.ts +34 -0
- package/src/server/routes/instance/httpapi/handlers/control-plane.ts +37 -0
- package/src/server/routes/instance/httpapi/handlers/control.ts +43 -0
- package/src/server/routes/instance/httpapi/handlers/event.ts +99 -0
- package/src/server/routes/instance/httpapi/handlers/experimental.ts +193 -0
- package/src/server/routes/instance/httpapi/handlers/file.ts +139 -0
- package/src/server/routes/instance/httpapi/handlers/global.ts +156 -0
- package/src/server/routes/instance/httpapi/handlers/instance.ts +110 -0
- package/src/server/routes/instance/httpapi/handlers/mcp.ts +111 -0
- package/src/server/routes/instance/httpapi/handlers/permission.ts +41 -0
- package/src/server/routes/instance/httpapi/handlers/project-copy.ts +83 -0
- package/src/server/routes/instance/httpapi/handlers/project.ts +63 -0
- package/src/server/routes/instance/httpapi/handlers/provider.ts +113 -0
- package/src/server/routes/instance/httpapi/handlers/pty.ts +273 -0
- package/src/server/routes/instance/httpapi/handlers/question.ts +54 -0
- package/src/server/routes/instance/httpapi/handlers/session-errors.ts +21 -0
- package/src/server/routes/instance/httpapi/handlers/session.ts +442 -0
- package/src/server/routes/instance/httpapi/handlers/sync.ts +89 -0
- package/src/server/routes/instance/httpapi/handlers/tui.ts +131 -0
- package/src/server/routes/instance/httpapi/handlers/workspace.ts +102 -0
- package/src/server/routes/instance/httpapi/lifecycle.ts +54 -0
- package/src/server/routes/instance/httpapi/middleware/authorization.ts +150 -0
- package/src/server/routes/instance/httpapi/middleware/compression.ts +64 -0
- package/src/server/routes/instance/httpapi/middleware/cors-vary.ts +29 -0
- package/src/server/routes/instance/httpapi/middleware/error.ts +43 -0
- package/src/server/routes/instance/httpapi/middleware/fence.ts +25 -0
- package/src/server/routes/instance/httpapi/middleware/instance-context.ts +43 -0
- package/src/server/routes/instance/httpapi/middleware/proxy.ts +108 -0
- package/src/server/routes/instance/httpapi/middleware/schema-error.ts +41 -0
- package/src/server/routes/instance/httpapi/middleware/workspace-routing.ts +250 -0
- package/src/server/routes/instance/httpapi/public.ts +537 -0
- package/src/server/routes/instance/httpapi/server.ts +325 -0
- package/src/server/routes/instance/httpapi/websocket-tracker.ts +60 -0
- package/src/server/server.ts +226 -0
- package/src/server/shared/fence.ts +60 -0
- package/src/server/shared/pty-ticket.ts +15 -0
- package/src/server/shared/public-ui.ts +12 -0
- package/src/server/shared/tui-control.ts +28 -0
- package/src/server/shared/ui.ts +108 -0
- package/src/server/shared/workspace-routing.ts +38 -0
- package/src/server/tui-event.ts +1 -0
- package/src/session/compaction.ts +562 -0
- package/src/session/instruction.ts +237 -0
- package/src/session/llm/AGENTS.md +90 -0
- package/src/session/llm/ai-sdk.ts +288 -0
- package/src/session/llm/native-request.ts +196 -0
- package/src/session/llm/native-runtime.ts +195 -0
- package/src/session/llm/request.ts +226 -0
- package/src/session/llm.ts +404 -0
- package/src/session/message-error.ts +14 -0
- package/src/session/message-v2.ts +734 -0
- package/src/session/message.ts +148 -0
- package/src/session/overflow.ts +34 -0
- package/src/session/processor.ts +718 -0
- package/src/session/prompt/anthropic.txt +105 -0
- package/src/session/prompt/beast.txt +147 -0
- package/src/session/prompt/build-switch.txt +5 -0
- package/src/session/prompt/codex.txt +79 -0
- package/src/session/prompt/copilot-gpt-5.txt +143 -0
- package/src/session/prompt/default.txt +95 -0
- package/src/session/prompt/gemini.txt +155 -0
- package/src/session/prompt/gpt.txt +107 -0
- package/src/session/prompt/kimi.txt +95 -0
- package/src/session/prompt/meta.txt +65 -0
- package/src/session/prompt/plan-mode.txt +70 -0
- package/src/session/prompt/plan-reminder-anthropic.txt +67 -0
- package/src/session/prompt/plan.txt +26 -0
- package/src/session/prompt/trinity.txt +97 -0
- package/src/session/prompt.ts +1631 -0
- package/src/session/reminders.ts +92 -0
- package/src/session/retry.ts +201 -0
- package/src/session/revert.ts +146 -0
- package/src/session/run-state.ts +151 -0
- package/src/session/schema.ts +26 -0
- package/src/session/session.ts +1018 -0
- package/src/session/status.ts +56 -0
- package/src/session/summary.ts +160 -0
- package/src/session/system.ts +145 -0
- package/src/session/todo.ts +74 -0
- package/src/session/tools.ts +590 -0
- package/src/share/session.ts +58 -0
- package/src/share/share-next.ts +371 -0
- package/src/skill/discovery.ts +140 -0
- package/src/skill/index.ts +354 -0
- package/src/snapshot/index.ts +807 -0
- package/src/sql.d.ts +4 -0
- package/src/storage/schema.ts +5 -0
- package/src/storage/storage.ts +327 -0
- package/src/sync/README.md +179 -0
- package/src/sync/schema.ts +11 -0
- package/src/temporary.ts +31 -0
- package/src/tool/apply_patch.ts +313 -0
- package/src/tool/apply_patch.txt +33 -0
- package/src/tool/code-mode.ts +310 -0
- package/src/tool/edit.ts +737 -0
- package/src/tool/edit.txt +10 -0
- package/src/tool/external-directory.ts +49 -0
- package/src/tool/glob.ts +76 -0
- package/src/tool/glob.txt +6 -0
- package/src/tool/grep.ts +115 -0
- package/src/tool/grep.txt +8 -0
- package/src/tool/invalid.ts +21 -0
- package/src/tool/json-schema.ts +164 -0
- package/src/tool/lsp.ts +113 -0
- package/src/tool/lsp.txt +24 -0
- package/src/tool/mcp-websearch.ts +96 -0
- package/src/tool/plan-enter.txt +14 -0
- package/src/tool/plan-exit.txt +13 -0
- package/src/tool/plan.ts +79 -0
- package/src/tool/question.ts +44 -0
- package/src/tool/question.txt +10 -0
- package/src/tool/read.ts +386 -0
- package/src/tool/read.txt +14 -0
- package/src/tool/registry.ts +450 -0
- package/src/tool/schema.ts +14 -0
- package/src/tool/shell/id.ts +19 -0
- package/src/tool/shell/prompt.ts +293 -0
- package/src/tool/shell/shell.txt +21 -0
- package/src/tool/shell.ts +645 -0
- package/src/tool/skill.ts +70 -0
- package/src/tool/skill.txt +5 -0
- package/src/tool/task.ts +360 -0
- package/src/tool/task.txt +19 -0
- package/src/tool/todo.ts +46 -0
- package/src/tool/todowrite.txt +44 -0
- package/src/tool/tool.ts +183 -0
- package/src/tool/truncate.ts +156 -0
- package/src/tool/truncation-dir.ts +4 -0
- package/src/tool/webfetch.ts +192 -0
- package/src/tool/webfetch.txt +13 -0
- package/src/tool/websearch.ts +143 -0
- package/src/tool/websearch.txt +14 -0
- package/src/tool/write.ts +104 -0
- package/src/tool/write.txt +8 -0
- package/src/util/archive.ts +17 -0
- package/src/util/bom.ts +27 -0
- package/src/util/data-url.ts +9 -0
- package/src/util/defer.ts +10 -0
- package/src/util/effect-http-client.ts +11 -0
- package/src/util/error.ts +1 -0
- package/src/util/filesystem.ts +251 -0
- package/src/util/html.ts +8 -0
- package/src/util/iife.ts +3 -0
- package/src/util/lazy.ts +20 -0
- package/src/util/local-context.ts +25 -0
- package/src/util/locale.ts +2 -0
- package/src/util/media.ts +26 -0
- package/src/util/process.ts +177 -0
- package/src/util/proxy-env.ts +72 -0
- package/src/util/queue.ts +32 -0
- package/src/util/record.ts +1 -0
- package/src/util/repository.ts +232 -0
- package/src/util/rpc.ts +66 -0
- package/src/util/signal.ts +12 -0
- package/src/util/timeout.ts +13 -0
- package/src/util/token.ts +1 -0
- package/src/util/wildcard.ts +59 -0
- package/src/worktree/index.ts +623 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { cmd } from "./cmd"
|
|
2
|
+
import { Duration, Effect, Match, Option } from "effect"
|
|
3
|
+
import { UI } from "../ui"
|
|
4
|
+
import { Account } from "@/account/account"
|
|
5
|
+
import { AccountID, OrgID, PollExpired, type PollResult, type AccountError } from "@/account/schema"
|
|
6
|
+
import { effectCmd } from "../effect-cmd"
|
|
7
|
+
import * as Prompt from "../effect/prompt"
|
|
8
|
+
import open from "open"
|
|
9
|
+
|
|
10
|
+
const openBrowser = (url: string) => Effect.promise(() => open(url).catch(() => undefined))
|
|
11
|
+
|
|
12
|
+
const println = (msg: string) => Effect.sync(() => UI.println(msg))
|
|
13
|
+
|
|
14
|
+
const dim = (value: string) => UI.Style.TEXT_DIM + value + UI.Style.TEXT_NORMAL
|
|
15
|
+
|
|
16
|
+
const activeSuffix = (isActive: boolean) => (isActive ? dim(" (active)") : "")
|
|
17
|
+
|
|
18
|
+
export const defaultConsoleUrl = "https://console.opencode.ai"
|
|
19
|
+
|
|
20
|
+
export const formatAccountLabel = (account: { email: string; url: string }, isActive: boolean) =>
|
|
21
|
+
`${account.email} ${dim(account.url)}${activeSuffix(isActive)}`
|
|
22
|
+
|
|
23
|
+
const formatOrgChoiceLabel = (account: { email: string }, org: { name: string }, isActive: boolean) =>
|
|
24
|
+
`${org.name} (${account.email})${activeSuffix(isActive)}`
|
|
25
|
+
|
|
26
|
+
export const formatOrgLine = (
|
|
27
|
+
account: { email: string; url: string },
|
|
28
|
+
org: { id: string; name: string },
|
|
29
|
+
isActive: boolean,
|
|
30
|
+
) => {
|
|
31
|
+
const dot = isActive ? UI.Style.TEXT_SUCCESS + "●" + UI.Style.TEXT_NORMAL : " "
|
|
32
|
+
const name = isActive ? UI.Style.TEXT_HIGHLIGHT_BOLD + org.name + UI.Style.TEXT_NORMAL : org.name
|
|
33
|
+
return ` ${dot} ${name} ${dim(account.email)} ${dim(account.url)} ${dim(org.id)}`
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const isActiveOrgChoice = (
|
|
37
|
+
active: Option.Option<{ id: AccountID; active_org_id: OrgID | null }>,
|
|
38
|
+
choice: { accountID: AccountID; orgID: OrgID },
|
|
39
|
+
) => Option.isSome(active) && active.value.id === choice.accountID && active.value.active_org_id === choice.orgID
|
|
40
|
+
|
|
41
|
+
const loginEffect = Effect.fn("login")(function* (url: string) {
|
|
42
|
+
const service = yield* Account.Service
|
|
43
|
+
|
|
44
|
+
yield* Prompt.intro("Log in")
|
|
45
|
+
const login = yield* service.login(url)
|
|
46
|
+
|
|
47
|
+
yield* Prompt.log.info("Go to: " + login.url)
|
|
48
|
+
yield* Prompt.log.info("Enter code: " + login.user)
|
|
49
|
+
yield* openBrowser(login.url)
|
|
50
|
+
|
|
51
|
+
const s = Prompt.spinner()
|
|
52
|
+
yield* s.start("Waiting for authorization...")
|
|
53
|
+
|
|
54
|
+
const poll = (wait: Duration.Duration): Effect.Effect<PollResult, AccountError> =>
|
|
55
|
+
Effect.gen(function* () {
|
|
56
|
+
yield* Effect.sleep(wait)
|
|
57
|
+
const result = yield* service.poll(login)
|
|
58
|
+
if (result._tag === "PollPending") return yield* poll(wait)
|
|
59
|
+
if (result._tag === "PollSlow") return yield* poll(Duration.sum(wait, Duration.seconds(5)))
|
|
60
|
+
return result
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
const result = yield* poll(login.interval).pipe(
|
|
64
|
+
Effect.timeout(login.expiry),
|
|
65
|
+
Effect.catchTag("TimeoutError", () => Effect.succeed(new PollExpired())),
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
yield* Match.valueTags(result, {
|
|
69
|
+
PollSuccess: (r) =>
|
|
70
|
+
Effect.gen(function* () {
|
|
71
|
+
yield* s.stop("Logged in as " + r.email)
|
|
72
|
+
yield* Prompt.outro("Done")
|
|
73
|
+
}),
|
|
74
|
+
PollExpired: () => s.stop("Device code expired", 1),
|
|
75
|
+
PollDenied: () => s.stop("Authorization denied", 1),
|
|
76
|
+
PollError: (r) => s.stop("Error: " + String(r.cause), 1),
|
|
77
|
+
PollPending: () => s.stop("Unexpected state", 1),
|
|
78
|
+
PollSlow: () => s.stop("Unexpected state", 1),
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
const logoutEffect = Effect.fn("logout")(function* (email?: string) {
|
|
83
|
+
const service = yield* Account.Service
|
|
84
|
+
const accounts = yield* service.list()
|
|
85
|
+
if (accounts.length === 0) return yield* println("Not logged in")
|
|
86
|
+
|
|
87
|
+
if (email) {
|
|
88
|
+
const match = accounts.find((a) => a.email === email)
|
|
89
|
+
if (!match) return yield* println("Account not found: " + email)
|
|
90
|
+
yield* service.remove(match.id)
|
|
91
|
+
yield* Prompt.outro("Logged out from " + email)
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const active = yield* service.active()
|
|
96
|
+
const activeID = Option.map(active, (a) => a.id)
|
|
97
|
+
|
|
98
|
+
yield* Prompt.intro("Log out")
|
|
99
|
+
|
|
100
|
+
const opts = accounts.map((a) => {
|
|
101
|
+
const isActive = Option.isSome(activeID) && activeID.value === a.id
|
|
102
|
+
return {
|
|
103
|
+
value: a,
|
|
104
|
+
label: formatAccountLabel(a, isActive),
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
const selected = yield* Prompt.select({ message: "Select account to log out", options: opts })
|
|
109
|
+
if (Option.isNone(selected)) return
|
|
110
|
+
|
|
111
|
+
yield* service.remove(selected.value.id)
|
|
112
|
+
yield* Prompt.outro("Logged out from " + selected.value.email)
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
interface OrgChoice {
|
|
116
|
+
orgID: OrgID
|
|
117
|
+
accountID: AccountID
|
|
118
|
+
label: string
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const switchEffect = Effect.fn("switch")(function* () {
|
|
122
|
+
const service = yield* Account.Service
|
|
123
|
+
|
|
124
|
+
const groups = yield* service.orgsByAccount()
|
|
125
|
+
if (groups.length === 0) return yield* println("Not logged in")
|
|
126
|
+
|
|
127
|
+
const active = yield* service.active()
|
|
128
|
+
|
|
129
|
+
const opts = groups.flatMap((group) =>
|
|
130
|
+
group.orgs.map((org) => {
|
|
131
|
+
const isActive = isActiveOrgChoice(active, { accountID: group.account.id, orgID: org.id })
|
|
132
|
+
return {
|
|
133
|
+
value: { orgID: org.id, accountID: group.account.id, label: org.name },
|
|
134
|
+
label: formatOrgChoiceLabel(group.account, org, isActive),
|
|
135
|
+
}
|
|
136
|
+
}),
|
|
137
|
+
)
|
|
138
|
+
if (opts.length === 0) return yield* println("No orgs found")
|
|
139
|
+
|
|
140
|
+
yield* Prompt.intro("Switch org")
|
|
141
|
+
|
|
142
|
+
const selected = yield* Prompt.select<OrgChoice>({ message: "Select org", options: opts })
|
|
143
|
+
if (Option.isNone(selected)) return
|
|
144
|
+
|
|
145
|
+
const choice = selected.value
|
|
146
|
+
yield* service.use(choice.accountID, Option.some(choice.orgID))
|
|
147
|
+
yield* Prompt.outro("Switched to " + choice.label)
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
const orgsEffect = Effect.fn("orgs")(function* () {
|
|
151
|
+
const service = yield* Account.Service
|
|
152
|
+
|
|
153
|
+
const groups = yield* service.orgsByAccount()
|
|
154
|
+
if (groups.length === 0) return yield* println("No accounts found")
|
|
155
|
+
if (!groups.some((group) => group.orgs.length > 0)) return yield* println("No orgs found")
|
|
156
|
+
|
|
157
|
+
const active = yield* service.active()
|
|
158
|
+
|
|
159
|
+
for (const group of groups) {
|
|
160
|
+
for (const org of group.orgs) {
|
|
161
|
+
const isActive = isActiveOrgChoice(active, { accountID: group.account.id, orgID: org.id })
|
|
162
|
+
yield* println(formatOrgLine(group.account, org, isActive))
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
const openEffect = Effect.fn("open")(function* () {
|
|
168
|
+
const service = yield* Account.Service
|
|
169
|
+
const active = yield* service.active()
|
|
170
|
+
if (Option.isNone(active)) return yield* println("No active account")
|
|
171
|
+
|
|
172
|
+
const url = active.value.url
|
|
173
|
+
yield* openBrowser(url)
|
|
174
|
+
yield* Prompt.outro("Opened " + url)
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
export const LoginCommand = effectCmd({
|
|
178
|
+
command: "login [url]",
|
|
179
|
+
describe: false,
|
|
180
|
+
instance: false,
|
|
181
|
+
builder: (yargs) =>
|
|
182
|
+
yargs.positional("url", {
|
|
183
|
+
describe: "server URL",
|
|
184
|
+
type: "string",
|
|
185
|
+
}),
|
|
186
|
+
handler: Effect.fn("Cli.account.login")(function* (args) {
|
|
187
|
+
UI.empty()
|
|
188
|
+
yield* Effect.orDie(loginEffect(args.url ?? defaultConsoleUrl))
|
|
189
|
+
}),
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
export const LogoutCommand = effectCmd({
|
|
193
|
+
command: "logout [email]",
|
|
194
|
+
describe: false,
|
|
195
|
+
instance: false,
|
|
196
|
+
builder: (yargs) =>
|
|
197
|
+
yargs.positional("email", {
|
|
198
|
+
describe: "account email to log out from",
|
|
199
|
+
type: "string",
|
|
200
|
+
}),
|
|
201
|
+
handler: Effect.fn("Cli.account.logout")(function* (args) {
|
|
202
|
+
UI.empty()
|
|
203
|
+
yield* Effect.orDie(logoutEffect(args.email))
|
|
204
|
+
}),
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
export const SwitchCommand = effectCmd({
|
|
208
|
+
command: "switch",
|
|
209
|
+
describe: false,
|
|
210
|
+
instance: false,
|
|
211
|
+
handler: Effect.fn("Cli.account.switch")(function* () {
|
|
212
|
+
UI.empty()
|
|
213
|
+
yield* Effect.orDie(switchEffect())
|
|
214
|
+
}),
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
export const OrgsCommand = effectCmd({
|
|
218
|
+
command: "orgs",
|
|
219
|
+
describe: false,
|
|
220
|
+
instance: false,
|
|
221
|
+
handler: Effect.fn("Cli.account.orgs")(function* () {
|
|
222
|
+
UI.empty()
|
|
223
|
+
yield* Effect.orDie(orgsEffect())
|
|
224
|
+
}),
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
export const OpenCommand = effectCmd({
|
|
228
|
+
command: "open",
|
|
229
|
+
describe: false,
|
|
230
|
+
instance: false,
|
|
231
|
+
handler: Effect.fn("Cli.account.open")(function* () {
|
|
232
|
+
UI.empty()
|
|
233
|
+
yield* Effect.orDie(openEffect())
|
|
234
|
+
}),
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
export const ConsoleCommand = cmd({
|
|
238
|
+
command: "console",
|
|
239
|
+
describe: false,
|
|
240
|
+
builder: (yargs) =>
|
|
241
|
+
yargs
|
|
242
|
+
.command({
|
|
243
|
+
...LoginCommand,
|
|
244
|
+
describe: "log in to console",
|
|
245
|
+
})
|
|
246
|
+
.command({
|
|
247
|
+
...LogoutCommand,
|
|
248
|
+
describe: "log out from console",
|
|
249
|
+
})
|
|
250
|
+
.command({
|
|
251
|
+
...SwitchCommand,
|
|
252
|
+
describe: "switch active org",
|
|
253
|
+
})
|
|
254
|
+
.command({
|
|
255
|
+
...OrgsCommand,
|
|
256
|
+
describe: "list orgs",
|
|
257
|
+
})
|
|
258
|
+
.command({
|
|
259
|
+
...OpenCommand,
|
|
260
|
+
describe: "open active console account",
|
|
261
|
+
})
|
|
262
|
+
.demandCommand(),
|
|
263
|
+
async handler() {},
|
|
264
|
+
})
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Effect } from "effect"
|
|
2
|
+
import { effectCmd } from "../effect-cmd"
|
|
3
|
+
import { AgentSideConnection, ndJsonStream } from "@agentclientprotocol/sdk"
|
|
4
|
+
import { ServerAuth } from "@/server/auth"
|
|
5
|
+
import { createOpencodeClient } from "@opencode-ai/sdk/v2"
|
|
6
|
+
import { withNetworkOptions, resolveNetworkOptions } from "../network"
|
|
7
|
+
import { ACPProfile } from "@/acp/profile"
|
|
8
|
+
|
|
9
|
+
export const AcpCommand = effectCmd({
|
|
10
|
+
command: "acp",
|
|
11
|
+
describe: "start ACP (Agent Client Protocol) server",
|
|
12
|
+
builder: (yargs) => {
|
|
13
|
+
return withNetworkOptions(yargs).option("cwd", {
|
|
14
|
+
describe: "working directory",
|
|
15
|
+
type: "string",
|
|
16
|
+
default: process.cwd(),
|
|
17
|
+
})
|
|
18
|
+
},
|
|
19
|
+
handler: Effect.fn("Cli.acp")(function* (args) {
|
|
20
|
+
const { Server } = yield* Effect.promise(() => import("@/server/server"))
|
|
21
|
+
const { ACP } = yield* Effect.promise(() => import("@/acp/agent"))
|
|
22
|
+
ACPProfile.mark("cli.acp.handler")
|
|
23
|
+
process.env.OPENCODE_CLIENT = "acp"
|
|
24
|
+
const opts = yield* resolveNetworkOptions(args)
|
|
25
|
+
const server = yield* Effect.promise(() => ACPProfile.measure("cli.acp.server.listen", () => Server.listen(opts)))
|
|
26
|
+
|
|
27
|
+
const sdk = createOpencodeClient({
|
|
28
|
+
baseUrl: `http://${server.hostname}:${server.port}`,
|
|
29
|
+
headers: ServerAuth.headers(),
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const input = new WritableStream<Uint8Array>({
|
|
33
|
+
write(chunk) {
|
|
34
|
+
return new Promise<void>((resolve, reject) => {
|
|
35
|
+
process.stdout.write(chunk, (err) => {
|
|
36
|
+
if (err) {
|
|
37
|
+
reject(err)
|
|
38
|
+
} else {
|
|
39
|
+
resolve()
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
const output = new ReadableStream<Uint8Array>({
|
|
46
|
+
start(controller) {
|
|
47
|
+
process.stdin.on("data", (chunk: Buffer) => {
|
|
48
|
+
controller.enqueue(new Uint8Array(chunk))
|
|
49
|
+
})
|
|
50
|
+
process.stdin.on("end", () => controller.close())
|
|
51
|
+
process.stdin.on("error", (err) => controller.error(err))
|
|
52
|
+
},
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const stream = ndJsonStream(input, output)
|
|
56
|
+
const agent = ACP.init({ sdk })
|
|
57
|
+
|
|
58
|
+
new AgentSideConnection((conn) => {
|
|
59
|
+
ACPProfile.mark("cli.acp.connection.create")
|
|
60
|
+
return agent.create(conn)
|
|
61
|
+
}, stream)
|
|
62
|
+
|
|
63
|
+
yield* Effect.logInfo("setup connection")
|
|
64
|
+
process.stdin.resume()
|
|
65
|
+
yield* Effect.promise(
|
|
66
|
+
() =>
|
|
67
|
+
new Promise<void>((resolve, reject) => {
|
|
68
|
+
process.stdin.on("end", () => resolve())
|
|
69
|
+
process.stdin.on("error", reject)
|
|
70
|
+
}),
|
|
71
|
+
)
|
|
72
|
+
}),
|
|
73
|
+
})
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { cmd } from "./cmd"
|
|
2
|
+
import * as prompts from "@clack/prompts"
|
|
3
|
+
import { UI } from "../ui"
|
|
4
|
+
import { Global } from "@opencode-ai/core/global"
|
|
5
|
+
import path from "path"
|
|
6
|
+
import fs from "fs/promises"
|
|
7
|
+
import { Filesystem } from "@/util/filesystem"
|
|
8
|
+
import matter from "gray-matter"
|
|
9
|
+
import { EOL } from "os"
|
|
10
|
+
import type { Argv } from "yargs"
|
|
11
|
+
import { Effect } from "effect"
|
|
12
|
+
import { effectCmd } from "../effect-cmd"
|
|
13
|
+
|
|
14
|
+
type AgentMode = "all" | "primary" | "subagent"
|
|
15
|
+
|
|
16
|
+
// Permission keys (not raw tool names). Multiple tools can map to a single
|
|
17
|
+
// permission — e.g. write/edit/apply_patch all gate on `edit` — so we configure
|
|
18
|
+
// agents at the permission level to match how the runtime actually enforces it.
|
|
19
|
+
const AVAILABLE_PERMISSIONS = [
|
|
20
|
+
"bash",
|
|
21
|
+
"read",
|
|
22
|
+
"edit",
|
|
23
|
+
"glob",
|
|
24
|
+
"grep",
|
|
25
|
+
"webfetch",
|
|
26
|
+
"task",
|
|
27
|
+
"todowrite",
|
|
28
|
+
"websearch",
|
|
29
|
+
"lsp",
|
|
30
|
+
"skill",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
const AgentCreateCommand = effectCmd({
|
|
34
|
+
command: "create",
|
|
35
|
+
describe: "create a new agent",
|
|
36
|
+
builder: (yargs: Argv) =>
|
|
37
|
+
yargs
|
|
38
|
+
.option("path", {
|
|
39
|
+
type: "string",
|
|
40
|
+
describe: "directory path to generate the agent file",
|
|
41
|
+
})
|
|
42
|
+
.option("description", {
|
|
43
|
+
type: "string",
|
|
44
|
+
describe: "what the agent should do",
|
|
45
|
+
})
|
|
46
|
+
.option("mode", {
|
|
47
|
+
type: "string",
|
|
48
|
+
describe: "agent mode",
|
|
49
|
+
choices: ["all", "primary", "subagent"] as const,
|
|
50
|
+
})
|
|
51
|
+
.option("permissions", {
|
|
52
|
+
type: "string",
|
|
53
|
+
alias: ["tools"],
|
|
54
|
+
describe: `comma-separated list of permissions to allow (default: all). Available: "${AVAILABLE_PERMISSIONS.join(", ")}"`,
|
|
55
|
+
})
|
|
56
|
+
.option("model", {
|
|
57
|
+
type: "string",
|
|
58
|
+
alias: ["m"],
|
|
59
|
+
describe: "model to use in the format of provider/model",
|
|
60
|
+
}),
|
|
61
|
+
handler: Effect.fn("Cli.agent.create")(function* (args) {
|
|
62
|
+
const { InstanceRef } = yield* Effect.promise(() => import("@/effect/instance-ref"))
|
|
63
|
+
const { Agent } = yield* Effect.promise(() => import("../../agent/agent"))
|
|
64
|
+
const { Provider } = yield* Effect.promise(() => import("@/provider/provider"))
|
|
65
|
+
const maybeCtx = yield* InstanceRef
|
|
66
|
+
if (!maybeCtx) return yield* Effect.die("InstanceRef not provided")
|
|
67
|
+
const ctx = maybeCtx
|
|
68
|
+
const agentSvc = yield* Agent.Service
|
|
69
|
+
const runLocalEffect = <A, E>(effect: Effect.Effect<A, E>) =>
|
|
70
|
+
Effect.runPromise(effect.pipe(Effect.provideService(InstanceRef, ctx)))
|
|
71
|
+
yield* Effect.promise(async () => {
|
|
72
|
+
const cliPath = args.path
|
|
73
|
+
const cliDescription = args.description
|
|
74
|
+
const cliMode = args.mode as AgentMode | undefined
|
|
75
|
+
const perms = args.permissions
|
|
76
|
+
|
|
77
|
+
const isFullyNonInteractive = cliPath && cliDescription && cliMode && perms !== undefined
|
|
78
|
+
|
|
79
|
+
if (!isFullyNonInteractive) {
|
|
80
|
+
UI.empty()
|
|
81
|
+
prompts.intro("Create agent")
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const project = ctx.project
|
|
85
|
+
|
|
86
|
+
// Determine scope/path
|
|
87
|
+
let targetPath: string
|
|
88
|
+
if (cliPath) {
|
|
89
|
+
targetPath = path.join(cliPath, "agents")
|
|
90
|
+
} else {
|
|
91
|
+
let scope: "global" | "project" = "global"
|
|
92
|
+
if (project.vcs === "git") {
|
|
93
|
+
const scopeResult = await prompts.select({
|
|
94
|
+
message: "Location",
|
|
95
|
+
options: [
|
|
96
|
+
{
|
|
97
|
+
label: "Current project",
|
|
98
|
+
value: "project" as const,
|
|
99
|
+
hint: ctx.worktree,
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
label: "Global",
|
|
103
|
+
value: "global" as const,
|
|
104
|
+
hint: Global.Path.config,
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
})
|
|
108
|
+
if (prompts.isCancel(scopeResult)) throw new UI.CancelledError()
|
|
109
|
+
scope = scopeResult
|
|
110
|
+
}
|
|
111
|
+
targetPath = path.join(scope === "global" ? Global.Path.config : path.join(ctx.worktree, ".opencode"), "agents")
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Get description
|
|
115
|
+
let description: string
|
|
116
|
+
if (cliDescription) {
|
|
117
|
+
description = cliDescription
|
|
118
|
+
} else {
|
|
119
|
+
const query = await prompts.text({
|
|
120
|
+
message: "Description",
|
|
121
|
+
placeholder: "What should this agent do?",
|
|
122
|
+
validate: (x) => (x && x.length > 0 ? undefined : "Required"),
|
|
123
|
+
})
|
|
124
|
+
if (prompts.isCancel(query)) throw new UI.CancelledError()
|
|
125
|
+
description = query
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Generate agent
|
|
129
|
+
const spinner = prompts.spinner()
|
|
130
|
+
spinner.start("Generating agent configuration...")
|
|
131
|
+
const model = args.model ? Provider.parseModel(args.model) : undefined
|
|
132
|
+
const generated = await runLocalEffect(agentSvc.generate({ description, model })).catch((error) => {
|
|
133
|
+
spinner.stop(`LLM failed to generate agent: ${error.message}`, 1)
|
|
134
|
+
if (isFullyNonInteractive) process.exit(1)
|
|
135
|
+
throw new UI.CancelledError()
|
|
136
|
+
})
|
|
137
|
+
spinner.stop(`Agent ${generated.identifier} generated`)
|
|
138
|
+
|
|
139
|
+
// Select permissions to allow
|
|
140
|
+
let selected: string[]
|
|
141
|
+
if (perms !== undefined) {
|
|
142
|
+
selected = perms ? perms.split(",").map((t) => t.trim()) : AVAILABLE_PERMISSIONS
|
|
143
|
+
} else {
|
|
144
|
+
const result = await prompts.multiselect({
|
|
145
|
+
message: "Select permissions to allow (Space to toggle)",
|
|
146
|
+
options: AVAILABLE_PERMISSIONS.map((permission) => ({
|
|
147
|
+
label: permission,
|
|
148
|
+
value: permission,
|
|
149
|
+
})),
|
|
150
|
+
initialValues: AVAILABLE_PERMISSIONS,
|
|
151
|
+
})
|
|
152
|
+
if (prompts.isCancel(result)) throw new UI.CancelledError()
|
|
153
|
+
selected = result
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Get mode
|
|
157
|
+
let mode: AgentMode
|
|
158
|
+
if (cliMode) {
|
|
159
|
+
mode = cliMode
|
|
160
|
+
} else {
|
|
161
|
+
const modeResult = await prompts.select({
|
|
162
|
+
message: "Agent mode",
|
|
163
|
+
options: [
|
|
164
|
+
{
|
|
165
|
+
label: "All",
|
|
166
|
+
value: "all" as const,
|
|
167
|
+
hint: "Can function in both primary and subagent roles",
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
label: "Primary",
|
|
171
|
+
value: "primary" as const,
|
|
172
|
+
hint: "Acts as a primary/main agent",
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
label: "Subagent",
|
|
176
|
+
value: "subagent" as const,
|
|
177
|
+
hint: "Can be used as a subagent by other agents",
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
initialValue: "all" as const,
|
|
181
|
+
})
|
|
182
|
+
if (prompts.isCancel(modeResult)) throw new UI.CancelledError()
|
|
183
|
+
mode = modeResult
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Build permissions config — deny anything not explicitly selected.
|
|
187
|
+
const permissions: Record<string, "deny"> = {}
|
|
188
|
+
for (const permission of AVAILABLE_PERMISSIONS) {
|
|
189
|
+
if (!selected.includes(permission)) {
|
|
190
|
+
permissions[permission] = "deny"
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Build frontmatter
|
|
195
|
+
const frontmatter: {
|
|
196
|
+
description: string
|
|
197
|
+
mode: AgentMode
|
|
198
|
+
permission?: Record<string, "deny">
|
|
199
|
+
} = {
|
|
200
|
+
description: generated.whenToUse,
|
|
201
|
+
mode,
|
|
202
|
+
}
|
|
203
|
+
if (Object.keys(permissions).length > 0) {
|
|
204
|
+
frontmatter.permission = permissions
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Write file
|
|
208
|
+
const content = matter.stringify(generated.systemPrompt, frontmatter)
|
|
209
|
+
const filePath = path.join(targetPath, `${generated.identifier}.md`)
|
|
210
|
+
|
|
211
|
+
await fs.mkdir(targetPath, { recursive: true })
|
|
212
|
+
|
|
213
|
+
if (await Filesystem.exists(filePath)) {
|
|
214
|
+
if (isFullyNonInteractive) {
|
|
215
|
+
console.error(`Error: Agent file already exists: ${filePath}`)
|
|
216
|
+
process.exit(1)
|
|
217
|
+
}
|
|
218
|
+
prompts.log.error(`Agent file already exists: ${filePath}`)
|
|
219
|
+
throw new UI.CancelledError()
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
await Filesystem.write(filePath, content)
|
|
223
|
+
|
|
224
|
+
if (isFullyNonInteractive) {
|
|
225
|
+
console.log(filePath)
|
|
226
|
+
} else {
|
|
227
|
+
prompts.log.success(`Agent created: ${filePath}`)
|
|
228
|
+
prompts.outro("Done")
|
|
229
|
+
}
|
|
230
|
+
})
|
|
231
|
+
}),
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
const AgentListCommand = effectCmd({
|
|
235
|
+
command: "list",
|
|
236
|
+
describe: "list all available agents",
|
|
237
|
+
handler: Effect.fn("Cli.agent.list")(function* () {
|
|
238
|
+
const { Agent } = yield* Effect.promise(() => import("../../agent/agent"))
|
|
239
|
+
const agents = yield* Agent.Service.use((svc) => svc.list())
|
|
240
|
+
const sortedAgents = agents.sort((a, b) => {
|
|
241
|
+
if (a.native !== b.native) {
|
|
242
|
+
return a.native ? -1 : 1
|
|
243
|
+
}
|
|
244
|
+
return a.name.localeCompare(b.name)
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
for (const agent of sortedAgents) {
|
|
248
|
+
process.stdout.write(`${agent.name} (${agent.mode})` + EOL)
|
|
249
|
+
process.stdout.write(` ${JSON.stringify(agent.permission, null, 2)}` + EOL)
|
|
250
|
+
}
|
|
251
|
+
}),
|
|
252
|
+
})
|
|
253
|
+
|
|
254
|
+
export const AgentCommand = cmd({
|
|
255
|
+
command: "agent",
|
|
256
|
+
describe: "manage agents",
|
|
257
|
+
builder: (yargs) => yargs.command(AgentCreateCommand).command(AgentListCommand).demandCommand(),
|
|
258
|
+
async handler() {},
|
|
259
|
+
})
|