@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,550 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { Readable, Writable } from "node:stream";
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import { methods, ndJsonStream, PROTOCOL_VERSION, } from "@agentclientprotocol/sdk";
|
|
6
|
+
import { mapSessionUpdate } from "./acp-event-mapper.js";
|
|
7
|
+
import { openActiveSession } from "./acp-active-session.js";
|
|
8
|
+
import { raceWithAbort } from "./acp-race.js";
|
|
9
|
+
import { createClaudeSessionActivityMarker } from "./acp-claude-activity.js";
|
|
10
|
+
import { ACP_CLIENT_CAPABILITIES, createHeadlessClientApp, } from "./headless-client.js";
|
|
11
|
+
import { killProcessTree } from "./acp-kill.js";
|
|
12
|
+
import { fileAttachmentPromptSuffix, partitionAttachments, } from "../attachment-prompt.js";
|
|
13
|
+
import { resolveAcpSpawn } from "./acp-spawn-profiles.js";
|
|
14
|
+
import { applySessionConfigOptions, resolveDesiredConfig, } from "./acp-config-options.js";
|
|
15
|
+
import { friendlyAuthErrorMessage } from "../auth-error-hints.js";
|
|
16
|
+
import { resourcesAlive, teardownResources, } from "./acp-session-pool.js";
|
|
17
|
+
export function supportsAcpSteering(response) {
|
|
18
|
+
const meta = response?._meta;
|
|
19
|
+
return meta?.steering?.supported === true;
|
|
20
|
+
}
|
|
21
|
+
export function steerAcpSession(agent, sessionId, prompt) {
|
|
22
|
+
return agent.request("_session/steering", {
|
|
23
|
+
sessionId,
|
|
24
|
+
prompt: [{ type: "text", text: prompt }],
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async function buildPromptBlocks(ctx) {
|
|
28
|
+
const { images, files } = partitionAttachments(ctx.attachments);
|
|
29
|
+
const blocks = [];
|
|
30
|
+
for (const att of images) {
|
|
31
|
+
const data = await fs.readFile(att.path, { encoding: "base64" });
|
|
32
|
+
blocks.push({
|
|
33
|
+
type: "image",
|
|
34
|
+
mimeType: att.mimeType ?? "image/png",
|
|
35
|
+
data,
|
|
36
|
+
uri: att.path,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
blocks.push({
|
|
40
|
+
type: "text",
|
|
41
|
+
text: ctx.prompt + fileAttachmentPromptSuffix(files),
|
|
42
|
+
});
|
|
43
|
+
return blocks;
|
|
44
|
+
}
|
|
45
|
+
function childToStream(child) {
|
|
46
|
+
if (!child.stdin || !child.stdout) {
|
|
47
|
+
throw new Error("ACP agent stdio pipes unavailable");
|
|
48
|
+
}
|
|
49
|
+
return ndJsonStream(Writable.toWeb(child.stdin), Readable.toWeb(child.stdout));
|
|
50
|
+
}
|
|
51
|
+
async function waitMs(ms, isAborted) {
|
|
52
|
+
const start = Date.now();
|
|
53
|
+
while (Date.now() - start < ms) {
|
|
54
|
+
if (isAborted())
|
|
55
|
+
return;
|
|
56
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** 长任务总上限;无输出与中途停滞由下面两个更短的 watchdog 独立处理。 */
|
|
60
|
+
const ACP_PROMPT_TIMEOUT_MS = 6 * 60 * 60 * 1000;
|
|
61
|
+
/** 从发 prompt 起这么久仍无任何输出,视为卡住(常见于 session/load 或看图);可经 config 覆盖 */
|
|
62
|
+
const ACP_NO_OUTPUT_TIMEOUT_MS = 10 * 60 * 1000;
|
|
63
|
+
/** 已有输出后这么久没有新事件,视为 mid-turn 卡死(如 tool 调用卡死);可经 config 覆盖 */
|
|
64
|
+
const ACP_STALL_TIMEOUT_MS = 30 * 60 * 1000;
|
|
65
|
+
const ACP_INIT_TIMEOUT_MS = 30_000;
|
|
66
|
+
// 后台子 agent(run_in_background)的 Task 工具在“启动即返回”时就 completed,stop 时并无
|
|
67
|
+
// 未闭合 tool_call;后台工作作为独立任务在 stop 之后继续产出 session_update。因此靠“探测”
|
|
68
|
+
// 判定是否真有后台:主轮起过 tool 才进 drain,probe 短窗内出现真实活动则切 quiet 长窗直到静默。
|
|
69
|
+
// 实测:首个后台事件约在 stop 后 +0.8s;后台过程内可静默十几秒(如 sub-agent 跑 sleep)。
|
|
70
|
+
const ACP_POST_STOP_PROBE_MS = 8 * 1000;
|
|
71
|
+
const ACP_POST_STOP_QUIET_MS = 75 * 1000;
|
|
72
|
+
const ACP_POST_STOP_MAX_MS = 20 * 60 * 1000;
|
|
73
|
+
function isActivityEvent(event) {
|
|
74
|
+
return (event.type === "text_delta" ||
|
|
75
|
+
event.type === "thought_delta" ||
|
|
76
|
+
event.type === "tool_start" ||
|
|
77
|
+
event.type === "tool_update" ||
|
|
78
|
+
event.type === "tool_end" ||
|
|
79
|
+
event.type === "plan" ||
|
|
80
|
+
event.type === "plan_update" ||
|
|
81
|
+
// 等用户 /approve 期间 wire 必然静默,权限请求本身算活动,免得 watchdog 误杀
|
|
82
|
+
event.type === "permission_request");
|
|
83
|
+
}
|
|
84
|
+
function withStderr(message, options) {
|
|
85
|
+
const stderr = options.readStderr?.().trim();
|
|
86
|
+
return stderr ? `${message}\n\n${stderr}` : message;
|
|
87
|
+
}
|
|
88
|
+
export async function* runActivePromptTurn(active, blocks, options) {
|
|
89
|
+
// 池模式跨轮接力同一个 carrier;非池模式局部(行为与旧版一致)
|
|
90
|
+
const carrier = options.updateCarrier ?? {
|
|
91
|
+
pending: null,
|
|
92
|
+
};
|
|
93
|
+
// 池复用:发新 prompt 之前先排干队列里已排队的消息——上一轮 drain 退出后仍到达的
|
|
94
|
+
// 后台产出(内容合法,照常 yield)与可能残留的陈旧 stop(丢弃,否则会被误判为新轮结束)。
|
|
95
|
+
// 有总时限:残余后台若持续以 <15ms 间隔产出,无上限的排干会把新 prompt 无限推迟、
|
|
96
|
+
// 且外部 /stop 也打不断(实测复现过)。到时限就带着残余进主循环,主循环本就能消化。
|
|
97
|
+
if (options.updateCarrier) {
|
|
98
|
+
const preDrainDeadline = Date.now() + 1_500;
|
|
99
|
+
while (!options.isAborted() && Date.now() < preDrainDeadline) {
|
|
100
|
+
carrier.pending ??= active.nextUpdate();
|
|
101
|
+
const got = await Promise.race([
|
|
102
|
+
carrier.pending.then((message) => ({ message }), () => "failed"),
|
|
103
|
+
new Promise((r) => setTimeout(() => r("empty"), 15)),
|
|
104
|
+
]);
|
|
105
|
+
if (got === "empty")
|
|
106
|
+
break;
|
|
107
|
+
carrier.pending = null;
|
|
108
|
+
if (got === "failed")
|
|
109
|
+
break; // 队列已失效,让主循环去暴露真实错误
|
|
110
|
+
if (got.message.kind === "session_update") {
|
|
111
|
+
if (got.message.update.sessionUpdate === "config_option_update") {
|
|
112
|
+
options.onConfigOptionsUpdate?.(got.message.update.configOptions);
|
|
113
|
+
}
|
|
114
|
+
for (const event of mapSessionUpdate(got.message.update)) {
|
|
115
|
+
yield event;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// kind === "stop":陈旧的上一轮结束信号,丢弃
|
|
119
|
+
// 队列可能持续有已就绪消息;让出一个 macrotask,保证 /stop 的 abort
|
|
120
|
+
// 以及进程信号能在预排干阶段被观察到,不被连续 resolved Promise 饿死。
|
|
121
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
122
|
+
}
|
|
123
|
+
if (options.isAborted())
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
for (const event of (await options.beforePrompt?.()) ?? []) {
|
|
127
|
+
yield event;
|
|
128
|
+
}
|
|
129
|
+
if (options.isAborted())
|
|
130
|
+
return;
|
|
131
|
+
void active.prompt(blocks);
|
|
132
|
+
const promptTimeoutMs = options.promptTimeoutMs ?? ACP_PROMPT_TIMEOUT_MS;
|
|
133
|
+
const noOutputTimeoutMs = options.noOutputTimeoutMs ?? ACP_NO_OUTPUT_TIMEOUT_MS;
|
|
134
|
+
const stallTimeoutMs = options.stallTimeoutMs ?? ACP_STALL_TIMEOUT_MS;
|
|
135
|
+
const postStopProbeMs = options.postStopProbeMs ?? ACP_POST_STOP_PROBE_MS;
|
|
136
|
+
const postStopQuietMs = options.postStopQuietMs ?? ACP_POST_STOP_QUIET_MS;
|
|
137
|
+
const postStopMaxMs = options.postStopMaxMs ?? ACP_POST_STOP_MAX_MS;
|
|
138
|
+
const drainEnabled = options.drainBackgroundWork ?? true;
|
|
139
|
+
let sawOutput = false;
|
|
140
|
+
const promptStartedAt = Date.now();
|
|
141
|
+
let lastActivityAt = promptStartedAt;
|
|
142
|
+
const noOutputTimeout = () => !sawOutput && Date.now() - promptStartedAt >= noOutputTimeoutMs;
|
|
143
|
+
// sawOutput 之后 120s watchdog 就不再生效,需要单独的 mid-turn 卡死检测
|
|
144
|
+
const stallTimeout = () => sawOutput && Date.now() - lastActivityAt >= stallTimeoutMs;
|
|
145
|
+
// "main" = 主 prompt 轮;"drain" = 主轮 stop 后续读后台子 agent 的 between-turn 输出。
|
|
146
|
+
// 只有本轮起过 tool(后台必经 Task 工具)才在 stop 后进 drain;纯对话轮 stop 即返回、零延迟。
|
|
147
|
+
let phase = "main";
|
|
148
|
+
let sawToolCall = false;
|
|
149
|
+
let drainStartAt = 0;
|
|
150
|
+
let lastDrainActivityAt = 0;
|
|
151
|
+
let drainConfirmed = false;
|
|
152
|
+
// 磁盘活动标记:节流读取(stat 很便宜但没必要每 40ms 一次)
|
|
153
|
+
let lastMarkerValue;
|
|
154
|
+
let lastMarkerCheckAt = 0;
|
|
155
|
+
const DRAIN_MARKER_INTERVAL_MS = 500;
|
|
156
|
+
let mainDeadline = promptStartedAt + promptTimeoutMs;
|
|
157
|
+
while (!options.isAborted()) {
|
|
158
|
+
// 带外事件(如权限请求):发生在连接回调里,经队列汇入本事件流
|
|
159
|
+
for (const oob of options.pollOutOfBandEvents?.() ?? []) {
|
|
160
|
+
if (isActivityEvent(oob)) {
|
|
161
|
+
sawOutput = true;
|
|
162
|
+
lastActivityAt = Date.now();
|
|
163
|
+
}
|
|
164
|
+
if (oob.type === "permission_request") {
|
|
165
|
+
// 等人回复不该撞总超时:至少留出比权限超时(8 分钟)更长的余量
|
|
166
|
+
mainDeadline = Math.max(mainDeadline, Date.now() + 10 * 60 * 1000);
|
|
167
|
+
}
|
|
168
|
+
yield oob;
|
|
169
|
+
}
|
|
170
|
+
if (phase === "main") {
|
|
171
|
+
if (Date.now() > mainDeadline) {
|
|
172
|
+
yield {
|
|
173
|
+
type: "error",
|
|
174
|
+
message: withStderr(`ACP 响应超时(${Math.round(promptTimeoutMs / 60000)} 分钟无结束信号)`, options),
|
|
175
|
+
fatal: true,
|
|
176
|
+
};
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
if (noOutputTimeout()) {
|
|
180
|
+
yield {
|
|
181
|
+
type: "error",
|
|
182
|
+
message: withStderr("ACP 长时间无任何输出(可能 agent 未登录、模型不可用或看图任务过慢)。", options),
|
|
183
|
+
fatal: true,
|
|
184
|
+
};
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
if (stallTimeout()) {
|
|
188
|
+
yield {
|
|
189
|
+
type: "error",
|
|
190
|
+
message: withStderr(`ACP 超过 ${Math.round(stallTimeoutMs / 60000)} 分钟无新事件(可能 tool 调用卡死)`, options),
|
|
191
|
+
fatal: true,
|
|
192
|
+
};
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
// drain 阶段:未确认前用 probe 短窗探后台;确认后用 quiet 长窗等静默;独立硬上限兜底。
|
|
198
|
+
// stall/noOutput 这类主轮 watchdog 不进入 drain:drain 期的静默是预期的(如 sub-agent 跑 sleep)。
|
|
199
|
+
// 磁盘活动标记:后台子 agent 写盘但 wire 静默时(transcript 在长、事件没来),
|
|
200
|
+
// 标记增长同样算活动——既能在 probe 窗内确认后台,也能刷新 quiet 计时防误切。
|
|
201
|
+
if (options.drainActivityMarker &&
|
|
202
|
+
Date.now() - lastMarkerCheckAt >= DRAIN_MARKER_INTERVAL_MS) {
|
|
203
|
+
lastMarkerCheckAt = Date.now();
|
|
204
|
+
const marker = options.drainActivityMarker();
|
|
205
|
+
if (marker !== undefined && marker !== lastMarkerValue) {
|
|
206
|
+
if (lastMarkerValue !== undefined) {
|
|
207
|
+
drainConfirmed = true;
|
|
208
|
+
lastDrainActivityAt = Date.now();
|
|
209
|
+
}
|
|
210
|
+
lastMarkerValue = marker;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (!drainConfirmed && Date.now() - drainStartAt >= postStopProbeMs) {
|
|
214
|
+
break; // 探不到真实后台活动 → 本轮无后台,干净返回
|
|
215
|
+
}
|
|
216
|
+
if (drainConfirmed && Date.now() - lastDrainActivityAt >= postStopQuietMs) {
|
|
217
|
+
break; // 后台真正静默 → 结束
|
|
218
|
+
}
|
|
219
|
+
if (Date.now() - drainStartAt >= postStopMaxMs) {
|
|
220
|
+
// 放弃仍在跑的后台任务:进程不可入池(否则失控任务借池续命,文案也成谎话)
|
|
221
|
+
options.markUnpoolable?.();
|
|
222
|
+
yield {
|
|
223
|
+
type: "error",
|
|
224
|
+
message: withStderr("ACP 后台任务超过 20 分钟仍未结束,已停止跟踪并终止该会话进程。", options),
|
|
225
|
+
fatal: false, // 主答已成功,这里只是停止跟踪,不算失败
|
|
226
|
+
};
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
// 必须跨迭代复用同一个 nextUpdate():每次调用都会在 SDK AsyncQueue 里注册一个
|
|
231
|
+
// waiter,被 race 抛弃的 waiter 仍排在 FIFO 前面,会把后续事件全部吞掉。
|
|
232
|
+
carrier.pending ??= active.nextUpdate();
|
|
233
|
+
const next = await Promise.race([
|
|
234
|
+
carrier.pending.then((message) => ({ message }), (err) => {
|
|
235
|
+
// /stop 拆资源会同步 fail 队列,rejection 必然抢在 isAborted 轮询前;
|
|
236
|
+
// 已中止时按干净退出处理,不把 dispose 噪音当成 fatal 错误往上抛。
|
|
237
|
+
if (options.isAborted())
|
|
238
|
+
return "aborted";
|
|
239
|
+
throw err;
|
|
240
|
+
}),
|
|
241
|
+
waitMs(40, options.isAborted).then(() => null),
|
|
242
|
+
]);
|
|
243
|
+
if (!next)
|
|
244
|
+
continue;
|
|
245
|
+
carrier.pending = null;
|
|
246
|
+
if (next === "aborted")
|
|
247
|
+
break;
|
|
248
|
+
if (next.message.kind === "session_update") {
|
|
249
|
+
const update = next.message.update;
|
|
250
|
+
if (update.sessionUpdate === "tool_call")
|
|
251
|
+
sawToolCall = true;
|
|
252
|
+
if (update.sessionUpdate === "config_option_update") {
|
|
253
|
+
options.onConfigOptionsUpdate?.(update.configOptions);
|
|
254
|
+
}
|
|
255
|
+
const events = mapSessionUpdate(update);
|
|
256
|
+
// drain 活动信号:映射出真实事件,或后台工具的进行中进度(in-progress tool_call_update
|
|
257
|
+
// 映射为空却代表后台工具仍在跑,须刷新静默计时,否则单个长工具会被 quiet 窗误切)。
|
|
258
|
+
// session_info_update / usage_update 这类噪音仍不算,避免普通轮次被尾随噪音误判为有后台。
|
|
259
|
+
const isDrainActivity = events.some(isActivityEvent) || update.sessionUpdate === "tool_call_update";
|
|
260
|
+
if (phase === "drain" && isDrainActivity) {
|
|
261
|
+
drainConfirmed = true;
|
|
262
|
+
lastDrainActivityAt = Date.now();
|
|
263
|
+
}
|
|
264
|
+
for (const event of events) {
|
|
265
|
+
if (isActivityEvent(event)) {
|
|
266
|
+
sawOutput = true;
|
|
267
|
+
lastActivityAt = Date.now();
|
|
268
|
+
}
|
|
269
|
+
yield event;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
else if (next.message.kind === "stop") {
|
|
273
|
+
if (phase !== "main")
|
|
274
|
+
break; // drain 期再遇 stop → 结束
|
|
275
|
+
if (drainEnabled && sawToolCall) {
|
|
276
|
+
phase = "drain";
|
|
277
|
+
drainStartAt = Date.now();
|
|
278
|
+
lastDrainActivityAt = drainStartAt;
|
|
279
|
+
drainConfirmed = false;
|
|
280
|
+
// 不 break,继续循环续读后台事件
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
break; // 无 tool(不可能有后台)或 drain 关闭 → 今天的即时返回行为
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (!options.updateCarrier) {
|
|
288
|
+
// 非池模式:进程即将被杀,pending 稍后因 dispose() reject,防御性吞掉。
|
|
289
|
+
// 池模式绝不能走到这:pending 已存在共享 carrier 上,由下一轮接力消费。
|
|
290
|
+
carrier.pending?.catch(() => { });
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
/** 复用匹配键:spawn 命令与关键 env 在进程启动时冻结,任一变化都不能复用 */
|
|
294
|
+
export function buildSessionMatchKeys(ctx) {
|
|
295
|
+
const profile = resolveAcpSpawn(ctx.backendConfig);
|
|
296
|
+
const canonicalMcpServers = (ctx.mcpServers ?? [])
|
|
297
|
+
.map((server) => ({
|
|
298
|
+
name: server.name,
|
|
299
|
+
command: server.command,
|
|
300
|
+
args: [...server.args],
|
|
301
|
+
env: Object.entries(server.env).sort(([left], [right]) => left.localeCompare(right)),
|
|
302
|
+
}))
|
|
303
|
+
.map((server) => JSON.stringify(server))
|
|
304
|
+
.sort();
|
|
305
|
+
return {
|
|
306
|
+
spawnKey: `${profile.command} ${profile.args.join(" ")}`,
|
|
307
|
+
envKey: `${ctx.extraEnv?.FCB_CHAT_ID ?? ""}|${ctx.extraEnv?.FCB_TOPIC_ID ?? ""}|${ctx.extraEnv?.FCB_RUN_ID ?? ""}`,
|
|
308
|
+
additionalDirectoriesKey: (ctx.additionalDirectories ?? []).join("\0"),
|
|
309
|
+
mcpServersKey: `sha256:${createHash("sha256")
|
|
310
|
+
.update(JSON.stringify(canonicalMcpServers))
|
|
311
|
+
.digest("hex")}`,
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
function acpMcpServers(ctx) {
|
|
315
|
+
return (ctx.mcpServers ?? []).map((server) => ({
|
|
316
|
+
name: server.name,
|
|
317
|
+
command: server.command,
|
|
318
|
+
args: [...server.args],
|
|
319
|
+
env: Object.entries(server.env).map(([name, value]) => ({ name, value })),
|
|
320
|
+
}));
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* 冷启动一个 ACP 会话的全部资源:spawn 适配器 → 连接 → initialize → 建/续会话。
|
|
324
|
+
* 权限决策器经 runtime 盒子间接读取——连接上的 handler 无法换装,而 requestDecision
|
|
325
|
+
* 是 per-run 闭包,必须每轮重绑(否则池复用后第二轮权限请求会调到第一轮的死闭包)。
|
|
326
|
+
* 失败时自行清理(杀进程/关连接)并把 stderr 摘要附在错误里抛出。
|
|
327
|
+
*/
|
|
328
|
+
async function openAcpSessionResources(ctx, options, onSpawn) {
|
|
329
|
+
const spawnProfile = resolveAcpSpawn(ctx.backendConfig);
|
|
330
|
+
const { spawnKey, envKey, additionalDirectoriesKey, mcpServersKey, } = buildSessionMatchKeys(ctx);
|
|
331
|
+
const child = spawn(spawnProfile.command, spawnProfile.args, {
|
|
332
|
+
cwd: ctx.cwd,
|
|
333
|
+
env: { ...process.env, ...ctx.extraEnv },
|
|
334
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
335
|
+
detached: true, // 自成进程组,killProcessTree 可 -pid 全组兜底(SIGKILL 不转发)
|
|
336
|
+
});
|
|
337
|
+
let stderr = "";
|
|
338
|
+
// 长时间任务下 stderr 会无界增长,只保留末尾 8 KiB 用于排障
|
|
339
|
+
const appendStderr = (chunk) => {
|
|
340
|
+
stderr += chunk;
|
|
341
|
+
if (stderr.length > 8192)
|
|
342
|
+
stderr = stderr.slice(-8192);
|
|
343
|
+
};
|
|
344
|
+
// 未监听 'error' 事件时 spawn 失败(如 ENOENT)会以 uncaught exception 炸掉整个进程
|
|
345
|
+
child.on("error", (err) => {
|
|
346
|
+
appendStderr(`${err.message}\n`);
|
|
347
|
+
});
|
|
348
|
+
child.stderr?.on("data", (d) => {
|
|
349
|
+
appendStderr(d.toString());
|
|
350
|
+
});
|
|
351
|
+
const childAlive = () => child.exitCode === null && child.signalCode === null;
|
|
352
|
+
const killChild = () => {
|
|
353
|
+
if (childAlive())
|
|
354
|
+
killProcessTree(child, "SIGTERM");
|
|
355
|
+
setTimeout(() => {
|
|
356
|
+
if (childAlive())
|
|
357
|
+
killProcessTree(child, "SIGKILL");
|
|
358
|
+
}, 2000).unref();
|
|
359
|
+
};
|
|
360
|
+
onSpawn(child, killChild);
|
|
361
|
+
let connection;
|
|
362
|
+
try {
|
|
363
|
+
const runtime = {
|
|
364
|
+
requestDecision: options.requestDecision,
|
|
365
|
+
};
|
|
366
|
+
const app = createHeadlessClientApp({
|
|
367
|
+
permissionPolicy: options.permissionPolicy,
|
|
368
|
+
requestDecision: (info) => runtime.requestDecision
|
|
369
|
+
? runtime.requestDecision(info)
|
|
370
|
+
: Promise.resolve(false),
|
|
371
|
+
});
|
|
372
|
+
const stream = childToStream(child);
|
|
373
|
+
connection = app.connect(stream);
|
|
374
|
+
const initializeResponse = await raceWithAbort(connection.agent.request(methods.agent.initialize, {
|
|
375
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
376
|
+
clientCapabilities: ACP_CLIENT_CAPABILITIES,
|
|
377
|
+
clientInfo: {
|
|
378
|
+
name: "codebridge",
|
|
379
|
+
version: "0.1.0",
|
|
380
|
+
},
|
|
381
|
+
}), options.isAborted, ACP_INIT_TIMEOUT_MS, "ACP initialize 超时");
|
|
382
|
+
const active = await openActiveSession(connection, ctx, ctx.backendConfig, {
|
|
383
|
+
isAborted: options.isAborted,
|
|
384
|
+
supportsAdditionalDirectories: initializeResponse.agentCapabilities?.sessionCapabilities
|
|
385
|
+
?.additionalDirectories != null,
|
|
386
|
+
mcpServers: acpMcpServers(ctx),
|
|
387
|
+
});
|
|
388
|
+
const resources = {
|
|
389
|
+
sessionId: active.sessionId,
|
|
390
|
+
child,
|
|
391
|
+
connection,
|
|
392
|
+
active,
|
|
393
|
+
cwd: ctx.cwd,
|
|
394
|
+
spawnKey,
|
|
395
|
+
envKey,
|
|
396
|
+
additionalDirectoriesKey,
|
|
397
|
+
mcpServersKey,
|
|
398
|
+
supportsSteering: supportsAcpSteering(initializeResponse),
|
|
399
|
+
supportsClose: initializeResponse.agentCapabilities?.sessionCapabilities?.close != null,
|
|
400
|
+
configOptions: [...(active.newSessionResponse.configOptions ?? [])],
|
|
401
|
+
readStderr: () => stderr,
|
|
402
|
+
carrier: { pending: null },
|
|
403
|
+
runtime,
|
|
404
|
+
};
|
|
405
|
+
return { resources };
|
|
406
|
+
}
|
|
407
|
+
catch (err) {
|
|
408
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
409
|
+
const detail = stderr.trim();
|
|
410
|
+
try {
|
|
411
|
+
connection?.close();
|
|
412
|
+
}
|
|
413
|
+
catch {
|
|
414
|
+
// 已关闭
|
|
415
|
+
}
|
|
416
|
+
killChild();
|
|
417
|
+
throw new Error(detail ? `${message}\n\n${detail}` : message);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
export async function* runAcpSession(ctx, options, outHandle) {
|
|
421
|
+
const pool = options.sessionPool;
|
|
422
|
+
const { spawnKey, envKey, additionalDirectoriesKey, mcpServersKey, } = buildSessionMatchKeys(ctx);
|
|
423
|
+
let resources;
|
|
424
|
+
if (pool?.enabled && ctx.resumeSessionId) {
|
|
425
|
+
resources =
|
|
426
|
+
pool.acquire(ctx.resumeSessionId, {
|
|
427
|
+
cwd: ctx.cwd,
|
|
428
|
+
spawnKey,
|
|
429
|
+
envKey,
|
|
430
|
+
additionalDirectoriesKey,
|
|
431
|
+
mcpServersKey,
|
|
432
|
+
}) ??
|
|
433
|
+
undefined;
|
|
434
|
+
}
|
|
435
|
+
const reused = resources !== undefined;
|
|
436
|
+
// healthy 只在轮子完整走完且无 fatal/abort 时为真;其余一律拆除(不归还池)
|
|
437
|
+
let healthy = false;
|
|
438
|
+
// drain 硬上限等路径会标记本轮资源不可入池(进程还活着但已不可信)
|
|
439
|
+
let poolable = true;
|
|
440
|
+
try {
|
|
441
|
+
if (!resources) {
|
|
442
|
+
const opened = await openAcpSessionResources(ctx, options, (child, kill) => {
|
|
443
|
+
// spawn 后立刻可取消(initialize/续聊阶段 /stop 也要能杀掉)
|
|
444
|
+
outHandle.current = { child, cancel: kill };
|
|
445
|
+
});
|
|
446
|
+
resources = opened.resources;
|
|
447
|
+
}
|
|
448
|
+
const r = resources;
|
|
449
|
+
outHandle.current = {
|
|
450
|
+
child: r.child,
|
|
451
|
+
...(r.supportsSteering
|
|
452
|
+
? {
|
|
453
|
+
steer: (prompt) => steerAcpSession(r.connection.agent, r.sessionId, prompt),
|
|
454
|
+
}
|
|
455
|
+
: {}),
|
|
456
|
+
cancel: () => {
|
|
457
|
+
void r.connection.agent
|
|
458
|
+
.notify(methods.agent.session.cancel, { sessionId: r.sessionId })
|
|
459
|
+
.catch(() => { });
|
|
460
|
+
// 只杀进程,不在此处 dispose/close:同步 fail 队列会抢在 isAborted 轮询前
|
|
461
|
+
// 把循环炸成伪 fatal("Active session disposed")。dispose/close 交给 finally
|
|
462
|
+
// 的 teardown(本轮已中止,healthy=false 必走拆除)。
|
|
463
|
+
killProcessTree(r.child, "SIGTERM");
|
|
464
|
+
const child = r.child;
|
|
465
|
+
setTimeout(() => {
|
|
466
|
+
if (child.exitCode === null && child.signalCode === null) {
|
|
467
|
+
killProcessTree(child, "SIGKILL");
|
|
468
|
+
}
|
|
469
|
+
}, 2000).unref();
|
|
470
|
+
},
|
|
471
|
+
};
|
|
472
|
+
yield { type: "session", sessionId: r.sessionId };
|
|
473
|
+
// 每轮重绑权限决策器(per-run 闭包;池复用时旧闭包已随上一轮失效)
|
|
474
|
+
r.runtime.requestDecision = options.requestDecision;
|
|
475
|
+
const blocks = await buildPromptBlocks(ctx);
|
|
476
|
+
let sawFatal = false;
|
|
477
|
+
for await (const event of runActivePromptTurn(r.active, blocks, {
|
|
478
|
+
...options,
|
|
479
|
+
markUnpoolable: () => {
|
|
480
|
+
poolable = false;
|
|
481
|
+
},
|
|
482
|
+
readStderr: r.readStderr,
|
|
483
|
+
// 池模式跨轮接力 pending waiter;复用轮先排干队列残留
|
|
484
|
+
updateCarrier: pool?.enabled ? r.carrier : undefined,
|
|
485
|
+
// claude 的后台子 agent 写盘不走 wire,用会话文件增长作 drain 的补充活动信号
|
|
486
|
+
drainActivityMarker: options.drainActivityMarker ??
|
|
487
|
+
(ctx.backendConfig.type === "claude-code"
|
|
488
|
+
? createClaudeSessionActivityMarker(ctx.cwd, r.sessionId)
|
|
489
|
+
: undefined),
|
|
490
|
+
onConfigOptionsUpdate: (configOptions) => {
|
|
491
|
+
r.configOptions = [...configOptions];
|
|
492
|
+
},
|
|
493
|
+
beforePrompt: async () => {
|
|
494
|
+
// 预排干会先消费跨轮残留的 config_option_update,之后再应用本轮 model/effort/mode;
|
|
495
|
+
// 这样池复用时使用的是最新能力快照,而非首次 session/new 的旧列表。
|
|
496
|
+
const desired = resolveDesiredConfig(ctx, options.permissionPolicy);
|
|
497
|
+
const result = await applySessionConfigOptions(r.connection.agent, r.sessionId, r.configOptions, desired, ctx.acpConfig);
|
|
498
|
+
r.configOptions = [...result.configOptions];
|
|
499
|
+
const events = result.warnings.map((message) => ({
|
|
500
|
+
type: "error",
|
|
501
|
+
message,
|
|
502
|
+
fatal: false,
|
|
503
|
+
}));
|
|
504
|
+
if (result.modelMismatch) {
|
|
505
|
+
events.push({
|
|
506
|
+
type: "model_resolved",
|
|
507
|
+
requested: result.modelMismatch.requested,
|
|
508
|
+
effective: result.modelMismatch.effective,
|
|
509
|
+
effectiveName: result.modelMismatch.effectiveName,
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
return events;
|
|
513
|
+
},
|
|
514
|
+
})) {
|
|
515
|
+
if (event.type === "error" && event.fatal)
|
|
516
|
+
sawFatal = true;
|
|
517
|
+
// 认证失败(OAuth 过期/未登录)常年只表现为一条不可操作的原始报错;这里就地改写成
|
|
518
|
+
// 「哪个后端 + 该在宿主机跑什么命令」,detail 保留原文不吞。命中的后端才有具体命令。
|
|
519
|
+
yield event.type === "error"
|
|
520
|
+
? { ...event, message: friendlyAuthErrorMessage(ctx.backendConfig.type, event.message) }
|
|
521
|
+
: event;
|
|
522
|
+
}
|
|
523
|
+
healthy = !sawFatal && !options.isAborted() && resourcesAlive(r);
|
|
524
|
+
}
|
|
525
|
+
catch (err) {
|
|
526
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
527
|
+
const detail = resources?.readStderr().trim() ?? "";
|
|
528
|
+
const combined = detail && !message.includes(detail) ? `${message}\n\n${detail}` : message;
|
|
529
|
+
yield {
|
|
530
|
+
type: "error",
|
|
531
|
+
message: friendlyAuthErrorMessage(ctx.backendConfig.type, combined),
|
|
532
|
+
fatal: true,
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
finally {
|
|
536
|
+
if (resources) {
|
|
537
|
+
// 防跨轮死闭包:轮末即解绑,池空闲期的权限请求直接按拒绝处理
|
|
538
|
+
resources.runtime.requestDecision = undefined;
|
|
539
|
+
if (healthy && poolable && pool?.enabled) {
|
|
540
|
+
pool.release(resources);
|
|
541
|
+
}
|
|
542
|
+
else {
|
|
543
|
+
teardownResources(resources);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
// reused 变量供将来遥测(冷/热轮次统计),当前无消费者
|
|
548
|
+
void reused;
|
|
549
|
+
}
|
|
550
|
+
//# sourceMappingURL=acp-session-runner.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type BackendProfile } from "@codebridge/core";
|
|
2
|
+
export interface AcpSpawnProfile {
|
|
3
|
+
command: string;
|
|
4
|
+
args: string[];
|
|
5
|
+
}
|
|
6
|
+
export declare function resolveAcpSpawn(profile: BackendProfile): AcpSpawnProfile;
|
|
7
|
+
/** Cursor 无 session/resume,续聊用 load;其余优先 resume */
|
|
8
|
+
export declare function acpContinueMethod(profile: BackendProfile): "session/load" | "session/resume";
|
|
9
|
+
//# sourceMappingURL=acp-spawn-profiles.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ACP_CLAUDE_AGENT_ACP_VERSION, ACP_CODEX_ACP_VERSION, } from "@codebridge/core";
|
|
2
|
+
const DEFAULTS = {
|
|
3
|
+
"cursor-cli": { command: "cursor-agent", args: ["acp"] },
|
|
4
|
+
"claude-code": {
|
|
5
|
+
command: "npx",
|
|
6
|
+
args: ["-y", `@agentclientprotocol/claude-agent-acp@${ACP_CLAUDE_AGENT_ACP_VERSION}`],
|
|
7
|
+
},
|
|
8
|
+
codex: {
|
|
9
|
+
command: "npx",
|
|
10
|
+
args: ["-y", `@agentclientprotocol/codex-acp@${ACP_CODEX_ACP_VERSION}`],
|
|
11
|
+
},
|
|
12
|
+
"generic-spawn": { command: "npx", args: [] },
|
|
13
|
+
};
|
|
14
|
+
export function resolveAcpSpawn(profile) {
|
|
15
|
+
if (profile.type === "pi-sdk") {
|
|
16
|
+
throw new Error("Pi SDK backend does not use an ACP spawn command");
|
|
17
|
+
}
|
|
18
|
+
const defaults = DEFAULTS[profile.type] ?? DEFAULTS["generic-spawn"];
|
|
19
|
+
return {
|
|
20
|
+
command: profile.acpCommand ?? defaults.command,
|
|
21
|
+
args: profile.acpArgs ?? defaults.args,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** Cursor 无 session/resume,续聊用 load;其余优先 resume */
|
|
25
|
+
export function acpContinueMethod(profile) {
|
|
26
|
+
return profile.type === "cursor-cli" ? "session/load" : "session/resume";
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=acp-spawn-profiles.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type ClientApp, type ClientCapabilities, type RequestPermissionRequest, type RequestPermissionResponse } from "@agentclientprotocol/sdk";
|
|
2
|
+
import type { AcpPermissionPolicy } from "@codebridge/core";
|
|
3
|
+
export interface HeadlessClientOptions {
|
|
4
|
+
permissionPolicy: AcpPermissionPolicy;
|
|
5
|
+
/**
|
|
6
|
+
* prompt_feishu 模式的决策等待器:把权限请求交给外界(飞书 /approve /deny),
|
|
7
|
+
* resolve true=允许 false=拒绝(含超时)。未提供时 prompt_feishu 退化为拒绝。
|
|
8
|
+
*/
|
|
9
|
+
requestDecision?: (info: {
|
|
10
|
+
title: string;
|
|
11
|
+
}) => Promise<boolean>;
|
|
12
|
+
}
|
|
13
|
+
export declare const ACP_CLIENT_CAPABILITIES: ClientCapabilities;
|
|
14
|
+
/** 从权限请求里提取给用户看的操作描述 */
|
|
15
|
+
export declare function permissionRequestTitle(params: RequestPermissionRequest): string;
|
|
16
|
+
export declare function pickAllowOption(params: RequestPermissionRequest): RequestPermissionResponse;
|
|
17
|
+
/** 流式 session/update 由 ActiveSession.nextUpdate() 接收,此处只处理权限 */
|
|
18
|
+
export declare function createHeadlessClientApp(options: HeadlessClientOptions): ClientApp;
|
|
19
|
+
//# sourceMappingURL=headless-client.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { client, methods, } from "@agentclientprotocol/sdk";
|
|
2
|
+
export const ACP_CLIENT_CAPABILITIES = {
|
|
3
|
+
fs: { readTextFile: false, writeTextFile: false },
|
|
4
|
+
plan: {},
|
|
5
|
+
session: { configOptions: { boolean: {} } },
|
|
6
|
+
};
|
|
7
|
+
/** 从权限请求里提取给用户看的操作描述 */
|
|
8
|
+
export function permissionRequestTitle(params) {
|
|
9
|
+
const toolCall = params.toolCall;
|
|
10
|
+
return toolCall?.title || toolCall?.kind || "工具操作";
|
|
11
|
+
}
|
|
12
|
+
export function pickAllowOption(params) {
|
|
13
|
+
const options = params.options ?? [];
|
|
14
|
+
const byKind = (kind) => options.find((o) => o.kind === kind);
|
|
15
|
+
const allow = byKind("allow_once") ?? byKind("allow_always");
|
|
16
|
+
if (!allow) {
|
|
17
|
+
return {
|
|
18
|
+
outcome: { outcome: "cancelled" },
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
outcome: {
|
|
23
|
+
outcome: "selected",
|
|
24
|
+
optionId: allow.optionId,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** 流式 session/update 由 ActiveSession.nextUpdate() 接收,此处只处理权限 */
|
|
29
|
+
export function createHeadlessClientApp(options) {
|
|
30
|
+
return client({ name: "codebridge" })
|
|
31
|
+
.onRequest(methods.client.session.requestPermission, async (ctx) => {
|
|
32
|
+
if (options.permissionPolicy === "auto_allow") {
|
|
33
|
+
return pickAllowOption(ctx.params);
|
|
34
|
+
}
|
|
35
|
+
if (options.permissionPolicy === "prompt_feishu" &&
|
|
36
|
+
options.requestDecision) {
|
|
37
|
+
const approved = await options.requestDecision({
|
|
38
|
+
title: permissionRequestTitle(ctx.params),
|
|
39
|
+
});
|
|
40
|
+
return approved
|
|
41
|
+
? pickAllowOption(ctx.params)
|
|
42
|
+
: { outcome: { outcome: "cancelled" } };
|
|
43
|
+
}
|
|
44
|
+
return { outcome: { outcome: "cancelled" } };
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=headless-client.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { resolveAcpSpawn, acpContinueMethod, type AcpSpawnProfile, } from "./acp-spawn-profiles.js";
|
|
2
|
+
export { mapSessionUpdate } from "./acp-event-mapper.js";
|
|
3
|
+
export { createHeadlessClientApp } from "./headless-client.js";
|
|
4
|
+
export { runAcpSession, type AcpRunHandle, type AcpRunOptions, } from "./acp-session-runner.js";
|
|
5
|
+
export { deleteAcpSession, loadAcpSessionHistory, listAcpConfigOptions, listAcpSessions, probeAcpInitialize, } from "./acp-session-list.js";
|
|
6
|
+
export { detectBackend } from "./acp-doctor.js";
|
|
7
|
+
export { killProcessTree } from "./acp-kill.js";
|
|
8
|
+
export { AcpSessionPool, type AcpSessionPoolOptions, type AcpSessionResources, } from "./acp-session-pool.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|