@graychennpm/codebridge 0.0.0-stage → 0.1.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/CHANGELOG.md +14 -0
- package/LICENSE +21 -0
- package/README.md +217 -2
- package/README.zh-CN.md +222 -0
- package/apps/web/public/brand/agent-logo-carbon.svg +1 -0
- package/apps/web/public/brand/agent-logo.svg +1 -0
- package/docs/zh-CN/npm-release.md +77 -0
- package/node_modules/@codebridge/agent-registry/dist/index.d.ts +32 -0
- package/node_modules/@codebridge/agent-registry/dist/index.js +177 -0
- package/node_modules/@codebridge/agent-registry/dist/setup.d.ts +9 -0
- package/node_modules/@codebridge/agent-registry/dist/setup.js +115 -0
- package/node_modules/@codebridge/agent-registry/package.json +17 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-active-session.d.ts +12 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-active-session.js +57 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-claude-activity.d.ts +9 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-claude-activity.js +49 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-config-options.d.ts +46 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-config-options.js +220 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-doctor.d.ts +3 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-doctor.js +18 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-event-mapper.d.ts +5 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-event-mapper.js +136 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-kill.d.ts +10 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-kill.js +24 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-race.d.ts +6 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-race.js +29 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-session-list.d.ts +32 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-session-list.js +218 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-session-pool.d.ts +85 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-session-pool.js +165 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-session-runner.d.ts +78 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-session-runner.js +550 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-spawn-profiles.d.ts +9 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-spawn-profiles.js +28 -0
- package/node_modules/@codebridge/backends/dist/acp/headless-client.d.ts +19 -0
- package/node_modules/@codebridge/backends/dist/acp/headless-client.js +47 -0
- package/node_modules/@codebridge/backends/dist/acp/index.d.ts +9 -0
- package/node_modules/@codebridge/backends/dist/acp/index.js +9 -0
- package/node_modules/@codebridge/backends/dist/agent-setup.d.ts +60 -0
- package/node_modules/@codebridge/backends/dist/agent-setup.js +504 -0
- package/node_modules/@codebridge/backends/dist/attachment-prompt.d.ts +8 -0
- package/node_modules/@codebridge/backends/dist/attachment-prompt.js +28 -0
- package/node_modules/@codebridge/backends/dist/auth-error-hints.d.ts +8 -0
- package/node_modules/@codebridge/backends/dist/auth-error-hints.js +33 -0
- package/node_modules/@codebridge/backends/dist/codex-skill-commands.d.ts +3 -0
- package/node_modules/@codebridge/backends/dist/codex-skill-commands.js +88 -0
- package/node_modules/@codebridge/backends/dist/index.d.ts +18 -0
- package/node_modules/@codebridge/backends/dist/index.js +34 -0
- package/node_modules/@codebridge/backends/dist/pi-providers.d.ts +45 -0
- package/node_modules/@codebridge/backends/dist/pi-providers.js +148 -0
- package/node_modules/@codebridge/backends/dist/pi-session-runner.d.ts +85 -0
- package/node_modules/@codebridge/backends/dist/pi-session-runner.js +460 -0
- package/node_modules/@codebridge/backends/dist/provider-connection.d.ts +17 -0
- package/node_modules/@codebridge/backends/dist/provider-connection.js +99 -0
- package/node_modules/@codebridge/backends/dist/session-discovery.d.ts +23 -0
- package/node_modules/@codebridge/backends/dist/session-discovery.js +340 -0
- package/node_modules/@codebridge/backends/dist/skill-control-plane.d.ts +147 -0
- package/node_modules/@codebridge/backends/dist/skill-control-plane.js +832 -0
- package/node_modules/@codebridge/backends/package.json +22 -0
- package/node_modules/@codebridge/bridge/dist/alert-notification-rules.d.ts +14 -0
- package/node_modules/@codebridge/bridge/dist/alert-notification-rules.js +37 -0
- package/node_modules/@codebridge/bridge/dist/channel-config.d.ts +4 -0
- package/node_modules/@codebridge/bridge/dist/channel-config.js +9 -0
- package/node_modules/@codebridge/bridge/dist/channel-ingress.d.ts +5 -0
- package/node_modules/@codebridge/bridge/dist/channel-ingress.js +403 -0
- package/node_modules/@codebridge/bridge/dist/cli.d.ts +3 -0
- package/node_modules/@codebridge/bridge/dist/cli.js +581 -0
- package/node_modules/@codebridge/bridge/dist/deployment.d.ts +46 -0
- package/node_modules/@codebridge/bridge/dist/deployment.js +174 -0
- package/node_modules/@codebridge/bridge/dist/event-loop-lag.d.ts +19 -0
- package/node_modules/@codebridge/bridge/dist/event-loop-lag.js +33 -0
- package/node_modules/@codebridge/bridge/dist/feishu-alert-monitor.d.ts +70 -0
- package/node_modules/@codebridge/bridge/dist/feishu-alert-monitor.js +591 -0
- package/node_modules/@codebridge/bridge/dist/init-wizard.d.ts +52 -0
- package/node_modules/@codebridge/bridge/dist/init-wizard.js +571 -0
- package/node_modules/@codebridge/bridge/dist/mcp-api.d.ts +4 -0
- package/node_modules/@codebridge/bridge/dist/mcp-api.js +100 -0
- package/node_modules/@codebridge/bridge/dist/outbound-api.d.ts +31 -0
- package/node_modules/@codebridge/bridge/dist/outbound-api.js +184 -0
- package/node_modules/@codebridge/bridge/dist/outbound-publishers.d.ts +54 -0
- package/node_modules/@codebridge/bridge/dist/outbound-publishers.js +213 -0
- package/node_modules/@codebridge/bridge/dist/project-api.d.ts +4 -0
- package/node_modules/@codebridge/bridge/dist/project-api.js +161 -0
- package/node_modules/@codebridge/bridge/dist/secrets-command.d.ts +13 -0
- package/node_modules/@codebridge/bridge/dist/secrets-command.js +34 -0
- package/node_modules/@codebridge/bridge/dist/session-api.d.ts +26 -0
- package/node_modules/@codebridge/bridge/dist/session-api.js +1378 -0
- package/node_modules/@codebridge/bridge/dist/session-history-import.d.ts +24 -0
- package/node_modules/@codebridge/bridge/dist/session-history-import.js +82 -0
- package/node_modules/@codebridge/bridge/dist/session-runtime-api.d.ts +19 -0
- package/node_modules/@codebridge/bridge/dist/session-runtime-api.js +453 -0
- package/node_modules/@codebridge/bridge/dist/session-runtime-migration.d.ts +21 -0
- package/node_modules/@codebridge/bridge/dist/session-runtime-migration.js +43 -0
- package/node_modules/@codebridge/bridge/dist/session-runtime-types.d.ts +85 -0
- package/node_modules/@codebridge/bridge/dist/session-runtime-types.js +98 -0
- package/node_modules/@codebridge/bridge/dist/skill-api.d.ts +28 -0
- package/node_modules/@codebridge/bridge/dist/skill-api.js +129 -0
- package/node_modules/@codebridge/bridge/dist/startup-surfaces.d.ts +15 -0
- package/node_modules/@codebridge/bridge/dist/startup-surfaces.js +13 -0
- package/node_modules/@codebridge/bridge/dist/web-frontend.d.ts +8 -0
- package/node_modules/@codebridge/bridge/dist/web-frontend.js +76 -0
- package/node_modules/@codebridge/bridge/dist/work-item-api.d.ts +6 -0
- package/node_modules/@codebridge/bridge/dist/work-item-api.js +414 -0
- package/node_modules/@codebridge/bridge/package.json +28 -0
- package/node_modules/@codebridge/channel-feishu/dist/alert-reactions.d.ts +6 -0
- package/node_modules/@codebridge/channel-feishu/dist/alert-reactions.js +58 -0
- package/node_modules/@codebridge/channel-feishu/dist/alert-types.d.ts +35 -0
- package/node_modules/@codebridge/channel-feishu/dist/alert-types.js +2 -0
- package/node_modules/@codebridge/channel-feishu/dist/bridge.d.ts +130 -0
- package/node_modules/@codebridge/channel-feishu/dist/bridge.js +1231 -0
- package/node_modules/@codebridge/channel-feishu/dist/cardkit-writer.d.ts +48 -0
- package/node_modules/@codebridge/channel-feishu/dist/cardkit-writer.js +153 -0
- package/node_modules/@codebridge/channel-feishu/dist/chain-topics.d.ts +20 -0
- package/node_modules/@codebridge/channel-feishu/dist/chain-topics.js +35 -0
- package/node_modules/@codebridge/channel-feishu/dist/coalescing-card-writer.d.ts +12 -0
- package/node_modules/@codebridge/channel-feishu/dist/coalescing-card-writer.js +53 -0
- package/node_modules/@codebridge/channel-feishu/dist/delivery-reconciler.d.ts +19 -0
- package/node_modules/@codebridge/channel-feishu/dist/delivery-reconciler.js +53 -0
- package/node_modules/@codebridge/channel-feishu/dist/durable-markdown-card.d.ts +19 -0
- package/node_modules/@codebridge/channel-feishu/dist/durable-markdown-card.js +77 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-extra-events.d.ts +27 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-extra-events.js +24 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-http.d.ts +4 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-http.js +25 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-inbound-context.d.ts +13 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-inbound-context.js +45 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-inbound-media.d.ts +22 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-inbound-media.js +273 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-mention-gate.d.ts +13 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-mention-gate.js +22 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-outbound-file.d.ts +12 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-outbound-file.js +38 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-quoted-message.d.ts +30 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-quoted-message.js +183 -0
- package/node_modules/@codebridge/channel-feishu/dist/index.d.ts +7 -0
- package/node_modules/@codebridge/channel-feishu/dist/index.js +3 -0
- package/node_modules/@codebridge/channel-feishu/dist/redacting-logger.d.ts +17 -0
- package/node_modules/@codebridge/channel-feishu/dist/redacting-logger.js +41 -0
- package/node_modules/@codebridge/channel-feishu/dist/run-status.d.ts +39 -0
- package/node_modules/@codebridge/channel-feishu/dist/run-status.js +166 -0
- package/node_modules/@codebridge/channel-feishu/dist/session-watcher.d.ts +98 -0
- package/node_modules/@codebridge/channel-feishu/dist/session-watcher.js +655 -0
- package/node_modules/@codebridge/channel-feishu/package.json +19 -0
- package/node_modules/@codebridge/channel-telegram/dist/coalescing-message-writer.d.ts +14 -0
- package/node_modules/@codebridge/channel-telegram/dist/coalescing-message-writer.js +56 -0
- package/node_modules/@codebridge/channel-telegram/dist/index.d.ts +3 -0
- package/node_modules/@codebridge/channel-telegram/dist/index.js +3 -0
- package/node_modules/@codebridge/channel-telegram/dist/telegram-api.d.ts +62 -0
- package/node_modules/@codebridge/channel-telegram/dist/telegram-api.js +72 -0
- package/node_modules/@codebridge/channel-telegram/dist/telegram-bridge.d.ts +64 -0
- package/node_modules/@codebridge/channel-telegram/dist/telegram-bridge.js +469 -0
- package/node_modules/@codebridge/channel-telegram/dist/telegram-session-watcher.d.ts +41 -0
- package/node_modules/@codebridge/channel-telegram/dist/telegram-session-watcher.js +184 -0
- package/node_modules/@codebridge/channel-telegram/package.json +18 -0
- package/node_modules/@codebridge/core/dist/config-schema.d.ts +1195 -0
- package/node_modules/@codebridge/core/dist/config-schema.js +293 -0
- package/node_modules/@codebridge/core/dist/config-store.d.ts +48 -0
- package/node_modules/@codebridge/core/dist/config-store.js +207 -0
- package/node_modules/@codebridge/core/dist/index.d.ts +11 -0
- package/node_modules/@codebridge/core/dist/index.js +10 -0
- package/node_modules/@codebridge/core/dist/json-file-store.d.ts +16 -0
- package/node_modules/@codebridge/core/dist/json-file-store.js +46 -0
- package/node_modules/@codebridge/core/dist/mcp-types.d.ts +7 -0
- package/node_modules/@codebridge/core/dist/mcp-types.js +2 -0
- package/node_modules/@codebridge/core/dist/mentions.d.ts +36 -0
- package/node_modules/@codebridge/core/dist/mentions.js +138 -0
- package/node_modules/@codebridge/core/dist/secret-migration.d.ts +14 -0
- package/node_modules/@codebridge/core/dist/secret-migration.js +55 -0
- package/node_modules/@codebridge/core/dist/secret-refs.d.ts +34 -0
- package/node_modules/@codebridge/core/dist/secret-refs.js +142 -0
- package/node_modules/@codebridge/core/dist/session-event-wire.d.ts +17 -0
- package/node_modules/@codebridge/core/dist/session-event-wire.js +28 -0
- package/node_modules/@codebridge/core/dist/types.d.ts +363 -0
- package/node_modules/@codebridge/core/dist/types.js +22 -0
- package/node_modules/@codebridge/core/dist/workspace-key.d.ts +11 -0
- package/node_modules/@codebridge/core/dist/workspace-key.js +25 -0
- package/node_modules/@codebridge/core/package.json +22 -0
- package/node_modules/@codebridge/mcp-runtime/dist/.tsbuildinfo +1 -0
- package/node_modules/@codebridge/mcp-runtime/dist/index.d.ts +92 -0
- package/node_modules/@codebridge/mcp-runtime/dist/index.js +377 -0
- package/node_modules/@codebridge/mcp-runtime/package.json +19 -0
- package/node_modules/@codebridge/policy/dist/capability-runtime.d.ts +123 -0
- package/node_modules/@codebridge/policy/dist/capability-runtime.js +195 -0
- package/node_modules/@codebridge/policy/dist/demo-capabilities.d.ts +4 -0
- package/node_modules/@codebridge/policy/dist/demo-capabilities.js +134 -0
- package/node_modules/@codebridge/policy/dist/equity-capabilities.d.ts +8 -0
- package/node_modules/@codebridge/policy/dist/equity-capabilities.js +35 -0
- package/node_modules/@codebridge/policy/dist/index.d.ts +107 -0
- package/node_modules/@codebridge/policy/dist/index.js +317 -0
- package/node_modules/@codebridge/policy/package.json +17 -0
- package/node_modules/@codebridge/project-catalog/dist/index.d.ts +145 -0
- package/node_modules/@codebridge/project-catalog/dist/index.js +699 -0
- package/node_modules/@codebridge/project-catalog/package.json +18 -0
- package/node_modules/@codebridge/router/dist/channel-stream-projector.d.ts +19 -0
- package/node_modules/@codebridge/router/dist/channel-stream-projector.js +68 -0
- package/node_modules/@codebridge/router/dist/command-help.d.ts +14 -0
- package/node_modules/@codebridge/router/dist/command-help.js +151 -0
- package/node_modules/@codebridge/router/dist/feishu-stream-presenter.d.ts +18 -0
- package/node_modules/@codebridge/router/dist/feishu-stream-presenter.js +193 -0
- package/node_modules/@codebridge/router/dist/index.d.ts +9 -0
- package/node_modules/@codebridge/router/dist/index.js +9 -0
- package/node_modules/@codebridge/router/dist/model-effort.d.ts +5 -0
- package/node_modules/@codebridge/router/dist/model-effort.js +33 -0
- package/node_modules/@codebridge/router/dist/orchestrator.d.ts +56 -0
- package/node_modules/@codebridge/router/dist/orchestrator.js +290 -0
- package/node_modules/@codebridge/router/dist/session-list-format.d.ts +19 -0
- package/node_modules/@codebridge/router/dist/session-list-format.js +97 -0
- package/node_modules/@codebridge/router/dist/session-rotation.d.ts +9 -0
- package/node_modules/@codebridge/router/dist/session-rotation.js +31 -0
- package/node_modules/@codebridge/router/dist/session-router.d.ts +59 -0
- package/node_modules/@codebridge/router/dist/session-router.js +182 -0
- package/node_modules/@codebridge/router/dist/slash-commands.d.ts +78 -0
- package/node_modules/@codebridge/router/dist/slash-commands.js +874 -0
- package/node_modules/@codebridge/router/package.json +18 -0
- package/node_modules/@codebridge/run-executor/dist/agent-event-aggregator.d.ts +18 -0
- package/node_modules/@codebridge/run-executor/dist/agent-event-aggregator.js +88 -0
- package/node_modules/@codebridge/run-executor/dist/index.d.ts +55 -0
- package/node_modules/@codebridge/run-executor/dist/index.js +754 -0
- package/node_modules/@codebridge/run-executor/dist/run-heartbeat.d.ts +14 -0
- package/node_modules/@codebridge/run-executor/dist/run-heartbeat.js +24 -0
- package/node_modules/@codebridge/run-executor/package.json +20 -0
- package/node_modules/@codebridge/runner-client/dist/index.d.ts +142 -0
- package/node_modules/@codebridge/runner-client/dist/index.js +439 -0
- package/node_modules/@codebridge/runner-client/package.json +18 -0
- package/node_modules/@codebridge/runner-host/dist/cli.d.ts +3 -0
- package/node_modules/@codebridge/runner-host/dist/cli.js +58 -0
- package/node_modules/@codebridge/runner-host/dist/codex-session-ownership.d.ts +13 -0
- package/node_modules/@codebridge/runner-host/dist/codex-session-ownership.js +79 -0
- package/node_modules/@codebridge/runner-host/dist/deployment-mcp-server.d.ts +10 -0
- package/node_modules/@codebridge/runner-host/dist/deployment-mcp-server.js +54 -0
- package/node_modules/@codebridge/runner-host/dist/fcb-script.d.ts +3 -0
- package/node_modules/@codebridge/runner-host/dist/fcb-script.js +99 -0
- package/node_modules/@codebridge/runner-host/dist/index.d.ts +3 -0
- package/node_modules/@codebridge/runner-host/dist/index.js +2 -0
- package/node_modules/@codebridge/runner-host/dist/materialize-attachments.d.ts +4 -0
- package/node_modules/@codebridge/runner-host/dist/materialize-attachments.js +62 -0
- package/node_modules/@codebridge/runner-host/dist/server.d.ts +150 -0
- package/node_modules/@codebridge/runner-host/dist/server.js +1295 -0
- package/node_modules/@codebridge/runner-host/dist/session-lease.d.ts +12 -0
- package/node_modules/@codebridge/runner-host/dist/session-lease.js +146 -0
- package/node_modules/@codebridge/runner-host/package.json +26 -0
- package/node_modules/@codebridge/session-catalog/dist/index.d.ts +124 -0
- package/node_modules/@codebridge/session-catalog/dist/index.js +411 -0
- package/node_modules/@codebridge/session-catalog/package.json +17 -0
- package/node_modules/@codebridge/session-coordinator/dist/coordinator.d.ts +111 -0
- package/node_modules/@codebridge/session-coordinator/dist/coordinator.js +364 -0
- package/node_modules/@codebridge/session-coordinator/dist/index.d.ts +5 -0
- package/node_modules/@codebridge/session-coordinator/dist/index.js +5 -0
- package/node_modules/@codebridge/session-coordinator/dist/lease.d.ts +14 -0
- package/node_modules/@codebridge/session-coordinator/dist/lease.js +26 -0
- package/node_modules/@codebridge/session-coordinator/dist/queued-claim.d.ts +20 -0
- package/node_modules/@codebridge/session-coordinator/dist/queued-claim.js +45 -0
- package/node_modules/@codebridge/session-coordinator/dist/recovery.d.ts +31 -0
- package/node_modules/@codebridge/session-coordinator/dist/recovery.js +114 -0
- package/node_modules/@codebridge/session-coordinator/package.json +17 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/abnfDiagram-N423BO3Z-C-JdFv0U.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/arc-DsNROjzU.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/architecture-TIHT7OUA-ZEBHG2JZ.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/architectureDiagram-T3A2C74G-OsrxcwPM.js +36 -0
- package/node_modules/@codebridge/web/dist/assets/array-BifhSqXX.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/blockDiagram-VBNYF7ZC-DRgfNeNW.js +132 -0
- package/node_modules/@codebridge/web/dist/assets/c4Diagram-5PPSVZJV-BtOGKTh8.js +10 -0
- package/node_modules/@codebridge/web/dist/assets/channel-MhXyjxUS.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-2GRJ4B5K-Dy1gJ7sY.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-2Q5K7J3B-C1jixKkw.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-4I5QYGJK-1pOLR_SG.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-5RXB4S5H-CP43rgsO.js +231 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-5VM5RSS4-ZNzvKenW.js +15 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-6Q2QTUOP-Bi3Xrp6W.js +88 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-7BUUIJ7U-Bb538aSH.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-7Z6QIM7H-CILAW2Nk.js +10 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-GF5L2VYU-CAp09yhq.js +206 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-I66GZJ75-B_rJXmNu.js +128 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-JQJVKLGR-OVeOJFCx.js +156 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-JWPE2WC7-DVXcaiue.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-KBJHAD2P-uaupp0k5.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-KEIR6QF5-BICK3FdT.js +161 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-NSK5VX7P-fIHF5wwn.js +2 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-QR6OTTB3-DxkJuF2b.js +62 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-RYQCIY6F-CC5j3u-X.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-UBXNYLIW-DB35O-6R.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-W5SLKNZC-bkRBsbq-.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-WRU74C26-DwvEoD-1.js +70 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-XXDRQBXY-DRyYA-HY.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-Y2CYZVJY-DsF7k-Jl.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/classDiagram-JCYQIIEL-B8r7z8ii.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/classDiagram-v2-OCEON4UE-B8r7z8ii.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/cose-bilkent-JH36ORCC-CLkwlrX7.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/cynefin-VYW2F7L2-C3_Llw02.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/cynefinDiagram-MW4NZA55-D5v7UnJy.js +62 -0
- package/node_modules/@codebridge/web/dist/assets/cytoscape.esm-B-NFISlW.js +321 -0
- package/node_modules/@codebridge/web/dist/assets/dagre-Buvkdvvj.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/dagre-VZM6K2ZE-Cr0IibwW.js +4 -0
- package/node_modules/@codebridge/web/dist/assets/defaultLocale-BFoDCU3G.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/diagram-7IWD3JNH-CpQXDIzA.js +30 -0
- package/node_modules/@codebridge/web/dist/assets/diagram-B4RE2ZJO-VaOkH0Ya.js +3 -0
- package/node_modules/@codebridge/web/dist/assets/diagram-LBJQPF4R-D0iXyNks.js +24 -0
- package/node_modules/@codebridge/web/dist/assets/diagram-Q27KOJAE-CtqYk01P.js +24 -0
- package/node_modules/@codebridge/web/dist/assets/diagram-UB23O5K3-CFnd3H1_.js +41 -0
- package/node_modules/@codebridge/web/dist/assets/dist-D2L7nRdk.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/ebnfDiagram-BXEA7PRR-B0GIbJYt.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/erDiagram-JOGREHBK-BApaLGVA.js +85 -0
- package/node_modules/@codebridge/web/dist/assets/eventmodeling-45OFAUF4-DqGGjcld.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/flowDiagram-UKHOOZJN-I_qlizLH.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/ganttDiagram-PKOTCBZU-B-QZ-J82.js +292 -0
- package/node_modules/@codebridge/web/dist/assets/gitGraph-TEB2WS4Q-DK2SJ2Ne.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/gitGraphDiagram-DS77QQ5N-B6Z-pu0D.js +106 -0
- package/node_modules/@codebridge/web/dist/assets/graphlib-DS17s2tU.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/index-8BzpyygS.js +559 -0
- package/node_modules/@codebridge/web/dist/assets/index-Bzaz89LE.css +1 -0
- package/node_modules/@codebridge/web/dist/assets/info-DKCQHKI2-CGWxt_Py.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/infoDiagram-6WML65LV-77XjrPZs.js +2 -0
- package/node_modules/@codebridge/web/dist/assets/init-C-OQMol4.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/ishikawaDiagram-WSZJBQD7-P1bZAz2x.js +70 -0
- package/node_modules/@codebridge/web/dist/assets/journeyDiagram-NVQOT4AX-C4rwMcBY.js +139 -0
- package/node_modules/@codebridge/web/dist/assets/kanban-definition-27J2QSJJ-mtw4a9bc.js +89 -0
- package/node_modules/@codebridge/web/dist/assets/line-DP4RkYqm.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/linear-DMg3PPio.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/map-BaFkSB1l.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/mermaid-parser.core-HY84kHw1.js +7 -0
- package/node_modules/@codebridge/web/dist/assets/mermaid.core-DdgCdsnM.js +42 -0
- package/node_modules/@codebridge/web/dist/assets/mindmap-definition-FAOFIHXS-Cw1EnbhZ.js +96 -0
- package/node_modules/@codebridge/web/dist/assets/ordinal-BDEzSJ7C.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/packet-7NZHBO7P-CEbrbJH3.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/path-fybaL0A-.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/pegDiagram-VL7TDLO6-CEc1Gedb.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/pie-RZYD4A2V-DPXVs-IW.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/pieDiagram-7S7Q4E2Y-hoQeGMFH.js +39 -0
- package/node_modules/@codebridge/web/dist/assets/quadrantDiagram-CIZ2JOQS-C-Nmxx0f.js +7 -0
- package/node_modules/@codebridge/web/dist/assets/radar-I7S5WNFK-BVd3X3Pd.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/railroad-3IZDKUUU-CxLxzr_v.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/railroad-abnf-AHOZXSZD-MA1zPI84.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/railroad-ebnf-EBAXGLYW-Bqug_umD.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/railroad-peg-LSFZ7HO6-DRcRFwpq.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/railroadDiagram-AXF67PYL-B007ZkL9.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/requirementDiagram-LRYGKXZP-LrTCcEi5.js +84 -0
- package/node_modules/@codebridge/web/dist/assets/rough.esm-Dy-Kn_BL.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/sankeyDiagram-W5VNT64P-Ch4mzHck.js +40 -0
- package/node_modules/@codebridge/web/dist/assets/sequenceDiagram-SI44F4Z6-CHg4OzLX.js +162 -0
- package/node_modules/@codebridge/web/dist/assets/sizeCapture-X5ZJPWSS-B0uUizjq.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/src-BrO6_odD.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/stateDiagram-OKZ733FA-7cVkr5nR.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/stateDiagram-v2-UEYNNEHI-CTy_mAXb.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/swimlanes-SLNWSIFB-BwSVF5qy.js +2 -0
- package/node_modules/@codebridge/web/dist/assets/swimlanesDiagram-ULZ7WXOC-BBQnfZ1j.js +8 -0
- package/node_modules/@codebridge/web/dist/assets/timeline-definition-Z64GVDOM-BaHEkVDV.js +120 -0
- package/node_modules/@codebridge/web/dist/assets/treeView-QDETBFTQ-CF0kLN62.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/treemap-6X3UGDF4-BB8A8uux.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/vennDiagram-T6HMQDX7-BFK12Iro.js +34 -0
- package/node_modules/@codebridge/web/dist/assets/wardley-OPB4EBWU-C_3y61zk.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/wardleyDiagram-T6FBY63Y-W2oGu4WK.js +78 -0
- package/node_modules/@codebridge/web/dist/assets/xychartDiagram-ELKLHX3M-BiVRnbvz.js +7 -0
- package/node_modules/@codebridge/web/dist/brand/agent-logo-carbon.svg +1 -0
- package/node_modules/@codebridge/web/dist/brand/agent-logo.svg +1 -0
- package/node_modules/@codebridge/web/dist/brand/agnet-logo-carbon.svg +1 -0
- package/node_modules/@codebridge/web/dist/brand/agnet-logo.svg +1 -0
- package/node_modules/@codebridge/web/dist/brand/agnet-mark-carbon.svg +1 -0
- package/node_modules/@codebridge/web/dist/brand/agnet-mark.svg +1 -0
- package/node_modules/@codebridge/web/dist/fonts/CommitMono-400-Regular.otf +0 -0
- package/node_modules/@codebridge/web/dist/fonts/CommitMono-700-Regular.otf +0 -0
- package/node_modules/@codebridge/web/dist/fonts/CommitMono-OFL.txt +21 -0
- package/node_modules/@codebridge/web/dist/fonts/DepartureMono-OFL.txt +21 -0
- package/node_modules/@codebridge/web/dist/fonts/DepartureMono-Regular.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/index.html +25 -0
- package/node_modules/@codebridge/web/package.json +7 -0
- package/node_modules/@codebridge/work-items/dist/index.d.ts +371 -0
- package/node_modules/@codebridge/work-items/dist/index.js +1784 -0
- package/node_modules/@codebridge/work-items/dist/session-projector.d.ts +4 -0
- package/node_modules/@codebridge/work-items/dist/session-projector.js +506 -0
- package/node_modules/@codebridge/work-items/dist/session-runtime.d.ts +274 -0
- package/node_modules/@codebridge/work-items/dist/session-runtime.js +1103 -0
- package/node_modules/@codebridge/work-items/dist/session-schema.d.ts +9 -0
- package/node_modules/@codebridge/work-items/dist/session-schema.js +292 -0
- package/node_modules/@codebridge/work-items/package.json +20 -0
- package/package.json +75 -4
|
@@ -0,0 +1,571 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { StringDecoder } from "node:string_decoder";
|
|
3
|
+
import { randomBytes } from "node:crypto";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import os from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { parseDocument, stringify as stringifyYaml } from "yaml";
|
|
8
|
+
import { ConfigStore, SUPPORTED_AGENT_IDS, defaultConfig, keychainServiceFor, resolveSecretRef, secretSourceOf, storeKeychainSecret, } from "@codebridge/core";
|
|
9
|
+
/** Commands AgentSetupService probes for each agent CLI. */
|
|
10
|
+
const AGENT_COMMANDS = {
|
|
11
|
+
cursor: ["cursor-agent", "agent"],
|
|
12
|
+
claude: ["claude"],
|
|
13
|
+
codex: ["codex"],
|
|
14
|
+
opencode: ["opencode"],
|
|
15
|
+
};
|
|
16
|
+
const INSTALL_HINTS = {
|
|
17
|
+
cursor: "https://cursor.com/docs/cli",
|
|
18
|
+
claude: "npm install -g @anthropic-ai/claude-code",
|
|
19
|
+
codex: "npm install -g @openai/codex",
|
|
20
|
+
opencode: "npm install -g opencode-ai",
|
|
21
|
+
};
|
|
22
|
+
function needsValue(value) {
|
|
23
|
+
const source = secretSourceOf(value);
|
|
24
|
+
return source === "missing" || source === "placeholder";
|
|
25
|
+
}
|
|
26
|
+
function defaultHasCommand(command) {
|
|
27
|
+
return (process.env.PATH ?? "").split(path.delimiter).some((dir) => {
|
|
28
|
+
try {
|
|
29
|
+
fs.accessSync(path.join(dir, command), fs.constants.X_OK);
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function newRunnerToken() {
|
|
38
|
+
return randomBytes(24).toString("hex");
|
|
39
|
+
}
|
|
40
|
+
/** Stage beside the real target so rename remains atomic and preserves config symlinks. */
|
|
41
|
+
function stageConfig(configPath, text) {
|
|
42
|
+
const target = fs.existsSync(configPath) ? fs.realpathSync(configPath) : path.resolve(configPath);
|
|
43
|
+
const dataDir = path.dirname(target);
|
|
44
|
+
fs.mkdirSync(dataDir, { recursive: true, mode: 0o700 });
|
|
45
|
+
const temporary = path.join(dataDir, `.config.${randomBytes(12).toString("hex")}.tmp`);
|
|
46
|
+
try {
|
|
47
|
+
fs.writeFileSync(temporary, text, { mode: 0o600, flag: "wx" });
|
|
48
|
+
try {
|
|
49
|
+
new ConfigStore({ dataDir, configFileName: path.basename(temporary), resolve: [] });
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// Schema errors may contain credential values; never dump them to the terminal.
|
|
53
|
+
throw new Error("配置校验失败,请检查 config.yaml 和环境变量;原配置和密钥未修改");
|
|
54
|
+
}
|
|
55
|
+
return { temporary, target };
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
fs.rmSync(temporary, { force: true });
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** Delete only a new, wizard-owned staging item, never an existing credential. */
|
|
63
|
+
function removeStagedSecret(service, secrets = {}) {
|
|
64
|
+
const run = secrets.run ?? ((file, args) => execFileSync(file, args, {
|
|
65
|
+
encoding: "utf8", timeout: 10_000, stdio: ["pipe", "pipe", "pipe"],
|
|
66
|
+
}));
|
|
67
|
+
if ((secrets.platform ?? process.platform) === "darwin") {
|
|
68
|
+
run("/usr/bin/security", ["delete-generic-password", "-s", service, "-a", "codebridge"]);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
run("secret-tool", ["clear", "service", service, "account", "codebridge"]);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** No TTY: generate a token in a 0600 file; never access the keychain or overwrite a config. */
|
|
75
|
+
export function initDefaults(dataDir) {
|
|
76
|
+
const configPath = path.join(dataDir, "config.yaml");
|
|
77
|
+
if (fs.existsSync(configPath))
|
|
78
|
+
return { written: false, configPath };
|
|
79
|
+
const doc = parseDocument(stringifyYaml(defaultConfig()));
|
|
80
|
+
doc.setIn(["runner", "token"], process.env.RUNNER_TOKEN ? "env:RUNNER_TOKEN" : newRunnerToken());
|
|
81
|
+
const staged = stageConfig(configPath, doc.toString());
|
|
82
|
+
try {
|
|
83
|
+
// link is no-clobber even if another init creates the config after our initial check.
|
|
84
|
+
fs.linkSync(staged.temporary, staged.target);
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
fs.rmSync(staged.temporary, { force: true });
|
|
88
|
+
}
|
|
89
|
+
return { written: true, configPath };
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Interactive setup. Fills what is missing in config.yaml and keeps every other field and
|
|
93
|
+
* comment; verifies credentials against Feishu/Telegram; stores secrets in the OS keychain
|
|
94
|
+
* with keychain: refs in the file. Nothing (keychain or file) is written until every step
|
|
95
|
+
* has finished and the result validates. New keychain items are isolated until config commit.
|
|
96
|
+
*/
|
|
97
|
+
export async function runInitWizard(options) {
|
|
98
|
+
const { io, dataDir } = options;
|
|
99
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
100
|
+
const hasCommand = options.hasCommand ?? defaultHasCommand;
|
|
101
|
+
const configPath = path.join(dataDir, "config.yaml");
|
|
102
|
+
const existed = fs.existsSync(configPath);
|
|
103
|
+
const doc = parseDocument(existed ? fs.readFileSync(configPath, "utf8") : stringifyYaml(defaultConfig()));
|
|
104
|
+
if (doc.errors.length)
|
|
105
|
+
throw new Error("config.yaml 格式错误,未修改配置");
|
|
106
|
+
const summary = { configPath, channels: [], secretStorage: {} };
|
|
107
|
+
/** Secrets to store at the very end, after everything else succeeded. */
|
|
108
|
+
const pending = new Map();
|
|
109
|
+
const setSecret = (secretPath, value) => pending.set(secretPath.join("."), { secretPath, value });
|
|
110
|
+
const resolveExisting = (value) => {
|
|
111
|
+
if (typeof value !== "string" || needsValue(value))
|
|
112
|
+
return undefined;
|
|
113
|
+
if (!value.startsWith("keychain:") && !value.startsWith("env:"))
|
|
114
|
+
return value;
|
|
115
|
+
try {
|
|
116
|
+
return resolveSecretRef(value, options.secrets);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
io.print(existed ? `更新已有配置:${configPath}(保留已有设置;只修改本次确认的项目,YAML 格式可能调整)` : `新建配置:${configPath}`);
|
|
123
|
+
// Runner token: generated, never typed.
|
|
124
|
+
if (process.env.RUNNER_TOKEN) {
|
|
125
|
+
if (needsValue(doc.getIn(["runner", "token"])))
|
|
126
|
+
doc.setIn(["runner", "token"], "env:RUNNER_TOKEN");
|
|
127
|
+
summary.secretStorage["runner.token"] = "kept";
|
|
128
|
+
}
|
|
129
|
+
else if (needsValue(doc.getIn(["runner", "token"])))
|
|
130
|
+
setSecret(["runner", "token"], options.newToken?.() ?? newRunnerToken());
|
|
131
|
+
else
|
|
132
|
+
summary.secretStorage["runner.token"] = "kept";
|
|
133
|
+
// Feishu.
|
|
134
|
+
const feishuFromEnv = Boolean(process.env.FEISHU_APP_ID && process.env.FEISHU_APP_SECRET);
|
|
135
|
+
const feishuConfigured = feishuFromEnv || !needsValue(doc.getIn(["feishu", "appSecret"])) && doc.getIn(["feishu", "appId"]) !== "cli_placeholder";
|
|
136
|
+
if (await io.confirm("启用飞书机器人?", true)) {
|
|
137
|
+
if (feishuFromEnv)
|
|
138
|
+
io.print("飞书凭据由环境变量提供;运行时环境变量优先于文件设置。");
|
|
139
|
+
if (feishuConfigured && !(await io.confirm("飞书凭据已配置,是否重新填写?", false))) {
|
|
140
|
+
summary.channels.push("feishu");
|
|
141
|
+
summary.secretStorage["feishu.appSecret"] = "kept";
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
const feishu = await promptFeishu(doc, io, fetchImpl);
|
|
145
|
+
if (feishu) {
|
|
146
|
+
doc.setIn(["feishu", "appId"], feishu.appId);
|
|
147
|
+
setSecret(["feishu", "appSecret"], feishu.appSecret);
|
|
148
|
+
summary.channels.push("feishu");
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const policy = doc.getIn(["feishu", "policy", "dmMode"]);
|
|
152
|
+
if (summary.channels.includes("feishu") && (policy ?? "open") === "open") {
|
|
153
|
+
io.print(" 注意:飞书私聊当前对租户内所有人开放(feishu.policy.dmMode: open)。只给自己用时,需在 config.yaml 同时设置 dmMode: allowlist 和 dmAllowlist。");
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// Telegram: never left without an allowlist, since an empty one lets anyone drive local agents.
|
|
157
|
+
const telegramFromEnv = Boolean(process.env.TELEGRAM_BOT_TOKEN);
|
|
158
|
+
const telegramToken = process.env.TELEGRAM_BOT_TOKEN || doc.getIn(["telegram", "botToken"]);
|
|
159
|
+
if (telegramFromEnv)
|
|
160
|
+
io.print("Telegram 凭据由环境变量提供,本次保留该机器人;更换机器人需先更新或移除 TELEGRAM_BOT_TOKEN 再运行向导。");
|
|
161
|
+
const telegramConfigured = Boolean(telegramToken);
|
|
162
|
+
if (await io.confirm("启用 Telegram 机器人?", telegramConfigured)) {
|
|
163
|
+
if (telegramConfigured && (telegramFromEnv || !(await io.confirm("Telegram 已配置,是否重新填写?", false)))) {
|
|
164
|
+
summary.channels.push("telegram");
|
|
165
|
+
summary.secretStorage["telegram.botToken"] = "kept";
|
|
166
|
+
if (!hasItems(doc.getIn(["telegram", "allowedUsers"])) && !hasItems(doc.getIn(["telegram", "allowedChats"]))) {
|
|
167
|
+
io.print("⚠ 现有 Telegram 配置没有白名单,任何人都能通过机器人操作这台电脑,必须补上。");
|
|
168
|
+
doc.setIn(["telegram", "allowedUsers"], await promptTelegramUsers(io, fetchImpl, resolveExisting(telegramToken), options));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
const telegram = await promptTelegram(io, fetchImpl, doc, options);
|
|
173
|
+
if (telegram) {
|
|
174
|
+
setSecret(["telegram", "botToken"], telegram.token);
|
|
175
|
+
doc.setIn(["telegram", "allowedUsers"], telegram.users);
|
|
176
|
+
if (telegram.replaceChats)
|
|
177
|
+
doc.deleteIn(["telegram", "allowedChats"]);
|
|
178
|
+
summary.channels.push("telegram");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (feishuConfigured && !summary.channels.includes("feishu")) {
|
|
183
|
+
summary.channels.push("feishu");
|
|
184
|
+
io.print("本次未修改已有飞书配置。");
|
|
185
|
+
}
|
|
186
|
+
if (telegramConfigured && !summary.channels.includes("telegram")) {
|
|
187
|
+
summary.channels.push("telegram");
|
|
188
|
+
io.print("本次未修改已有 Telegram 凭据。");
|
|
189
|
+
if (!hasItems(doc.getIn(["telegram", "allowedUsers"])) && !hasItems(doc.getIn(["telegram", "allowedChats"]))) {
|
|
190
|
+
io.print("现有 Telegram 仍会启用,需补上白名单。");
|
|
191
|
+
doc.setIn(["telegram", "allowedUsers"], await promptTelegramUsers(io, fetchImpl, resolveExisting(telegramToken), options));
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// Workspace root.
|
|
195
|
+
const currentRoot = String(doc.getIn(["workspaces", "root"]) ?? path.join(os.homedir(), "Projects"));
|
|
196
|
+
const answerRoot = await io.ask("项目根目录(Agent 默认在这里工作)", currentRoot);
|
|
197
|
+
const root = path.resolve(answerRoot.replace(/^~(?=$|\/)/, os.homedir()));
|
|
198
|
+
if (answerRoot !== currentRoot || !doc.hasIn(["workspaces", "root"]))
|
|
199
|
+
doc.setIn(["workspaces", "root"], root);
|
|
200
|
+
let createRoot = false;
|
|
201
|
+
if (!fs.existsSync(root)) {
|
|
202
|
+
createRoot = await io.confirm(`${root} 不存在,现在创建?`, true);
|
|
203
|
+
if (!createRoot)
|
|
204
|
+
throw new Error("项目目录不存在,初始化中止;原配置和密钥未修改");
|
|
205
|
+
}
|
|
206
|
+
// Default agent: installed CLIs, plus the current default (e.g. pi or a custom backend).
|
|
207
|
+
const installed = Object.entries(AGENT_COMMANDS).filter(([, commands]) => commands.some(hasCommand)).map(([id]) => id);
|
|
208
|
+
const current = String(doc.getIn(["defaultAgent"]) ?? "") || (existed ? String(doc.getIn(["defaultBackend"]) ?? "") : "");
|
|
209
|
+
const backends = doc.getIn(["backends"]);
|
|
210
|
+
const currentValid = Boolean(current) && (SUPPORTED_AGENT_IDS.includes(current) || backends?.has?.(current) === true);
|
|
211
|
+
const choices = [...new Set([...(currentValid ? [current] : []), ...installed])];
|
|
212
|
+
io.print(`已检测到的 Agent CLI:${installed.length ? installed.join("、") : "无"}`);
|
|
213
|
+
for (const [id, hint] of Object.entries(INSTALL_HINTS)) {
|
|
214
|
+
if (!installed.includes(id))
|
|
215
|
+
io.print(` 未安装 ${id}:${hint}`);
|
|
216
|
+
}
|
|
217
|
+
if (choices.length) {
|
|
218
|
+
let choice = "";
|
|
219
|
+
while (!choices.includes(choice)) {
|
|
220
|
+
choice = (await io.ask(`默认 Agent(${choices.join(" / ")})`, choices[0])).trim();
|
|
221
|
+
}
|
|
222
|
+
if (choice !== current) {
|
|
223
|
+
doc.setIn(["defaultAgent"], choice);
|
|
224
|
+
if (SUPPORTED_AGENT_IDS.includes(choice))
|
|
225
|
+
doc.setIn(["defaultBackend"], choice);
|
|
226
|
+
}
|
|
227
|
+
summary.defaultAgent = choice;
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
io.print("至少安装一个 Agent CLI 才能写代码;安装后重新运行 codebridge init 选择默认 Agent。");
|
|
231
|
+
}
|
|
232
|
+
// Validate before touching credentials. Each new item has its own name, so even a
|
|
233
|
+
// failed commit cannot replace a secret referenced by the live config/deployer.
|
|
234
|
+
io.checkCancelled();
|
|
235
|
+
const planned = [...pending.values()].map((entry) => ({
|
|
236
|
+
...entry, service: `${keychainServiceFor(entry.secretPath, dataDir)}.init-${randomBytes(12).toString("hex")}`,
|
|
237
|
+
}));
|
|
238
|
+
for (const entry of planned)
|
|
239
|
+
doc.setIn(entry.secretPath, `keychain:${entry.service}`);
|
|
240
|
+
const staged = stageConfig(configPath, doc.toString());
|
|
241
|
+
const stored = [];
|
|
242
|
+
let committed = false;
|
|
243
|
+
try {
|
|
244
|
+
for (const { secretPath, value, service } of planned) {
|
|
245
|
+
const name = secretPath.join(".");
|
|
246
|
+
let saved = false;
|
|
247
|
+
try {
|
|
248
|
+
storeKeychainSecret(service, value, options.secrets);
|
|
249
|
+
stored.push(service);
|
|
250
|
+
saved = resolveSecretRef(`keychain:${service}`, options.secrets) === value;
|
|
251
|
+
}
|
|
252
|
+
catch { /* Offer explicit plaintext fallback, without leaking helper errors. */ }
|
|
253
|
+
if (saved) {
|
|
254
|
+
summary.secretStorage[name] = "keychain";
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
if (stored.includes(service)) {
|
|
258
|
+
removeStagedSecret(service, options.secrets);
|
|
259
|
+
stored.splice(stored.indexOf(service), 1);
|
|
260
|
+
}
|
|
261
|
+
if (!(await io.confirm(`无法写入系统钥匙串,把 ${name} 明文写入 config.yaml(文件权限 600)?`, false))) {
|
|
262
|
+
throw new Error(`${name} 未保存,初始化中止;原配置和密钥未修改`);
|
|
263
|
+
}
|
|
264
|
+
doc.setIn(secretPath, value);
|
|
265
|
+
summary.secretStorage[name] = "plaintext";
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
io.checkCancelled();
|
|
269
|
+
fs.writeFileSync(staged.temporary, doc.toString());
|
|
270
|
+
if (createRoot)
|
|
271
|
+
fs.mkdirSync(root, { recursive: true });
|
|
272
|
+
fs.renameSync(staged.temporary, staged.target);
|
|
273
|
+
committed = true;
|
|
274
|
+
}
|
|
275
|
+
finally {
|
|
276
|
+
fs.rmSync(staged.temporary, { force: true });
|
|
277
|
+
if (!committed) {
|
|
278
|
+
const failed = [];
|
|
279
|
+
for (const service of stored) {
|
|
280
|
+
try {
|
|
281
|
+
removeStagedSecret(service, options.secrets);
|
|
282
|
+
}
|
|
283
|
+
catch {
|
|
284
|
+
failed.push(service);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (failed.length)
|
|
288
|
+
io.print(`未能清理新建钥匙串条目:${failed.join("、")};原配置引用的密钥未修改。`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return summary;
|
|
292
|
+
}
|
|
293
|
+
function hasItems(node) {
|
|
294
|
+
const items = node?.items;
|
|
295
|
+
return Array.isArray(node) ? node.length > 0 : Boolean(items?.length);
|
|
296
|
+
}
|
|
297
|
+
async function promptFeishu(doc, io, fetchImpl) {
|
|
298
|
+
const domain = String(process.env.FEISHU_DOMAIN ?? doc.getIn(["feishu", "domain"]) ?? "https://open.feishu.cn").replace(/\/$/, "");
|
|
299
|
+
io.print("飞书开放平台 → 企业自建应用 → 凭证与基础信息,复制 App ID 和 App Secret。");
|
|
300
|
+
for (let attempt = 1; attempt <= 3; attempt++) {
|
|
301
|
+
const current = String(doc.getIn(["feishu", "appId"]) ?? "");
|
|
302
|
+
const appId = (await io.ask("飞书 App ID(输入 /skip 跳过;无默认值时回车也可跳过)", current === "cli_placeholder" ? undefined : current)).trim();
|
|
303
|
+
if (!appId || appId === "/skip") {
|
|
304
|
+
io.print("已跳过飞书。");
|
|
305
|
+
return undefined;
|
|
306
|
+
}
|
|
307
|
+
const appSecret = (await io.askSecret("飞书 App Secret(输入不显示)")).trim();
|
|
308
|
+
if (!appSecret) {
|
|
309
|
+
io.print("已跳过飞书,本次不修改凭据。");
|
|
310
|
+
return undefined;
|
|
311
|
+
}
|
|
312
|
+
const problem = await verifyFeishu(fetchImpl, domain, appId, appSecret);
|
|
313
|
+
if (!problem) {
|
|
314
|
+
io.print("✓ 飞书凭据有效。");
|
|
315
|
+
io.print(" 还需在开放平台:开启机器人;开通 im:message、im:message:send_as_bot;事件订阅选长连接并添加 im.message.receive_v1。");
|
|
316
|
+
return { appId, appSecret };
|
|
317
|
+
}
|
|
318
|
+
io.print(`✗ 飞书凭据校验失败:${problem}`);
|
|
319
|
+
}
|
|
320
|
+
if (await io.confirm("飞书连续 3 次校验失败,跳过飞书、先完成其余配置?", true))
|
|
321
|
+
return undefined;
|
|
322
|
+
throw new Error("飞书凭据连续 3 次校验失败,初始化中止;原配置和密钥未修改");
|
|
323
|
+
}
|
|
324
|
+
async function verifyFeishu(fetchImpl, domain, appId, appSecret) {
|
|
325
|
+
// Never send the secret over plain HTTP.
|
|
326
|
+
if (!/^https:\/\//.test(domain))
|
|
327
|
+
return `feishu.domain 不是 https(${domain}),不发送密钥`;
|
|
328
|
+
try {
|
|
329
|
+
const response = await fetchImpl(`${domain}/open-apis/auth/v3/tenant_access_token/internal`, {
|
|
330
|
+
method: "POST",
|
|
331
|
+
redirect: "error",
|
|
332
|
+
headers: { "content-type": "application/json" },
|
|
333
|
+
body: JSON.stringify({ app_id: appId, app_secret: appSecret }),
|
|
334
|
+
signal: AbortSignal.timeout(10_000),
|
|
335
|
+
});
|
|
336
|
+
const body = await response.json().catch(() => ({}));
|
|
337
|
+
return response.ok && body.code === 0 ? undefined : `${body.msg ?? `HTTP ${response.status}`}(code ${body.code ?? "?"})`.replaceAll(appSecret, "[REDACTED]");
|
|
338
|
+
}
|
|
339
|
+
catch (error) {
|
|
340
|
+
return `无法连接 ${domain}:${error instanceof Error ? error.message : String(error)}`.replaceAll(appSecret, "[REDACTED]");
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
async function promptTelegram(io, fetchImpl, doc, options) {
|
|
344
|
+
io.print("在 Telegram 找 @BotFather,/newbot 后复制 bot token。");
|
|
345
|
+
for (let attempt = 1; attempt <= 3; attempt++) {
|
|
346
|
+
const token = (await io.askSecret("Telegram bot token(输入不显示,回车跳过 Telegram)")).trim();
|
|
347
|
+
if (!token) {
|
|
348
|
+
io.print("已跳过 Telegram。");
|
|
349
|
+
return undefined;
|
|
350
|
+
}
|
|
351
|
+
const bot = await telegramCall(fetchImpl, token, "getMe");
|
|
352
|
+
if (!bot.ok) {
|
|
353
|
+
io.print(`✗ Telegram token 校验失败:${bot.error}`);
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
io.print(`✓ 机器人 @${bot.result.username ?? "?"} 有效。`);
|
|
357
|
+
const existing = doc.getIn(["telegram", "allowedUsers"]);
|
|
358
|
+
const existingUsers = existing?.toJSON?.() ?? [];
|
|
359
|
+
const chats = doc.getIn(["telegram", "allowedChats"]);
|
|
360
|
+
const existingChats = chats?.toJSON?.() ?? [];
|
|
361
|
+
if ((existingUsers.length || existingChats.length) && await io.confirm(`保留现有白名单(用户:${existingUsers.join(", ") || "未限制"};聊天:${existingChats.join(", ") || "未限制"};选否将改用新用户白名单并清除原聊天限制)?`, true)) {
|
|
362
|
+
return { token, users: existingUsers.map(String), replaceChats: false };
|
|
363
|
+
}
|
|
364
|
+
return { token, users: await promptTelegramUsers(io, fetchImpl, token, options), replaceChats: true };
|
|
365
|
+
}
|
|
366
|
+
if (await io.confirm("Telegram 连续 3 次校验失败,跳过 Telegram、先完成其余配置?", true))
|
|
367
|
+
return undefined;
|
|
368
|
+
throw new Error("Telegram token 连续 3 次校验失败,初始化中止;原配置和密钥未修改");
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* At least one user id is required. Auto-detection binds to a one-time code the user sends
|
|
372
|
+
* in a private chat, so a stranger messaging the public bot can never be picked.
|
|
373
|
+
*/
|
|
374
|
+
async function promptTelegramUsers(io, fetchImpl, token, options) {
|
|
375
|
+
if (token && await io.confirm("自动识别你的 Telegram 用户 ID?(需要私聊机器人发一个验证码)", true)) {
|
|
376
|
+
const code = options.newCode?.() ?? `cb-${randomBytes(8).toString("hex")}`;
|
|
377
|
+
io.print(`在 Telegram 私聊你的机器人,发送这段验证码:${code}`);
|
|
378
|
+
await io.ask("发送后按回车继续", "");
|
|
379
|
+
let offset;
|
|
380
|
+
let match;
|
|
381
|
+
for (let page = 0; page < 10 && !match; page++) {
|
|
382
|
+
const updates = await telegramCall(fetchImpl, token, `getUpdates${offset === undefined ? "" : `?offset=${offset}`}`);
|
|
383
|
+
if (!updates.ok) {
|
|
384
|
+
io.print(`读取消息失败(${updates.error}),改为手动填写。`);
|
|
385
|
+
break;
|
|
386
|
+
}
|
|
387
|
+
match = updates.result.find((update) => update.message?.text?.trim() === code
|
|
388
|
+
&& update.message.chat?.type === "private" && update.message.from?.is_bot === false && update.message.from?.id);
|
|
389
|
+
if (match || updates.result.length < 100)
|
|
390
|
+
break;
|
|
391
|
+
offset = updates.result.at(-1).update_id + 1;
|
|
392
|
+
}
|
|
393
|
+
if (match) {
|
|
394
|
+
// Acknowledge, so the code is not delivered to the bridge as a prompt on first start.
|
|
395
|
+
const acknowledged = await telegramCall(fetchImpl, token, `getUpdates?offset=${match.update_id + 1}&limit=1`);
|
|
396
|
+
if (!acknowledged.ok)
|
|
397
|
+
throw new Error("Telegram 验证码消息未能确认,初始化中止以免它被当作任务执行;原配置和密钥未修改");
|
|
398
|
+
const from = match.message.from;
|
|
399
|
+
if (await io.confirm(`验证码来自 ${from.username ? `@${from.username} ` : ""}(${from.id}),只允许此人使用?`, false)) {
|
|
400
|
+
return [String(from.id)];
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
io.print("没有收到这段验证码的私聊消息,改为手动填写。");
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
for (;;) {
|
|
408
|
+
const ids = (await io.ask("允许使用的 Telegram 用户 ID(数字,逗号分隔;可问 @userinfobot)")).split(",").map((id) => id.trim()).filter(Boolean);
|
|
409
|
+
if (ids.length && ids.every((id) => /^\d+$/.test(id)))
|
|
410
|
+
return ids;
|
|
411
|
+
io.print("至少填写一个纯数字的用户 ID;不设白名单会让任何人都能操作你的电脑。");
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
async function telegramCall(fetchImpl, token, method) {
|
|
415
|
+
if (!/^\d+:[A-Za-z0-9_-]+$/.test(token))
|
|
416
|
+
return { ok: false, error: "格式应为 123456:ABC…" };
|
|
417
|
+
try {
|
|
418
|
+
const response = await fetchImpl(`https://api.telegram.org/bot${token}/${method}`, { redirect: "error", signal: AbortSignal.timeout(10_000) });
|
|
419
|
+
const body = await response.json().catch(() => ({}));
|
|
420
|
+
return response.ok && body.ok ? { ok: true, result: body.result } : { ok: false, error: (body.description ?? `HTTP ${response.status}`).replaceAll(token, "[REDACTED]") };
|
|
421
|
+
}
|
|
422
|
+
catch (error) {
|
|
423
|
+
return { ok: false, error: (error instanceof Error ? error.message : String(error)).replaceAll(token, "[REDACTED]") };
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
/** No history; discard pasted lines after Enter, including fragmented escape sequences. */
|
|
427
|
+
export function applyLineInput(state, chunk, secret) {
|
|
428
|
+
let buffer = state.buffer;
|
|
429
|
+
let escape = state.escape ?? "";
|
|
430
|
+
let echo = "";
|
|
431
|
+
for (const ch of chunk) {
|
|
432
|
+
if (escape) {
|
|
433
|
+
escape += ch;
|
|
434
|
+
if (escape.length === 2 && (ch === "[" || ch === "O"))
|
|
435
|
+
continue;
|
|
436
|
+
if (escape.length === 2 || /[@-~]/.test(ch))
|
|
437
|
+
escape = "";
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
if (ch === "\x1b") {
|
|
441
|
+
escape = ch;
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
if (ch === "\r" || ch === "\n")
|
|
445
|
+
return { buffer, done: true, cancelled: false, echo };
|
|
446
|
+
if (ch === "\u0003" || (ch === "\u0004" && !buffer))
|
|
447
|
+
return { buffer: "", done: true, cancelled: true, echo };
|
|
448
|
+
if (ch === "\u007f" || ch === "\b") {
|
|
449
|
+
if (buffer) {
|
|
450
|
+
buffer = [...buffer].slice(0, -1).join("");
|
|
451
|
+
if (!secret)
|
|
452
|
+
echo += "\b \b";
|
|
453
|
+
}
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
456
|
+
if (ch < " ")
|
|
457
|
+
continue;
|
|
458
|
+
buffer += ch;
|
|
459
|
+
if (!secret)
|
|
460
|
+
echo += ch;
|
|
461
|
+
}
|
|
462
|
+
return { buffer, escape, done: false, cancelled: false, echo };
|
|
463
|
+
}
|
|
464
|
+
/** Keep raw mode until close so type-ahead during network calls is never echoed. */
|
|
465
|
+
export function terminalIo() {
|
|
466
|
+
const stdin = process.stdin;
|
|
467
|
+
const wasRaw = stdin.isRaw;
|
|
468
|
+
let decoder = new StringDecoder("utf8");
|
|
469
|
+
let active;
|
|
470
|
+
let cancelled = false;
|
|
471
|
+
let pasting = false;
|
|
472
|
+
let discardPaste = false;
|
|
473
|
+
let marker = "";
|
|
474
|
+
const consume = (text) => {
|
|
475
|
+
if (text.includes("\u0003")) {
|
|
476
|
+
cancelled = true;
|
|
477
|
+
active?.reject(new Error("已取消初始化"));
|
|
478
|
+
active = undefined;
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
if (discardPaste)
|
|
482
|
+
return;
|
|
483
|
+
if (!active) {
|
|
484
|
+
if (text.includes("\u0003") || text.includes("\u0004"))
|
|
485
|
+
cancelled = true;
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
const next = applyLineInput(active.state, text, active.secret);
|
|
489
|
+
if (next.echo)
|
|
490
|
+
process.stdout.write(next.echo);
|
|
491
|
+
active.state = next;
|
|
492
|
+
if (!next.done)
|
|
493
|
+
return;
|
|
494
|
+
const pending = active;
|
|
495
|
+
active = undefined;
|
|
496
|
+
if (pasting)
|
|
497
|
+
discardPaste = true;
|
|
498
|
+
process.stdout.write("\n");
|
|
499
|
+
if (next.cancelled) {
|
|
500
|
+
cancelled = true;
|
|
501
|
+
pending.reject(new Error("已取消初始化"));
|
|
502
|
+
}
|
|
503
|
+
else
|
|
504
|
+
pending.resolve(next.buffer);
|
|
505
|
+
};
|
|
506
|
+
const onData = (chunk) => {
|
|
507
|
+
for (const ch of decoder.write(chunk)) {
|
|
508
|
+
if (marker || ch === "\x1b") {
|
|
509
|
+
marker += ch;
|
|
510
|
+
if (marker === "\x1b[200~") {
|
|
511
|
+
pasting = true;
|
|
512
|
+
marker = "";
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
if (marker === "\x1b[201~") {
|
|
516
|
+
pasting = false;
|
|
517
|
+
discardPaste = false;
|
|
518
|
+
marker = "";
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
521
|
+
if ("\x1b[200~".startsWith(marker) || "\x1b[201~".startsWith(marker))
|
|
522
|
+
continue;
|
|
523
|
+
consume(marker);
|
|
524
|
+
marker = "";
|
|
525
|
+
}
|
|
526
|
+
else
|
|
527
|
+
consume(ch);
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
const onEnd = () => {
|
|
531
|
+
cancelled = true;
|
|
532
|
+
active?.reject(new Error("终端输入已关闭,初始化中止"));
|
|
533
|
+
active = undefined;
|
|
534
|
+
};
|
|
535
|
+
stdin.setRawMode(true);
|
|
536
|
+
process.stdout.write("\x1b[?2004h");
|
|
537
|
+
stdin.on("data", onData);
|
|
538
|
+
stdin.on("end", onEnd);
|
|
539
|
+
stdin.resume();
|
|
540
|
+
const readLine = (prompt, secret) => new Promise((resolve, reject) => {
|
|
541
|
+
if (cancelled) {
|
|
542
|
+
reject(new Error("已取消初始化"));
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
decoder = new StringDecoder("utf8");
|
|
546
|
+
active = { secret, state: { buffer: "" }, resolve, reject };
|
|
547
|
+
process.stdout.write(prompt);
|
|
548
|
+
});
|
|
549
|
+
return {
|
|
550
|
+
checkCancelled: () => { if (cancelled)
|
|
551
|
+
throw new Error("已取消初始化"); },
|
|
552
|
+
print: (text) => process.stdout.write(`${text}\n`),
|
|
553
|
+
ask: async (question, defaultValue) => {
|
|
554
|
+
const answer = (await readLine(`${question}${defaultValue ? ` [${defaultValue}]` : ""}: `, false)).trim();
|
|
555
|
+
return answer || defaultValue || "";
|
|
556
|
+
},
|
|
557
|
+
askSecret: (question) => readLine(`${question}: `, true),
|
|
558
|
+
confirm: async (question, defaultYes) => {
|
|
559
|
+
const answer = (await readLine(`${question} ${defaultYes ? "[Y/n]" : "[y/N]"}: `, false)).trim().toLowerCase();
|
|
560
|
+
return answer ? answer.startsWith("y") : defaultYes;
|
|
561
|
+
},
|
|
562
|
+
close: () => {
|
|
563
|
+
stdin.off("data", onData);
|
|
564
|
+
stdin.off("end", onEnd);
|
|
565
|
+
process.stdout.write("\x1b[?2004l");
|
|
566
|
+
stdin.setRawMode(wasRaw ?? false);
|
|
567
|
+
stdin.pause();
|
|
568
|
+
},
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
//# sourceMappingURL=init-wizard.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import type { McpRuntime, McpServerRegistry } from "@codebridge/mcp-runtime";
|
|
3
|
+
export declare function createMcpApp(registry: McpServerRegistry, runtime: McpRuntime, token: string): Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">;
|
|
4
|
+
//# sourceMappingURL=mcp-api.d.ts.map
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
const RISKS = new Set([
|
|
3
|
+
"read_only",
|
|
4
|
+
"workspace_write",
|
|
5
|
+
"git_write",
|
|
6
|
+
"production_write",
|
|
7
|
+
]);
|
|
8
|
+
export function createMcpApp(registry, runtime, token) {
|
|
9
|
+
const app = new Hono();
|
|
10
|
+
app.use("/v1/*", async (c, next) => {
|
|
11
|
+
if (c.req.header("authorization") !== `Bearer ${token}`) {
|
|
12
|
+
return c.json({ error: { code: "unauthorized", message: "未授权" } }, 401);
|
|
13
|
+
}
|
|
14
|
+
await next();
|
|
15
|
+
});
|
|
16
|
+
app.get("/v1/mcp/servers", (c) => c.json({ servers: registry.listServers().map(toApiServer) }));
|
|
17
|
+
app.get("/v1/mcp/candidates", (c) => c.json({ candidates: registry.listCandidates().map(toApiCandidate) }));
|
|
18
|
+
app.post("/v1/mcp/servers/:server_id/discover", async (c) => {
|
|
19
|
+
try {
|
|
20
|
+
const candidates = await runtime.discover(c.req.param("server_id"));
|
|
21
|
+
return c.json({ candidates: candidates.map(toApiCandidate) });
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
const message = messageOf(error);
|
|
25
|
+
const status = message.includes("not found") ? 404 : 503;
|
|
26
|
+
return c.json({ error: { code: status === 404 ? "mcp_server_not_found" : "mcp_discovery_failed", message } }, status);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
app.post("/v1/mcp/candidates/:candidate_id/approve", async (c) => {
|
|
30
|
+
const body = await c.req.json().catch(() => null);
|
|
31
|
+
const risk = body?.risk;
|
|
32
|
+
if (risk !== undefined && (typeof risk !== "string" || !RISKS.has(risk))) {
|
|
33
|
+
return c.json({ error: { code: "invalid_capability_risk", message: "risk 无效" } }, 400);
|
|
34
|
+
}
|
|
35
|
+
const environments = body?.environments;
|
|
36
|
+
if (environments !== undefined && (!Array.isArray(environments) || environments.some((value) => typeof value !== "string" || !value.trim()))) {
|
|
37
|
+
return c.json({ error: { code: "invalid_environments", message: "environments 必须是非空字符串数组" } }, 400);
|
|
38
|
+
}
|
|
39
|
+
const input = {
|
|
40
|
+
capabilityId: typeof body?.capability_id === "string" && body.capability_id.trim() ? body.capability_id : undefined,
|
|
41
|
+
risk: risk,
|
|
42
|
+
environments: environments,
|
|
43
|
+
};
|
|
44
|
+
try {
|
|
45
|
+
return c.json(toApiCandidate(await runtime.approveCandidate(c.req.param("candidate_id"), input)));
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
const message = messageOf(error);
|
|
49
|
+
const status = message.includes("not found") ? 404 : 409;
|
|
50
|
+
return c.json({ error: { code: status === 404 ? "mcp_candidate_not_found" : "mcp_candidate_not_reviewable", message } }, status);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
app.post("/v1/mcp/candidates/:candidate_id/reject", (c) => {
|
|
54
|
+
try {
|
|
55
|
+
return c.json(toApiCandidate(registry.rejectCandidate(c.req.param("candidate_id"))));
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
return c.json({ error: { code: "mcp_candidate_not_found", message: messageOf(error) } }, 404);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return app;
|
|
62
|
+
}
|
|
63
|
+
function toApiServer(server) {
|
|
64
|
+
return {
|
|
65
|
+
id: server.id,
|
|
66
|
+
transport: server.transport,
|
|
67
|
+
command: server.command,
|
|
68
|
+
args: server.args ?? [],
|
|
69
|
+
url: server.url,
|
|
70
|
+
env: server.env ?? [],
|
|
71
|
+
revision: server.revision,
|
|
72
|
+
enabled: server.enabled,
|
|
73
|
+
health: {
|
|
74
|
+
status: server.health.status,
|
|
75
|
+
checked_at: server.health.checkedAt,
|
|
76
|
+
error: server.health.error,
|
|
77
|
+
},
|
|
78
|
+
updated_at: server.updatedAt,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function toApiCandidate(candidate) {
|
|
82
|
+
return {
|
|
83
|
+
id: candidate.id,
|
|
84
|
+
server_id: candidate.serverId,
|
|
85
|
+
tool_name: candidate.toolName,
|
|
86
|
+
description: candidate.description,
|
|
87
|
+
input_schema: candidate.inputSchema,
|
|
88
|
+
suggested_capability_id: candidate.suggestedCapabilityId,
|
|
89
|
+
adapter_id: candidate.adapterId,
|
|
90
|
+
risk: candidate.risk,
|
|
91
|
+
revision: candidate.revision,
|
|
92
|
+
status: candidate.status,
|
|
93
|
+
observed_at: candidate.observedAt,
|
|
94
|
+
reviewed_at: candidate.reviewedAt,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function messageOf(error) {
|
|
98
|
+
return error instanceof Error ? error.message : String(error);
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=mcp-api.js.map
|