vessel-agent 0.0.0-stage → 2.3.0-beta.2
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/LICENSE +21 -0
- package/README.md +466 -2
- package/README.zh-CN.md +476 -0
- package/apps/web/dist/Vela.png +0 -0
- package/apps/web/dist/Vessel.svg +24 -0
- package/apps/web/dist/apple-touch-icon.png +0 -0
- package/apps/web/dist/assets/ConfigView-BKdxb1s5.js +1 -0
- package/apps/web/dist/assets/DesignLabContent-CY5HfVn_.js +4 -0
- package/apps/web/dist/assets/DesignLabView-DTBWv5-E.js +1 -0
- package/apps/web/dist/assets/action-menu.preview-CpIL3tay.js +1 -0
- package/apps/web/dist/assets/agent-message.preview-CSYnJxgr.js +1 -0
- package/apps/web/dist/assets/assistant-text.preview-Bc2Is6sW.js +2 -0
- package/apps/web/dist/assets/badges.preview-DP0oPcs5.js +1 -0
- package/apps/web/dist/assets/buttons.preview-Y84aT4k3.js +1 -0
- package/apps/web/dist/assets/card-shell.preview-mwRwhVb8.js +1 -0
- package/apps/web/dist/assets/chip-tones.preview-dQ_6pwft.js +1 -0
- package/apps/web/dist/assets/composer-controls.preview-CBtJVrMo.js +1 -0
- package/apps/web/dist/assets/confirm-dialog.preview-BkNEtLld.js +1 -0
- package/apps/web/dist/assets/data-table.preview-DPZ7Pnn8.js +1 -0
- package/apps/web/dist/assets/depth-color.preview-CtCbAgCH.js +1 -0
- package/apps/web/dist/assets/entity-header.preview-BxPLNUSH.js +1 -0
- package/apps/web/dist/assets/env-card.preview-Bv4UlMjr.js +1 -0
- package/apps/web/dist/assets/failure-card.preview-DD3-RMju.js +1 -0
- package/apps/web/dist/assets/filter-popover.preview-D7Q7Kws8.js +1 -0
- package/apps/web/dist/assets/form.preview-D_Qltx-j.js +1 -0
- package/apps/web/dist/assets/index-ee36IO2F.js +600 -0
- package/apps/web/dist/assets/index-uU9N5oTa.css +1 -0
- package/apps/web/dist/assets/key-value.preview-B0gzxwtK.js +1 -0
- package/apps/web/dist/assets/mention-popover.preview-Duza1RgL.js +1 -0
- package/apps/web/dist/assets/message-fold.preview-Cx-CD3Y4.js +1 -0
- package/apps/web/dist/assets/modal-shell.preview-DYKwUk2S.js +1 -0
- package/apps/web/dist/assets/nav-item.preview-FTbsBQ2g.js +1 -0
- package/apps/web/dist/assets/nav-status-legend.preview-bS4LDFbd.js +1 -0
- package/apps/web/dist/assets/page-scaffold.preview-bzBFkjZ6.js +1 -0
- package/apps/web/dist/assets/plugin-ui-BxTydP3l.js +1 -0
- package/apps/web/dist/assets/projection-card.preview-BV0P-y8e.js +6 -0
- package/apps/web/dist/assets/queued.preview-zQqFe4Zr.js +1 -0
- package/apps/web/dist/assets/react-vendor-CUu194FT.js +9 -0
- package/apps/web/dist/assets/reasoning.preview-DtHXgW_8.js +2 -0
- package/apps/web/dist/assets/section.preview-A-PRm-rh.js +1 -0
- package/apps/web/dist/assets/sidebar-shell.preview-DFKMwNoo.js +1 -0
- package/apps/web/dist/assets/stat.preview-BzChSFLL.js +1 -0
- package/apps/web/dist/assets/states.preview-CyXZWnZ-.js +1 -0
- package/apps/web/dist/assets/status-icons.preview-DHdWwUis.js +1 -0
- package/apps/web/dist/assets/tabs.preview-CHbK1Two.js +1 -0
- package/apps/web/dist/assets/tool-card.preview-Z48fekTD.js +2 -0
- package/apps/web/dist/assets/toolbar.preview-Bl6hLYXX.js +1 -0
- package/apps/web/dist/assets/tooltip.preview-GKGTGfMP.js +1 -0
- package/apps/web/dist/assets/user-bubble.preview-CHYvio9z.js +1 -0
- package/apps/web/dist/assets/vendor/jsx-runtime.mjs +7 -0
- package/apps/web/dist/assets/vendor/plugin-sdk.mjs +12 -0
- package/apps/web/dist/assets/vendor/react-dom-client.mjs +6 -0
- package/apps/web/dist/assets/vendor/react-dom.mjs +11 -0
- package/apps/web/dist/assets/vendor/react.mjs +39 -0
- package/apps/web/dist/build.json +5 -0
- package/apps/web/dist/favicon.ico +0 -0
- package/apps/web/dist/index.html +24 -0
- package/package.json +70 -4
- package/packages/agent/package.json +32 -0
- package/packages/agent/src/address-display.ts +141 -0
- package/packages/agent/src/conversation-budget.ts +651 -0
- package/packages/agent/src/conversation-store.ts +351 -0
- package/packages/agent/src/distress.ts +161 -0
- package/packages/agent/src/env-info-scope.ts +153 -0
- package/packages/agent/src/error-text.ts +28 -0
- package/packages/agent/src/inbox-source.ts +73 -0
- package/packages/agent/src/inbox.ts +2335 -0
- package/packages/agent/src/index.ts +273 -0
- package/packages/agent/src/member-cwd.ts +128 -0
- package/packages/agent/src/member-ports.ts +162 -0
- package/packages/agent/src/refs.ts +51 -0
- package/packages/agent/src/registry.ts +741 -0
- package/packages/agent/src/runtime.ts +2501 -0
- package/packages/agent/src/self-card-delta.ts +428 -0
- package/packages/agent/src/service.ts +9212 -0
- package/packages/agent/src/snapshot.ts +614 -0
- package/packages/agent/src/team-address.ts +96 -0
- package/packages/agent/src/team-log.ts +487 -0
- package/packages/agent/src/team-service.ts +1966 -0
- package/packages/agent/src/team-slug.ts +167 -0
- package/packages/agent/src/team-store.ts +619 -0
- package/packages/agent/src/tool.ts +1306 -0
- package/packages/agent/src/types/budget.ts +168 -0
- package/packages/agent/src/types/constants.ts +17 -0
- package/packages/agent/src/types/dispatch.ts +133 -0
- package/packages/agent/src/types/events.ts +132 -0
- package/packages/agent/src/types/execution.ts +289 -0
- package/packages/agent/src/types/lifecycle.ts +372 -0
- package/packages/agent/src/types/member.ts +221 -0
- package/packages/agent/src/types/message.ts +113 -0
- package/packages/agent/src/types/results.ts +64 -0
- package/packages/agent/src/types/roster.ts +137 -0
- package/packages/agent/src/types/service.ts +702 -0
- package/packages/agent/src/types/session.ts +102 -0
- package/packages/agent/src/types/team.ts +558 -0
- package/packages/agent/src/types.ts +22 -0
- package/packages/agent/tsconfig.json +8 -0
- package/packages/config/package.json +32 -0
- package/packages/config/src/auth-origins.ts +85 -0
- package/packages/config/src/auth-strategies/avatar-ref.ts +40 -0
- package/packages/config/src/auth-strategies/gitee.ts +72 -0
- package/packages/config/src/auth-strategies/github.ts +64 -0
- package/packages/config/src/auth-strategies/index.ts +47 -0
- package/packages/config/src/auth-strategies/match.ts +82 -0
- package/packages/config/src/auth-strategies/microsoft.ts +100 -0
- package/packages/config/src/auth-strategies/oauth-exchange.ts +192 -0
- package/packages/config/src/auth-strategies/password.ts +34 -0
- package/packages/config/src/auth-strategies/registry.ts +105 -0
- package/packages/config/src/auth-strategies/shapes.ts +138 -0
- package/packages/config/src/auth-strategies/types.ts +190 -0
- package/packages/config/src/auth.ts +305 -0
- package/packages/config/src/config-lock.ts +328 -0
- package/packages/config/src/defaults.ts +271 -0
- package/packages/config/src/env-file.ts +175 -0
- package/packages/config/src/env-injection.ts +117 -0
- package/packages/config/src/explain.ts +283 -0
- package/packages/config/src/gateway.ts +107 -0
- package/packages/config/src/index.ts +253 -0
- package/packages/config/src/loader.ts +871 -0
- package/packages/config/src/model-migration.ts +534 -0
- package/packages/config/src/model-registry.ts +374 -0
- package/packages/config/src/models-disk.ts +72 -0
- package/packages/config/src/models-validation.ts +467 -0
- package/packages/config/src/node-registration.ts +583 -0
- package/packages/config/src/root-secret.ts +402 -0
- package/packages/config/src/secrets.ts +452 -0
- package/packages/config/src/sources.ts +82 -0
- package/packages/config/src/team-policy.ts +422 -0
- package/packages/config/src/types/agent.ts +263 -0
- package/packages/config/src/types/attention.ts +28 -0
- package/packages/config/src/types/auth.ts +126 -0
- package/packages/config/src/types/connect.ts +21 -0
- package/packages/config/src/types/hub.ts +59 -0
- package/packages/config/src/types/models.ts +153 -0
- package/packages/config/src/types/node.ts +202 -0
- package/packages/config/src/types/observability.ts +84 -0
- package/packages/config/src/types/root.ts +240 -0
- package/packages/config/src/types/runtime.ts +123 -0
- package/packages/config/src/types/security.ts +43 -0
- package/packages/config/src/types/serve.ts +34 -0
- package/packages/config/src/types/snapshot.ts +28 -0
- package/packages/config/src/types/team.ts +112 -0
- package/packages/config/src/types/ui.ts +179 -0
- package/packages/config/src/types.ts +22 -0
- package/packages/config/src/user-config.ts +175 -0
- package/packages/config/src/utils.ts +55 -0
- package/packages/config/src/validator/auth.ts +302 -0
- package/packages/config/src/validator/hub.ts +329 -0
- package/packages/config/src/validator/models.ts +1304 -0
- package/packages/config/src/validator/serve.ts +784 -0
- package/packages/config/src/validator/settings.ts +244 -0
- package/packages/config/src/validator/shared.ts +304 -0
- package/packages/config/src/validator/tenant-keys.ts +91 -0
- package/packages/config/src/validator/unknown-keys.ts +452 -0
- package/packages/config/src/validator.ts +1146 -0
- package/packages/config/tsconfig.json +8 -0
- package/packages/core/package.json +38 -0
- package/packages/core/src/context/anchor.ts +57 -0
- package/packages/core/src/context/archive-notice.ts +283 -0
- package/packages/core/src/context/cleared-tool-result.ts +262 -0
- package/packages/core/src/context/compaction-index.ts +381 -0
- package/packages/core/src/context/composition.ts +251 -0
- package/packages/core/src/context/context-manager.ts +1585 -0
- package/packages/core/src/context/context-notice.ts +218 -0
- package/packages/core/src/context/index.ts +220 -0
- package/packages/core/src/context/model-change-notice.ts +81 -0
- package/packages/core/src/context/projection-policy.ts +719 -0
- package/packages/core/src/context/prompt-context.ts +66 -0
- package/packages/core/src/context/read-side-mask.ts +63 -0
- package/packages/core/src/context/request-sequence.ts +423 -0
- package/packages/core/src/context/request-view.ts +256 -0
- package/packages/core/src/context/session-breaker.ts +100 -0
- package/packages/core/src/context/tool-result-whitelist.ts +135 -0
- package/packages/core/src/events/event-stream.ts +271 -0
- package/packages/core/src/events/file-event-store.ts +119 -0
- package/packages/core/src/events/index.ts +15 -0
- package/packages/core/src/events/replay.ts +82 -0
- package/packages/core/src/events/summarize-event.ts +135 -0
- package/packages/core/src/index.ts +475 -0
- package/packages/core/src/kernel/cancellation.ts +54 -0
- package/packages/core/src/kernel/event-bus.ts +65 -0
- package/packages/core/src/kernel/index.ts +32 -0
- package/packages/core/src/kernel/internal.ts +32 -0
- package/packages/core/src/kernel/scheduler.ts +406 -0
- package/packages/core/src/kernel/types.ts +269 -0
- package/packages/core/src/limits/index.ts +23 -0
- package/packages/core/src/limits/limit-checker.ts +270 -0
- package/packages/core/src/limits/limit-error.ts +29 -0
- package/packages/core/src/log-format.ts +722 -0
- package/packages/core/src/log-hub.ts +278 -0
- package/packages/core/src/logging.ts +64 -0
- package/packages/core/src/observability/index.ts +24 -0
- package/packages/core/src/observability/metrics.ts +279 -0
- package/packages/core/src/observability/read-trace.ts +163 -0
- package/packages/core/src/observability/rebuild-metrics.ts +37 -0
- package/packages/core/src/observability/trace-prune.ts +248 -0
- package/packages/core/src/observability/trace-recorder.ts +484 -0
- package/packages/core/src/observability/trace-redactor.ts +93 -0
- package/packages/core/src/pii/index.ts +88 -0
- package/packages/core/src/pii/notice.ts +156 -0
- package/packages/core/src/pii/reveal.ts +198 -0
- package/packages/core/src/pii/rules.ts +545 -0
- package/packages/core/src/pii/types.ts +140 -0
- package/packages/core/src/pii/vault.ts +764 -0
- package/packages/core/src/provider/errors.ts +41 -0
- package/packages/core/src/provider/index.ts +19 -0
- package/packages/core/src/provider/providers.ts +1011 -0
- package/packages/core/src/provider/request-extras.ts +285 -0
- package/packages/core/src/provider/stream-accumulator.ts +168 -0
- package/packages/core/src/provider/usage.ts +112 -0
- package/packages/core/src/runtime/error-envelope.ts +451 -0
- package/packages/core/src/runtime/error-summary.ts +174 -0
- package/packages/core/src/runtime/execution-unit.ts +6675 -0
- package/packages/core/src/runtime/guardrail-runner.ts +86 -0
- package/packages/core/src/runtime/hook-runner.ts +137 -0
- package/packages/core/src/runtime/index.ts +123 -0
- package/packages/core/src/runtime/permission-policy.ts +267 -0
- package/packages/core/src/runtime/plugin-host.ts +489 -0
- package/packages/core/src/runtime/plugin-install.ts +144 -0
- package/packages/core/src/runtime/policy/index.ts +21 -0
- package/packages/core/src/runtime/prompt-prefix-guard.ts +166 -0
- package/packages/core/src/runtime/provider-retry.ts +220 -0
- package/packages/core/src/runtime/resume-markers.ts +114 -0
- package/packages/core/src/runtime/resume-recovery.ts +164 -0
- package/packages/core/src/runtime/run-journal.ts +382 -0
- package/packages/core/src/runtime/run-timing.ts +217 -0
- package/packages/core/src/runtime/runtime.ts +349 -0
- package/packages/core/src/runtime/safepoint-pause.ts +29 -0
- package/packages/core/src/runtime/tool-attachment.ts +170 -0
- package/packages/core/src/runtime/tool-calling-loop.ts +1219 -0
- package/packages/core/src/runtime/tool-name.ts +215 -0
- package/packages/core/src/runtime/tool-pipeline.ts +459 -0
- package/packages/core/src/runtime/tool-provenance.ts +48 -0
- package/packages/core/src/runtime/tool-result-gate.ts +329 -0
- package/packages/core/src/session/atomic-write.ts +335 -0
- package/packages/core/src/session/compaction-index-derive.ts +173 -0
- package/packages/core/src/session/compaction-index-store.ts +161 -0
- package/packages/core/src/session/compaction-recall.ts +375 -0
- package/packages/core/src/session/delete-session.ts +198 -0
- package/packages/core/src/session/file-backend.ts +1311 -0
- package/packages/core/src/session/index.ts +118 -0
- package/packages/core/src/session/message-identity.ts +272 -0
- package/packages/core/src/session/project-messages.ts +908 -0
- package/packages/core/src/session/projection-cache.ts +254 -0
- package/packages/core/src/session/prune.ts +153 -0
- package/packages/core/src/session/run-record-store.ts +307 -0
- package/packages/core/src/session/session-index.ts +158 -0
- package/packages/core/src/session/session-log-dir.ts +39 -0
- package/packages/core/src/session/session-store.ts +266 -0
- package/packages/core/src/session/sqlite-backend.ts +391 -0
- package/packages/core/src/socket-inherit-guard.ts +188 -0
- package/packages/core/src/storage/metadata-sidecar.ts +124 -0
- package/packages/core/src/tenant/index.ts +13 -0
- package/packages/core/src/tenant/resolve-tenant.ts +19 -0
- package/packages/core/src/tenant/tenant-paths.ts +83 -0
- package/packages/core/src/timeline/archive-audit.ts +316 -0
- package/packages/core/src/timeline/archive-lock.ts +124 -0
- package/packages/core/src/timeline/blocks.ts +1639 -0
- package/packages/core/src/timeline/enum-stats.ts +34 -0
- package/packages/core/src/timeline/holes.ts +431 -0
- package/packages/core/src/timeline/index.ts +387 -0
- package/packages/core/src/timeline/legacy-format.ts +97 -0
- package/packages/core/src/timeline/read-port.ts +582 -0
- package/packages/core/src/timeline/types.ts +371 -0
- package/packages/core/src/timeline/wal.ts +2485 -0
- package/packages/core/src/timeline/writer.ts +2079 -0
- package/packages/core/src/timeout.ts +93 -0
- package/packages/core/src/transport/in-process.ts +86 -0
- package/packages/core/src/transport/index.ts +6 -0
- package/packages/core/src/types/context.ts +229 -0
- package/packages/core/src/types/env-cadence.ts +35 -0
- package/packages/core/src/types/error-registry.ts +343 -0
- package/packages/core/src/types/error.ts +107 -0
- package/packages/core/src/types/event.ts +496 -0
- package/packages/core/src/types/guardrail.ts +35 -0
- package/packages/core/src/types/hook.ts +122 -0
- package/packages/core/src/types/index.ts +28 -0
- package/packages/core/src/types/lease.ts +91 -0
- package/packages/core/src/types/limits.ts +112 -0
- package/packages/core/src/types/logging.ts +54 -0
- package/packages/core/src/types/member-port.ts +194 -0
- package/packages/core/src/types/plugin.ts +392 -0
- package/packages/core/src/types/projection-cache.ts +80 -0
- package/packages/core/src/types/projection.ts +100 -0
- package/packages/core/src/types/provider.ts +319 -0
- package/packages/core/src/types/run-journal.ts +178 -0
- package/packages/core/src/types/run-record-store.ts +128 -0
- package/packages/core/src/types/run.ts +140 -0
- package/packages/core/src/types/session.ts +328 -0
- package/packages/core/src/types/source-module.ts +68 -0
- package/packages/core/src/types/tenant.ts +41 -0
- package/packages/core/src/types/tool-name.ts +57 -0
- package/packages/core/src/types/tool.ts +122 -0
- package/packages/core/src/types/trace.ts +38 -0
- package/packages/core/src/types/vision.ts +219 -0
- package/packages/core/src/vision/blobs.ts +328 -0
- package/packages/core/src/vision/index.ts +73 -0
- package/packages/core/src/vision/ingest.ts +126 -0
- package/packages/core/src/vision/notice.ts +58 -0
- package/packages/core/src/vision/plan.ts +358 -0
- package/packages/core/src/vision/staging.ts +81 -0
- package/packages/core/tsconfig.json +8 -0
- package/packages/permission/package.json +31 -0
- package/packages/permission/src/index.ts +60 -0
- package/packages/plugin-sdk/package.json +21 -0
- package/packages/plugin-sdk/src/index.ts +478 -0
- package/packages/plugin-sdk/src/semver.ts +154 -0
- package/packages/plugin-ui/package.json +33 -0
- package/packages/plugin-ui/src/Badge.tsx +41 -0
- package/packages/plugin-ui/src/Button.tsx +84 -0
- package/packages/plugin-ui/src/ComposerAttachments.tsx +87 -0
- package/packages/plugin-ui/src/ComposerContextMeter.tsx +209 -0
- package/packages/plugin-ui/src/ComposerToolbar.tsx +233 -0
- package/packages/plugin-ui/src/CountBadge.tsx +57 -0
- package/packages/plugin-ui/src/DataTable.tsx +168 -0
- package/packages/plugin-ui/src/Field.tsx +543 -0
- package/packages/plugin-ui/src/KeyValueList.tsx +32 -0
- package/packages/plugin-ui/src/Page.tsx +39 -0
- package/packages/plugin-ui/src/Pager.tsx +63 -0
- package/packages/plugin-ui/src/SearchInput.tsx +33 -0
- package/packages/plugin-ui/src/Section.tsx +47 -0
- package/packages/plugin-ui/src/Stat.tsx +25 -0
- package/packages/plugin-ui/src/TableToolbar.tsx +27 -0
- package/packages/plugin-ui/src/Tabs.tsx +77 -0
- package/packages/plugin-ui/src/card-surface.ts +11 -0
- package/packages/plugin-ui/src/cn.ts +7 -0
- package/packages/plugin-ui/src/dom-globals.d.ts +124 -0
- package/packages/plugin-ui/src/host.ts +270 -0
- package/packages/plugin-ui/src/index.ts +26 -0
- package/packages/plugin-ui/src/styles.css +386 -0
- package/packages/plugin-ui/src/useStaleWhileRevalidate.ts +211 -0
- package/packages/serve/package.json +32 -0
- package/packages/serve/src/agent-control.ts +595 -0
- package/packages/serve/src/agents-registry.ts +409 -0
- package/packages/serve/src/auth/avatar.ts +352 -0
- package/packages/serve/src/auth/bootstrap.ts +184 -0
- package/packages/serve/src/auth/credentials.ts +275 -0
- package/packages/serve/src/auth/github-oauth.ts +33 -0
- package/packages/serve/src/auth/index.ts +121 -0
- package/packages/serve/src/auth/oauth.ts +394 -0
- package/packages/serve/src/auth/origins.ts +145 -0
- package/packages/serve/src/auth/password.ts +187 -0
- package/packages/serve/src/auth/ratelimit.ts +249 -0
- package/packages/serve/src/auth/routes.ts +1757 -0
- package/packages/serve/src/auth/session.ts +407 -0
- package/packages/serve/src/auth/totp.ts +183 -0
- package/packages/serve/src/backpressure.ts +91 -0
- package/packages/serve/src/durable.ts +216 -0
- package/packages/serve/src/evals.ts +140 -0
- package/packages/serve/src/event-buffer.ts +92 -0
- package/packages/serve/src/event-summary.ts +11 -0
- package/packages/serve/src/federation.ts +1100 -0
- package/packages/serve/src/feishu.ts +51 -0
- package/packages/serve/src/gateway/auth.ts +773 -0
- package/packages/serve/src/gateway/errors.ts +21 -0
- package/packages/serve/src/gateway/frames.ts +195 -0
- package/packages/serve/src/gateway/methods/admin.ts +530 -0
- package/packages/serve/src/gateway/methods/agents.ts +1727 -0
- package/packages/serve/src/gateway/methods/attachments.ts +354 -0
- package/packages/serve/src/gateway/methods/common.ts +50 -0
- package/packages/serve/src/gateway/methods/config.ts +883 -0
- package/packages/serve/src/gateway/methods/evals.ts +87 -0
- package/packages/serve/src/gateway/methods/feishu.ts +52 -0
- package/packages/serve/src/gateway/methods/fleet.ts +225 -0
- package/packages/serve/src/gateway/methods/images.ts +196 -0
- package/packages/serve/src/gateway/methods/interactions.ts +721 -0
- package/packages/serve/src/gateway/methods/jobs.ts +148 -0
- package/packages/serve/src/gateway/methods/kanban.ts +637 -0
- package/packages/serve/src/gateway/methods/mcp.ts +82 -0
- package/packages/serve/src/gateway/methods/observability.ts +264 -0
- package/packages/serve/src/gateway/methods/permissions.ts +397 -0
- package/packages/serve/src/gateway/methods/rpc-namespaces.ts +80 -0
- package/packages/serve/src/gateway/methods/runs.ts +434 -0
- package/packages/serve/src/gateway/methods/schemas.ts +1196 -0
- package/packages/serve/src/gateway/methods/sessions.ts +2568 -0
- package/packages/serve/src/gateway/methods/subscription.ts +515 -0
- package/packages/serve/src/gateway/methods/teams.ts +638 -0
- package/packages/serve/src/gateway/sse.ts +130 -0
- package/packages/serve/src/gateway/static.ts +66 -0
- package/packages/serve/src/gateway/timeline-protocol.ts +532 -0
- package/packages/serve/src/gateway.ts +4974 -0
- package/packages/serve/src/hub-control.ts +86 -0
- package/packages/serve/src/hub-frames.ts +435 -0
- package/packages/serve/src/hub-protocol.ts +182 -0
- package/packages/serve/src/index.ts +511 -0
- package/packages/serve/src/interactions-registry.ts +1362 -0
- package/packages/serve/src/interactions-store.ts +360 -0
- package/packages/serve/src/local.ts +48 -0
- package/packages/serve/src/log-event.ts +57 -0
- package/packages/serve/src/mcp.ts +73 -0
- package/packages/serve/src/metrics.ts +137 -0
- package/packages/serve/src/platform/auth.ts +146 -0
- package/packages/serve/src/platform/index.ts +54 -0
- package/packages/serve/src/platform/listen-guard.ts +68 -0
- package/packages/serve/src/platform/metrics.ts +123 -0
- package/packages/serve/src/platform/proxy-config.ts +368 -0
- package/packages/serve/src/platform/proxy-ws.ts +737 -0
- package/packages/serve/src/platform/proxy.ts +909 -0
- package/packages/serve/src/platform/registry.ts +130 -0
- package/packages/serve/src/platform/rpc.ts +445 -0
- package/packages/serve/src/platform/server.ts +1148 -0
- package/packages/serve/src/platform/types.ts +276 -0
- package/packages/serve/src/plugin-host/catalog.ts +212 -0
- package/packages/serve/src/plugin-host/child.ts +767 -0
- package/packages/serve/src/plugin-host/dto.ts +191 -0
- package/packages/serve/src/plugin-host/errors.ts +50 -0
- package/packages/serve/src/plugin-host/events.ts +114 -0
- package/packages/serve/src/plugin-host/expose.ts +142 -0
- package/packages/serve/src/plugin-host/http.ts +823 -0
- package/packages/serve/src/plugin-host/index.ts +170 -0
- package/packages/serve/src/plugin-host/manager.ts +2027 -0
- package/packages/serve/src/plugin-host/ndjson.ts +136 -0
- package/packages/serve/src/plugin-host/proxy.ts +358 -0
- package/packages/serve/src/plugin-host/registry.ts +208 -0
- package/packages/serve/src/plugin-host/static.ts +162 -0
- package/packages/serve/src/plugin-host/types.ts +529 -0
- package/packages/serve/src/plugin-host/ws-proxy.ts +431 -0
- package/packages/serve/src/prometheus.ts +98 -0
- package/packages/serve/src/protocol.ts +332 -0
- package/packages/serve/src/replay-budget.ts +481 -0
- package/packages/serve/src/rpc.ts +614 -0
- package/packages/serve/src/run-control.ts +106 -0
- package/packages/serve/src/session-search.ts +142 -0
- package/packages/serve/src/shutdown-step.ts +128 -0
- package/packages/serve/src/team-control.ts +282 -0
- package/packages/serve/src/tenant-event-hub.ts +194 -0
- package/packages/serve/src/tenant.ts +169 -0
- package/packages/serve/src/tool-events.ts +244 -0
- package/packages/tui/package.json +40 -0
- package/packages/tui/src/commands/agents-command.ts +402 -0
- package/packages/tui/src/commands/capabilities-command.ts +356 -0
- package/packages/tui/src/commands/commands.ts +1361 -0
- package/packages/tui/src/commands/config-command.ts +541 -0
- package/packages/tui/src/commands/context-command.ts +348 -0
- package/packages/tui/src/commands/cost-command.ts +66 -0
- package/packages/tui/src/commands/details-command.ts +47 -0
- package/packages/tui/src/commands/errors-command.ts +205 -0
- package/packages/tui/src/commands/export-command.ts +193 -0
- package/packages/tui/src/commands/feishu-command.ts +101 -0
- package/packages/tui/src/commands/mcp-command.ts +319 -0
- package/packages/tui/src/commands/metrics-command.ts +314 -0
- package/packages/tui/src/commands/permissions-command.ts +117 -0
- package/packages/tui/src/commands/runs-command.ts +421 -0
- package/packages/tui/src/commands/sessions-command.ts +367 -0
- package/packages/tui/src/commands/settings-command.ts +180 -0
- package/packages/tui/src/commands/status-command.ts +30 -0
- package/packages/tui/src/commands/trace-command.ts +382 -0
- package/packages/tui/src/components/AskUserDialog.tsx +663 -0
- package/packages/tui/src/components/BottomBar.tsx +44 -0
- package/packages/tui/src/components/ConfirmDialog.tsx +175 -0
- package/packages/tui/src/components/DataTable.tsx +99 -0
- package/packages/tui/src/components/DetailPanel.tsx +80 -0
- package/packages/tui/src/components/EmptyState.tsx +27 -0
- package/packages/tui/src/components/InlineAutocomplete.tsx +319 -0
- package/packages/tui/src/components/InteractiveViewHost.tsx +652 -0
- package/packages/tui/src/components/KeyHints.tsx +41 -0
- package/packages/tui/src/components/Markdown.tsx +489 -0
- package/packages/tui/src/components/PanelFrame.tsx +113 -0
- package/packages/tui/src/components/QueuePreview.tsx +113 -0
- package/packages/tui/src/components/QuickHelp.tsx +91 -0
- package/packages/tui/src/components/ReasoningBlock.tsx +42 -0
- package/packages/tui/src/components/SessionTable.tsx +523 -0
- package/packages/tui/src/components/SpinnerWithVerb.tsx +116 -0
- package/packages/tui/src/components/StateTracker.ts +102 -0
- package/packages/tui/src/components/StatusBar.tsx +315 -0
- package/packages/tui/src/components/StreamOutput.tsx +302 -0
- package/packages/tui/src/components/SubagentActivity.tsx +57 -0
- package/packages/tui/src/components/TextViewer.tsx +100 -0
- package/packages/tui/src/components/ToolDisplay.tsx +248 -0
- package/packages/tui/src/components/ToolTrail.tsx +104 -0
- package/packages/tui/src/components/UiItemView.tsx +460 -0
- package/packages/tui/src/components/UpdateBanner.tsx +48 -0
- package/packages/tui/src/components/indicator.ts +61 -0
- package/packages/tui/src/error-classifier.ts +255 -0
- package/packages/tui/src/i18n/index.ts +67 -0
- package/packages/tui/src/i18n/messages/en.ts +543 -0
- package/packages/tui/src/i18n/messages/zh-CN.ts +528 -0
- package/packages/tui/src/index.ts +335 -0
- package/packages/tui/src/renderer/ask-user.ts +431 -0
- package/packages/tui/src/renderer/notify-user.ts +184 -0
- package/packages/tui/src/renderer/stream-renderer.ts +149 -0
- package/packages/tui/src/renderer/tool-confirm.ts +47 -0
- package/packages/tui/src/repl/agent-registry.ts +747 -0
- package/packages/tui/src/repl/cache-metrics.ts +241 -0
- package/packages/tui/src/repl/clear-on-start.ts +28 -0
- package/packages/tui/src/repl/error-archive.ts +95 -0
- package/packages/tui/src/repl/error-log.ts +212 -0
- package/packages/tui/src/repl/ink-repl.tsx +1735 -0
- package/packages/tui/src/repl/layout.ts +303 -0
- package/packages/tui/src/repl/limit-info.ts +630 -0
- package/packages/tui/src/repl/permission-pending.ts +49 -0
- package/packages/tui/src/repl/project/ui-item.ts +1307 -0
- package/packages/tui/src/repl/queue-info.ts +109 -0
- package/packages/tui/src/repl/resume-picker.ts +24 -0
- package/packages/tui/src/repl/run-turn.ts +60 -0
- package/packages/tui/src/repl/runtime-counters.ts +91 -0
- package/packages/tui/src/repl/startup-header.ts +144 -0
- package/packages/tui/src/repl/startup-notice.ts +100 -0
- package/packages/tui/src/repl/status-format.ts +513 -0
- package/packages/tui/src/repl/status-metrics.ts +88 -0
- package/packages/tui/src/repl/status-snapshot.ts +454 -0
- package/packages/tui/src/repl/use-repl-state.ts +548 -0
- package/packages/tui/src/repl-context.ts +349 -0
- package/packages/tui/src/rich-renderer.ts +63 -0
- package/packages/tui/src/rpc-events.ts +161 -0
- package/packages/tui/src/rpc.ts +149 -0
- package/packages/tui/src/theme.ts +180 -0
- package/packages/tui/src/types/events.ts +284 -0
- package/packages/tui/src/utils/dialog.ts +35 -0
- package/packages/tui/src/utils/diff.ts +124 -0
- package/packages/tui/src/utils/display-labels.ts +56 -0
- package/packages/tui/src/utils/file-reference.ts +180 -0
- package/packages/tui/src/utils/git.ts +24 -0
- package/packages/tui/src/utils/sanitize-terminal-text.ts +109 -0
- package/packages/tui/src/utils/text-layout.ts +127 -0
- package/packages/tui/src/utils/time.ts +25 -0
- package/packages/tui/src/utils/tool-input-summary.ts +70 -0
- package/packages/tui/src/views/keys.ts +344 -0
- package/packages/tui/src/views/layout.ts +224 -0
- package/packages/tui/src/views/render-text.ts +154 -0
- package/packages/tui/src/views/selection.ts +57 -0
- package/packages/tui/src/views/session-picker.ts +215 -0
- package/packages/tui/src/views/tones.ts +24 -0
- package/packages/tui/src/views/types.ts +200 -0
- package/packages/tui/src/wizard/setup-wizard.ts +439 -0
- package/packages/tui/tsconfig.json +10 -0
- package/plugins/context/doc-subscription/package.json +32 -0
- package/plugins/context/doc-subscription/src/agent.ts +151 -0
- package/plugins/context/doc-subscription/src/auto-sub.ts +80 -0
- package/plugins/context/doc-subscription/src/config.ts +358 -0
- package/plugins/context/doc-subscription/src/diff.ts +107 -0
- package/plugins/context/doc-subscription/src/friend-edges.ts +118 -0
- package/plugins/context/doc-subscription/src/health.ts +163 -0
- package/plugins/context/doc-subscription/src/hook.ts +1222 -0
- package/plugins/context/doc-subscription/src/implicit.ts +84 -0
- package/plugins/context/doc-subscription/src/index.ts +288 -0
- package/plugins/context/doc-subscription/src/lifecycle-listener.ts +58 -0
- package/plugins/context/doc-subscription/src/lifecycle.ts +186 -0
- package/plugins/context/doc-subscription/src/mute.ts +39 -0
- package/plugins/context/doc-subscription/src/notice.ts +347 -0
- package/plugins/context/doc-subscription/src/script.ts +288 -0
- package/plugins/context/doc-subscription/src/sources.ts +187 -0
- package/plugins/context/doc-subscription/src/store.ts +748 -0
- package/plugins/context/doc-subscription/src/team-log.ts +155 -0
- package/plugins/context/doc-subscription/src/tool.ts +2132 -0
- package/plugins/context/skills/package.json +182 -0
- package/plugins/context/skills/src/config.ts +178 -0
- package/plugins/context/skills/src/frontmatter.ts +166 -0
- package/plugins/context/skills/src/index.ts +144 -0
- package/plugins/context/skills/src/rpc.ts +274 -0
- package/plugins/context/skills/src/scanner.ts +262 -0
- package/plugins/context/skills/src/service.ts +277 -0
- package/plugins/context/skills/src/store.ts +333 -0
- package/plugins/context/skills/src/tool.ts +354 -0
- package/plugins/context/skills/src/trust.ts +71 -0
- package/plugins/context/skills/src/types.ts +130 -0
- package/plugins/context/skills/src/watch.ts +83 -0
- package/plugins/context/skills/tsconfig.web.json +29 -0
- package/plugins/context/skills/vite.config.embed.ts +107 -0
- package/plugins/context/skills/vite.config.ts +121 -0
- package/plugins/context/skills/web/assets/skills-8su2cNqF.css +2 -0
- package/plugins/context/skills/web/assets/skills-BhiDTAac.js +10 -0
- package/plugins/context/skills/web/embed/index.css +3 -0
- package/plugins/context/skills/web/embed/index.mjs +4251 -0
- package/plugins/context/skills/web/skills.html +13 -0
- package/plugins/context/skills/web-src/App.tsx +47 -0
- package/plugins/context/skills/web-src/SkillsView.tsx +649 -0
- package/plugins/context/skills/web-src/embed.css +153 -0
- package/plugins/context/skills/web-src/embed.tsx +36 -0
- package/plugins/context/skills/web-src/env.d.ts +2 -0
- package/plugins/context/skills/web-src/i18n.ts +195 -0
- package/plugins/context/skills/web-src/main.tsx +14 -0
- package/plugins/context/skills/web-src/shared.tsx +226 -0
- package/plugins/context/skills/web-src/skills.html +12 -0
- package/plugins/context/skills/web-src/styles.css +62 -0
- package/plugins/context/skills/web-src/types.ts +85 -0
- package/plugins/context/thinking-intensity/package.json +201 -0
- package/plugins/context/thinking-intensity/src/index.ts +285 -0
- package/plugins/context/thinking-intensity/src/mapping.ts +175 -0
- package/plugins/context/thinking-intensity/src/state.ts +134 -0
- package/plugins/evals/harness/package.json +32 -0
- package/plugins/evals/harness/src/assertions.ts +99 -0
- package/plugins/evals/harness/src/errors.ts +23 -0
- package/plugins/evals/harness/src/index.ts +48 -0
- package/plugins/evals/harness/src/mock-provider.ts +64 -0
- package/plugins/evals/harness/src/plugin.ts +48 -0
- package/plugins/evals/harness/src/report.ts +66 -0
- package/plugins/evals/harness/src/runner.ts +417 -0
- package/plugins/evals/harness/src/suite.ts +352 -0
- package/plugins/evals/harness/src/types.ts +154 -0
- package/plugins/fleet/compose/README.md +40 -0
- package/plugins/fleet/compose/package.json +172 -0
- package/plugins/fleet/compose/src/cli.ts +347 -0
- package/plugins/fleet/compose/src/i18n.ts +99 -0
- package/plugins/fleet/compose/src/index.ts +3 -0
- package/plugins/fleet/compose/src/manifest.ts +194 -0
- package/plugins/im/feishu/FEISHU.md +142 -0
- package/plugins/im/feishu/package.json +33 -0
- package/plugins/im/feishu/src/channel.ts +360 -0
- package/plugins/im/feishu/src/config.ts +133 -0
- package/plugins/im/feishu/src/dedupe.ts +30 -0
- package/plugins/im/feishu/src/errors.ts +21 -0
- package/plugins/im/feishu/src/index.ts +47 -0
- package/plugins/im/feishu/src/messages.ts +41 -0
- package/plugins/im/feishu/src/queue.ts +71 -0
- package/plugins/im/feishu/src/runner.ts +356 -0
- package/plugins/im/feishu/src/sdk-transport.ts +220 -0
- package/plugins/im/feishu/src/text.ts +56 -0
- package/plugins/im/feishu/src/types.ts +150 -0
- package/plugins/marketplace/marketplace/package.json +166 -0
- package/plugins/marketplace/marketplace/registry-template/README.md +105 -0
- package/plugins/marketplace/marketplace/registry-template/index.sample.json +71 -0
- package/plugins/marketplace/marketplace/registry-template/validate.mjs +272 -0
- package/plugins/marketplace/marketplace/registry-template/validate.yml +35 -0
- package/plugins/marketplace/marketplace/src/config-lock.ts +325 -0
- package/plugins/marketplace/marketplace/src/config.ts +432 -0
- package/plugins/marketplace/marketplace/src/errors.ts +79 -0
- package/plugins/marketplace/marketplace/src/index.ts +364 -0
- package/plugins/marketplace/marketplace/src/install.ts +930 -0
- package/plugins/marketplace/marketplace/src/jobs.ts +155 -0
- package/plugins/marketplace/marketplace/src/registry.ts +508 -0
- package/plugins/marketplace/marketplace/src/semver.ts +162 -0
- package/plugins/marketplace/marketplace/src/settings.ts +108 -0
- package/plugins/marketplace/marketplace/src/tar.ts +269 -0
- package/plugins/marketplace/marketplace/tsconfig.ui.json +26 -0
- package/plugins/marketplace/marketplace/vite.config.ts +107 -0
- package/plugins/marketplace/marketplace/web/assets/index-B2V7bx73.css +2 -0
- package/plugins/marketplace/marketplace/web/assets/index-B4NAz59m.js +13 -0
- package/plugins/marketplace/marketplace/web/index.html +13 -0
- package/plugins/marketplace/marketplace/web-src/App.tsx +193 -0
- package/plugins/marketplace/marketplace/web-src/api.ts +153 -0
- package/plugins/marketplace/marketplace/web-src/catalog.ts +27 -0
- package/plugins/marketplace/marketplace/web-src/components/ConfirmDialog.tsx +96 -0
- package/plugins/marketplace/marketplace/web-src/components/InstalledTable.tsx +152 -0
- package/plugins/marketplace/marketplace/web-src/components/JobStatus.tsx +70 -0
- package/plugins/marketplace/marketplace/web-src/components/Permissions.tsx +116 -0
- package/plugins/marketplace/marketplace/web-src/components/RegistryBanners.tsx +22 -0
- package/plugins/marketplace/marketplace/web-src/components/RegistrySetup.tsx +69 -0
- package/plugins/marketplace/marketplace/web-src/components/States.tsx +97 -0
- package/plugins/marketplace/marketplace/web-src/i18n.ts +337 -0
- package/plugins/marketplace/marketplace/web-src/index.html +12 -0
- package/plugins/marketplace/marketplace/web-src/main.tsx +17 -0
- package/plugins/marketplace/marketplace/web-src/styles.css +37 -0
- package/plugins/marketplace/marketplace/web-src/types.ts +175 -0
- package/plugins/marketplace/marketplace/web-src/views/InstalledView.tsx +150 -0
- package/plugins/marketplace/marketplace/web-src/views/MarketplaceView.tsx +479 -0
- package/plugins/marketplace/marketplace/web-src/views/UpdatesView.tsx +207 -0
- package/plugins/marketplace/marketplace/web-src/vite-env.d.ts +1 -0
- package/plugins/mcp/client/package.json +31 -0
- package/plugins/mcp/client/src/config-validate.ts +37 -0
- package/plugins/mcp/client/src/http-transport.ts +369 -0
- package/plugins/mcp/client/src/index.ts +35 -0
- package/plugins/mcp/client/src/json-rpc.ts +104 -0
- package/plugins/mcp/client/src/logging.ts +51 -0
- package/plugins/mcp/client/src/naming.ts +36 -0
- package/plugins/mcp/client/src/plugin.ts +310 -0
- package/plugins/mcp/client/src/registration.ts +143 -0
- package/plugins/mcp/client/src/server-connection.ts +556 -0
- package/plugins/mcp/client/src/stdio-transport.ts +377 -0
- package/plugins/mcp/client/src/transport.ts +11 -0
- package/plugins/mcp/client/src/types.ts +147 -0
- package/plugins/media/media/package.json +33 -0
- package/plugins/media/media/src/binaries.ts +88 -0
- package/plugins/media/media/src/config.ts +184 -0
- package/plugins/media/media/src/exec.ts +172 -0
- package/plugins/media/media/src/index.ts +125 -0
- package/plugins/media/media/src/tool.ts +640 -0
- package/plugins/observability/hook-logging/package.json +31 -0
- package/plugins/observability/hook-logging/src/index.ts +286 -0
- package/plugins/observability/usage/package.json +163 -0
- package/plugins/observability/usage/src/aggregate.ts +919 -0
- package/plugins/observability/usage/src/index.ts +362 -0
- package/plugins/observability/usage/src/query.ts +322 -0
- package/plugins/observability/usage/src/store.ts +1455 -0
- package/plugins/observability/usage/src/worker-client.ts +263 -0
- package/plugins/observability/usage/src/worker.ts +87 -0
- package/plugins/observability/usage/tsconfig.web.json +29 -0
- package/plugins/observability/usage/vite.config.embed.ts +105 -0
- package/plugins/observability/usage/vite.config.ts +121 -0
- package/plugins/observability/usage/web/assets/main-DD4g5VDL.css +2 -0
- package/plugins/observability/usage/web/assets/main-DVmWaf73.js +10 -0
- package/plugins/observability/usage/web/embed/index.css +3 -0
- package/plugins/observability/usage/web/embed/index.mjs +4560 -0
- package/plugins/observability/usage/web/logs.html +13 -0
- package/plugins/observability/usage/web/usage.html +13 -0
- package/plugins/observability/usage/web-src/App.tsx +54 -0
- package/plugins/observability/usage/web-src/LogsView.tsx +505 -0
- package/plugins/observability/usage/web-src/ModelTable.tsx +102 -0
- package/plugins/observability/usage/web-src/UsageView.tsx +210 -0
- package/plugins/observability/usage/web-src/embed.css +96 -0
- package/plugins/observability/usage/web-src/embed.tsx +75 -0
- package/plugins/observability/usage/web-src/env.d.ts +2 -0
- package/plugins/observability/usage/web-src/format.ts +88 -0
- package/plugins/observability/usage/web-src/i18n.ts +261 -0
- package/plugins/observability/usage/web-src/logs.html +12 -0
- package/plugins/observability/usage/web-src/main.tsx +19 -0
- package/plugins/observability/usage/web-src/shared.tsx +187 -0
- package/plugins/observability/usage/web-src/styles.css +22 -0
- package/plugins/observability/usage/web-src/usage.html +12 -0
- package/plugins/provider/anthropic/package.json +31 -0
- package/plugins/provider/anthropic/src/index.ts +75 -0
- package/plugins/provider/anthropic/src/retry.ts +266 -0
- package/plugins/provider/anthropic/src/timeout.ts +84 -0
- package/plugins/provider/model-registry/package.json +167 -0
- package/plugins/provider/model-registry/src/connectivity.ts +123 -0
- package/plugins/provider/model-registry/src/credential-store.ts +219 -0
- package/plugins/provider/model-registry/src/index.ts +453 -0
- package/plugins/provider/model-registry/src/registry-store.ts +223 -0
- package/plugins/provider/model-registry/tsconfig.web.json +29 -0
- package/plugins/provider/model-registry/vite.config.embed.ts +105 -0
- package/plugins/provider/model-registry/vite.config.ts +122 -0
- package/plugins/provider/model-registry/web/assets/main-BofPzD0n.js +10 -0
- package/plugins/provider/model-registry/web/assets/main-DkpGgdsZ.css +2 -0
- package/plugins/provider/model-registry/web/credentials.html +13 -0
- package/plugins/provider/model-registry/web/embed/index.css +3 -0
- package/plugins/provider/model-registry/web/embed/index.mjs +4887 -0
- package/plugins/provider/model-registry/web/models.html +13 -0
- package/plugins/provider/model-registry/web-src/App.tsx +54 -0
- package/plugins/provider/model-registry/web-src/CredentialsView.tsx +357 -0
- package/plugins/provider/model-registry/web-src/ModelForm.tsx +489 -0
- package/plugins/provider/model-registry/web-src/ModelsView.tsx +383 -0
- package/plugins/provider/model-registry/web-src/credentials.html +12 -0
- package/plugins/provider/model-registry/web-src/embed.css +96 -0
- package/plugins/provider/model-registry/web-src/embed.tsx +43 -0
- package/plugins/provider/model-registry/web-src/env.d.ts +2 -0
- package/plugins/provider/model-registry/web-src/i18n.ts +323 -0
- package/plugins/provider/model-registry/web-src/main.tsx +21 -0
- package/plugins/provider/model-registry/web-src/models.html +12 -0
- package/plugins/provider/model-registry/web-src/shared.tsx +147 -0
- package/plugins/provider/model-registry/web-src/styles.css +22 -0
- package/plugins/provider/model-registry/web-src/types.ts +120 -0
- package/plugins/provider/openai/package.json +31 -0
- package/plugins/provider/openai/src/index.ts +104 -0
- package/plugins/provider/openai/src/retry.ts +266 -0
- package/plugins/provider/openai/src/timeout.ts +84 -0
- package/plugins/provider/openai/src/vision.ts +121 -0
- package/plugins/security/guardrail-pii/package.json +31 -0
- package/plugins/security/guardrail-pii/src/index.ts +285 -0
- package/plugins/security/guardrail-pii/src/rules.ts +197 -0
- package/plugins/security/redact-secrets/package.json +31 -0
- package/plugins/security/redact-secrets/src/index.ts +145 -0
- package/plugins/security/redact-secrets/src/redactor.ts +83 -0
- package/plugins/security/redact-secrets/src/rules.ts +137 -0
- package/plugins/security/tool-policy/package.json +31 -0
- package/plugins/security/tool-policy/src/index.ts +184 -0
- package/plugins/tools/basic-tools/package.json +32 -0
- package/plugins/tools/basic-tools/src/background-jobs.ts +356 -0
- package/plugins/tools/basic-tools/src/bash-source.ts +58 -0
- package/plugins/tools/basic-tools/src/call-scope.ts +80 -0
- package/plugins/tools/basic-tools/src/config.ts +130 -0
- package/plugins/tools/basic-tools/src/index.ts +202 -0
- package/plugins/tools/basic-tools/src/path-boundary.ts +258 -0
- package/plugins/tools/basic-tools/src/shared.ts +221 -0
- package/plugins/tools/basic-tools/src/text.ts +49 -0
- package/plugins/tools/basic-tools/src/tools/bash-async.ts +1830 -0
- package/plugins/tools/basic-tools/src/tools/bash-exec.ts +567 -0
- package/plugins/tools/basic-tools/src/tools/bash.ts +300 -0
- package/plugins/tools/basic-tools/src/tools/edit.ts +160 -0
- package/plugins/tools/basic-tools/src/tools/grep.ts +601 -0
- package/plugins/tools/basic-tools/src/tools/read.ts +151 -0
- package/plugins/tools/basic-tools/src/tools/write.ts +494 -0
- package/plugins/tools/basic-tools/src/write-coord.ts +291 -0
- package/plugins/tools/basic-tools/src/write-lock.ts +353 -0
- package/plugins/tools/engine-client/package.json +34 -0
- package/plugins/tools/engine-client/src/client.ts +276 -0
- package/plugins/tools/engine-client/src/forward.ts +164 -0
- package/plugins/tools/engine-client/src/index.ts +18 -0
- package/plugins/tools/engine-client/src/pending.ts +101 -0
- package/plugins/tools/engine-client/src/pool.ts +1173 -0
- package/plugins/tools/engine-client/src/protocol.ts +249 -0
- package/plugins/tools/engine-client/src/registry.ts +138 -0
- package/plugins/tools/file-refs/README.md +68 -0
- package/plugins/tools/file-refs/package.json +135 -0
- package/plugins/tools/file-refs/src/index.ts +24 -0
- package/plugins/tools/file-refs/tsconfig.web.json +27 -0
- package/plugins/tools/file-refs/vite.config.embed.ts +88 -0
- package/plugins/tools/file-refs/web/embed/index.css +3 -0
- package/plugins/tools/file-refs/web/embed/index.mjs +879 -0
- package/plugins/tools/file-refs/web-src/AttachSheet.tsx +613 -0
- package/plugins/tools/file-refs/web-src/FileRefCard.tsx +206 -0
- package/plugins/tools/file-refs/web-src/FileRefLinkCard.tsx +90 -0
- package/plugins/tools/file-refs/web-src/attach-handler.tsx +116 -0
- package/plugins/tools/file-refs/web-src/attach-paths.ts +69 -0
- package/plugins/tools/file-refs/web-src/drop-handler.ts +15 -0
- package/plugins/tools/file-refs/web-src/embed.css +518 -0
- package/plugins/tools/file-refs/web-src/embed.tsx +18 -0
- package/plugins/tools/file-refs/web-src/env.d.ts +2 -0
- package/plugins/tools/file-refs/web-src/i18n.ts +137 -0
- package/plugins/tools/file-refs/web-src/icons.tsx +122 -0
- package/plugins/tools/file-refs/web-src/staging.ts +120 -0
- package/plugins/tools/file-refs/web-src/thumbnail.tsx +36 -0
- package/plugins/tools/recall/package.json +31 -0
- package/plugins/tools/recall/src/config.ts +74 -0
- package/plugins/tools/recall/src/index.ts +151 -0
- package/plugins/tools/recall/src/tool.ts +307 -0
- package/plugins/tools/web-tools/README.md +330 -0
- package/plugins/tools/web-tools/package.json +184 -0
- package/plugins/tools/web-tools/src/backends.ts +61 -0
- package/plugins/tools/web-tools/src/budget.ts +80 -0
- package/plugins/tools/web-tools/src/cache.ts +94 -0
- package/plugins/tools/web-tools/src/config.ts +412 -0
- package/plugins/tools/web-tools/src/deepseek-client.ts +406 -0
- package/plugins/tools/web-tools/src/deepseek-fetch.ts +168 -0
- package/plugins/tools/web-tools/src/extract.ts +373 -0
- package/plugins/tools/web-tools/src/fetch/local.ts +36 -0
- package/plugins/tools/web-tools/src/fetch/provider.ts +56 -0
- package/plugins/tools/web-tools/src/http.ts +415 -0
- package/plugins/tools/web-tools/src/index.ts +649 -0
- package/plugins/tools/web-tools/src/limits.ts +388 -0
- package/plugins/tools/web-tools/src/provider-http.ts +102 -0
- package/plugins/tools/web-tools/src/render.ts +248 -0
- package/plugins/tools/web-tools/src/robots.ts +187 -0
- package/plugins/tools/web-tools/src/search/custom.ts +595 -0
- package/plugins/tools/web-tools/src/search/deepseek.ts +111 -0
- package/plugins/tools/web-tools/src/search/index.ts +725 -0
- package/plugins/tools/web-tools/src/search/provider.ts +200 -0
- package/plugins/tools/web-tools/src/search/serper.ts +157 -0
- package/plugins/tools/web-tools/src/search/tavily.ts +146 -0
- package/plugins/tools/web-tools/src/secrets.ts +87 -0
- package/plugins/tools/web-tools/src/ssrf.ts +287 -0
- package/plugins/tools/web-tools/src/types.ts +137 -0
- package/skills/code-writing.md +33 -0
- package/src/agent/agent-control.ts +409 -0
- package/src/agent/agent-owner-client.ts +150 -0
- package/src/agent/agent-owner-server.ts +689 -0
- package/src/agent/agent-service-wiring.ts +675 -0
- package/src/agent/agent-wiring.ts +48 -0
- package/src/agent/ask-answer-delivery.ts +215 -0
- package/src/agent/local-run-adapter.ts +335 -0
- package/src/agent/peer-notices.ts +459 -0
- package/src/agent/peer-source.ts +63 -0
- package/src/agent/self-card.ts +52 -0
- package/src/agent/team-human-delivery.ts +144 -0
- package/src/assembly/collect.ts +161 -0
- package/src/assembly/feature.ts +133 -0
- package/src/assembly/features/attachments.ts +38 -0
- package/src/assembly/features/fleet.ts +31 -0
- package/src/assembly/features/jobs.ts +32 -0
- package/src/assembly/features/kanban.ts +56 -0
- package/src/assembly/features/restart.ts +35 -0
- package/src/assembly/features/subscription.ts +32 -0
- package/src/assembly/features.ts +30 -0
- package/src/cli/agent-call.ts +107 -0
- package/src/cli/args.ts +551 -0
- package/src/cli/ask-channel.ts +447 -0
- package/src/cli/command-spec/agent.ts +306 -0
- package/src/cli/command-spec/config.ts +179 -0
- package/src/cli/command-spec/define.ts +86 -0
- package/src/cli/command-spec/federation.ts +333 -0
- package/src/cli/command-spec/flags.ts +668 -0
- package/src/cli/command-spec/gateway.ts +350 -0
- package/src/cli/command-spec/hub.ts +290 -0
- package/src/cli/command-spec/kanban.ts +134 -0
- package/src/cli/command-spec/misc.ts +1032 -0
- package/src/cli/command-spec/model.ts +338 -0
- package/src/cli/command-spec/node.ts +160 -0
- package/src/cli/command-spec/plugin.ts +148 -0
- package/src/cli/command-spec/shared.ts +86 -0
- package/src/cli/command-spec/team.ts +582 -0
- package/src/cli/command-spec/token.ts +111 -0
- package/src/cli/command-spec.ts +270 -0
- package/src/cli/command-support.ts +53 -0
- package/src/cli/commands/agent/agent-command.ts +279 -0
- package/src/cli/commands/agent/agent-inbox-command.ts +141 -0
- package/src/cli/commands/agent/agents-command.ts +145 -0
- package/src/cli/commands/attention.ts +896 -0
- package/src/cli/commands/cli-update.ts +283 -0
- package/src/cli/commands/completion-command.ts +29 -0
- package/src/cli/commands/config-command.ts +545 -0
- package/src/cli/commands/dev-command.ts +429 -0
- package/src/cli/commands/doctor-command.ts +873 -0
- package/src/cli/commands/doctor-fleet.ts +410 -0
- package/src/cli/commands/errors-command.ts +469 -0
- package/src/cli/commands/eval-command.ts +168 -0
- package/src/cli/commands/federation-pair.ts +426 -0
- package/src/cli/commands/federation-peer.ts +445 -0
- package/src/cli/commands/federation.ts +527 -0
- package/src/cli/commands/fleet/fleet-inventory.ts +222 -0
- package/src/cli/commands/fleet/fleet-status-command.ts +433 -0
- package/src/cli/commands/fleet/ps-command.ts +387 -0
- package/src/cli/commands/fleet/restart-command.ts +745 -0
- package/src/cli/commands/fleet/start-command.ts +176 -0
- package/src/cli/commands/fleet/status-command.ts +318 -0
- package/src/cli/commands/fleet/stop-command.ts +548 -0
- package/src/cli/commands/gateway/gateway-command.ts +4204 -0
- package/src/cli/commands/gateway/gateway-nodes-command.ts +401 -0
- package/src/cli/commands/hub-command.ts +1007 -0
- package/src/cli/commands/kanban-command.ts +204 -0
- package/src/cli/commands/logs-command.ts +148 -0
- package/src/cli/commands/migrate-command.ts +131 -0
- package/src/cli/commands/model.ts +427 -0
- package/src/cli/commands/node-command.ts +805 -0
- package/src/cli/commands/permission/permission-show-command.ts +189 -0
- package/src/cli/commands/plugin/plugin-cli-command.ts +831 -0
- package/src/cli/commands/plugin/plugin-cli-local.ts +267 -0
- package/src/cli/commands/plugin/plugin-command.ts +407 -0
- package/src/cli/commands/prune-command.ts +233 -0
- package/src/cli/commands/resume-command.ts +100 -0
- package/src/cli/commands/rpc-command.ts +226 -0
- package/src/cli/commands/session/session-status-command.ts +352 -0
- package/src/cli/commands/team-command.ts +722 -0
- package/src/cli/commands/token-command.ts +494 -0
- package/src/cli/commands/trace-command.ts +133 -0
- package/src/cli/completion-script.ts +627 -0
- package/src/cli/completion-spec.ts +101 -0
- package/src/cli/control-plane-target.ts +295 -0
- package/src/cli/control-plane-types.ts +189 -0
- package/src/cli/feishu-command.ts +45 -0
- package/src/cli/headless-runner.ts +354 -0
- package/src/cli/help-search.ts +320 -0
- package/src/cli/help.ts +489 -0
- package/src/cli/output.ts +141 -0
- package/src/cli/parse-engine.ts +701 -0
- package/src/cli/parse-validators.ts +155 -0
- package/src/cli/project.ts +355 -0
- package/src/cli/registry.ts +25 -0
- package/src/cli.ts +2272 -0
- package/src/config/cli-overrides.ts +74 -0
- package/src/config/config-error-format.ts +44 -0
- package/src/config/config-snapshot.ts +15 -0
- package/src/config/config-watch.ts +436 -0
- package/src/config/config-write-apply.ts +98 -0
- package/src/config/empty-response-settings.ts +49 -0
- package/src/config/hot-apply-appliers.ts +527 -0
- package/src/config/hot-apply-assembly.ts +317 -0
- package/src/config/legacy-tool-names.ts +48 -0
- package/src/config/permission-defaults.ts +26 -0
- package/src/config/ui-settings.ts +568 -0
- package/src/config/vision-settings.ts +98 -0
- package/src/data/attachment-ingest.ts +101 -0
- package/src/data/attachment-staging.ts +377 -0
- package/src/data/attachments-list.ts +240 -0
- package/src/data/auto-prune.ts +342 -0
- package/src/data/data-lock.ts +580 -0
- package/src/data/data-paths.ts +265 -0
- package/src/data/image-blob-gc.ts +341 -0
- package/src/data/migrate.ts +480 -0
- package/src/data/path-resolution.ts +172 -0
- package/src/data/permission-store.ts +322 -0
- package/src/data/prune-wiring.ts +1037 -0
- package/src/data/refs-notice-hook.ts +417 -0
- package/src/federation/attention-client.ts +196 -0
- package/src/federation/attention-nodes.ts +142 -0
- package/src/federation/federation-address.ts +276 -0
- package/src/federation/federation-client.ts +620 -0
- package/src/federation/federation-config.ts +222 -0
- package/src/federation/federation-outbox.ts +374 -0
- package/src/federation/federation-pair-store.ts +236 -0
- package/src/federation/federation-pairing.ts +176 -0
- package/src/federation/federation-peer-store.ts +145 -0
- package/src/federation/federation-secrets.ts +140 -0
- package/src/federation/federation-send-port.ts +436 -0
- package/src/gateway/clean-spawn.ts +260 -0
- package/src/gateway/daemon.ts +336 -0
- package/src/gateway/fleet-index.ts +262 -0
- package/src/gateway/gateway-banner.ts +199 -0
- package/src/gateway/gateway-config-control.ts +53 -0
- package/src/gateway/gateway-reload-wiring.ts +512 -0
- package/src/gateway/gateway-wiring.ts +113 -0
- package/src/gateway/handoff.ts +131 -0
- package/src/gateway/instance-lock.ts +244 -0
- package/src/gateway/interactions-dir.ts +27 -0
- package/src/gateway/node-listen.ts +123 -0
- package/src/gateway/node-registry.ts +401 -0
- package/src/gateway/node-supervisor.ts +2226 -0
- package/src/gateway/pid.ts +827 -0
- package/src/gateway/pool-supervisor.ts +1150 -0
- package/src/gateway/reload.ts +238 -0
- package/src/gateway/restart-stop-exemption.ts +43 -0
- package/src/gateway/self-restart.ts +147 -0
- package/src/gateway/serve-auth.ts +184 -0
- package/src/gateway/serve-config.ts +135 -0
- package/src/gateway/service.ts +361 -0
- package/src/gateway/shutdown-report.ts +47 -0
- package/src/gateway/shutdown-sequence.ts +70 -0
- package/src/gateway/stop-drain.ts +299 -0
- package/src/gateway/stop-nodes-marker.ts +151 -0
- package/src/gateway/transport-factory.ts +53 -0
- package/src/gateway/watchdog.ts +622 -0
- package/src/gateway/web-dist.ts +1155 -0
- package/src/hub/client-protocol.ts +43 -0
- package/src/hub/derive-origins.ts +193 -0
- package/src/hub/hub-wiring.ts +310 -0
- package/src/hub/inbound-control.ts +432 -0
- package/src/hub/join-policy.ts +75 -0
- package/src/hub/join-store.ts +243 -0
- package/src/hub/node-credential-store.ts +295 -0
- package/src/hub/node-state.ts +279 -0
- package/src/hub/node-url.ts +33 -0
- package/src/hub/outbound-client.ts +509 -0
- package/src/hub/outbound-wiring.ts +168 -0
- package/src/hub/pairing-code.ts +27 -0
- package/src/hub/registry.ts +575 -0
- package/src/hub/runtime.ts +599 -0
- package/src/hub/secret-store.ts +571 -0
- package/src/hub/server.ts +1032 -0
- package/src/hub/snapshot-policy.ts +67 -0
- package/src/hub/types.ts +258 -0
- package/src/i18n/index.ts +94 -0
- package/src/i18n/messages/en.ts +1462 -0
- package/src/i18n/messages/zh-CN.ts +1323 -0
- package/src/mock/scenarios.ts +165 -0
- package/src/node/node-auto-resume.ts +264 -0
- package/src/node/node-drain.ts +520 -0
- package/src/node/node-identity.ts +240 -0
- package/src/node/node-resume.ts +511 -0
- package/src/node/resume-scan.ts +97 -0
- package/src/node/token-derive.ts +504 -0
- package/src/observability/logging.ts +72 -0
- package/src/observability/observability-wiring.ts +82 -0
- package/src/observability/startup-timing.ts +151 -0
- package/src/observability/trace-wiring.ts +250 -0
- package/src/observability/usage-pricing.ts +80 -0
- package/src/plugin/eval-wiring.ts +175 -0
- package/src/plugin/feishu-wiring.ts +250 -0
- package/src/plugin/mcp-wiring.ts +200 -0
- package/src/plugin/plugin-config.ts +491 -0
- package/src/plugin/plugin-host-assembly.ts +448 -0
- package/src/plugin/plugin-lifecycle.ts +130 -0
- package/src/plugin/plugin-loader.ts +788 -0
- package/src/plugin/plugin-manifest.ts +1936 -0
- package/src/plugin/plugin-selection.ts +200 -0
- package/src/plugin/plugin-surface.ts +207 -0
- package/src/plugin/plugin-watch.ts +114 -0
- package/src/rpc/http-client.ts +579 -0
- package/src/rpc/index.ts +34 -0
- package/src/rpc/local-client.ts +55 -0
- package/src/rpc/types.ts +125 -0
- package/src/run/connect-run-wait.ts +544 -0
- package/src/run/durable-wiring.ts +133 -0
- package/src/run/lease-service.ts +510 -0
- package/src/run/run-control.ts +160 -0
- package/src/run/run-record-store-factory.ts +89 -0
- package/src/runtime/agent-activity-watch.ts +335 -0
- package/src/runtime/agent-assembly.ts +818 -0
- package/src/runtime/agent-events-bridge.ts +86 -0
- package/src/runtime/bash-job-delivery.ts +291 -0
- package/src/runtime/bootstrap-connect.ts +644 -0
- package/src/runtime/bootstrap-types.ts +303 -0
- package/src/runtime/bootstrap.ts +1020 -0
- package/src/runtime/bus-source.ts +62 -0
- package/src/runtime/gc-assembly.ts +214 -0
- package/src/runtime/local-rpc-surface.ts +301 -0
- package/src/runtime/model-registry-wiring.ts +653 -0
- package/src/runtime/node-health-watch.ts +484 -0
- package/src/runtime/node-restart.ts +444 -0
- package/src/runtime/process-handlers.ts +164 -0
- package/src/runtime/provider-factory.ts +86 -0
- package/src/runtime/reasoning.ts +47 -0
- package/src/runtime/repl-context.ts +234 -0
- package/src/runtime/runtime-notice-hook.ts +357 -0
- package/src/runtime/runtime-notice.ts +273 -0
- package/src/runtime/session-id.ts +15 -0
- package/src/runtime/shutdown-sequence.ts +429 -0
- package/src/runtime/subscription-mute-bridge.ts +99 -0
- package/src/runtime/subscription-rpc-port.ts +597 -0
- package/src/runtime/team-log-bridge.ts +46 -0
- package/src/runtime/tenant-runtime-factory.ts +1838 -0
- package/src/runtime/thinking-agent-bridge.ts +57 -0
- package/src/runtime/tool-output-env.ts +80 -0
- package/src/runtime/vessel-meta.ts +338 -0
- package/src/session/context-composition.ts +147 -0
- package/src/session/context-ratio-source.ts +165 -0
- package/src/session/context-usage.ts +346 -0
- package/src/session/image-delivery.ts +297 -0
- package/src/session/session-control.ts +135 -0
- package/src/session/session-events.ts +144 -0
- package/src/session/session-factory.ts +73 -0
- package/src/session/session-liveness.ts +405 -0
- package/src/session/session-lock-runtime.ts +64 -0
- package/src/session/session-lock.ts +399 -0
- package/src/session/session-resume.ts +282 -0
- package/src/session/system-context.ts +235 -0
- package/src/session/timeline-dual-write.ts +2129 -0
- package/src/session/timeline-session-log.ts +140 -0
- package/src/shared/port-in-use.ts +27 -0
- package/src/shared/socket-inherit-guard.ts +13 -0
- package/src/shared/version.ts +38 -0
- package/src/tools-engine/engine.ts +286 -0
- package/src/tools-engine/entry.ts +757 -0
- package/src/tools-engine/mcp-engine-wiring.ts +354 -0
- package/src/tools-engine/mcp.ts +324 -0
- package/src/tools-engine/supervisor.ts +234 -0
- package/src/tools-engine/tools-list.ts +148 -0
- package/src/tools-engine/validate.ts +395 -0
- package/src/tools-engine/wiring.ts +88 -0
- package/src/tools-engine/worker.ts +110 -0
- package/src/update/background.ts +64 -0
- package/src/update/cache.ts +70 -0
- package/src/update/check.ts +138 -0
- package/src/update/gateway-check.ts +231 -0
- package/src/update/install-detect.ts +125 -0
- package/src/update/manifest.ts +132 -0
- package/src/update/semver.ts +70 -0
- package/src/update/stage.ts +219 -0
|
@@ -0,0 +1,818 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentService / REPL owner 装配(P1 批 4,自 bootstrap.ts 迁出;ADR-107 strangler)。
|
|
3
|
+
*
|
|
4
|
+
* 顺序承重契约不变:assembleAgentWiring(含 agent 工具注册 + 工具名闸)→
|
|
5
|
+
* 主干显式调用 wiring.startOwner()(顺序可见)→ finishAgentAssembly(恢复/hub/owner 端点)。
|
|
6
|
+
* 晚绑定回填语义不变:trunk 的 let 由返回值原地回填(均先于 startOwner);
|
|
7
|
+
* notice router 的父 session 重解析经 ctx.resolveNoticeAgentService getter 读 trunk 活引用。
|
|
8
|
+
* 唯一接线改动 = resolveParentSession 一行改读 getter;其余移动体逐字节(整体缩进 -2)。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { AgentService, MemberStatus, TeamDeclaration } from '@vessel-agent/agent';
|
|
12
|
+
import type { EngineClient } from '@vessel-agent/engine-client';
|
|
13
|
+
import { resolveEnvCadence, type VesselConfig } from '../../packages/config/src/index';
|
|
14
|
+
import {
|
|
15
|
+
assertToolNameLegality,
|
|
16
|
+
type Logger,
|
|
17
|
+
type Runtime,
|
|
18
|
+
sameRestartMarker,
|
|
19
|
+
} from '../../packages/core/src/index';
|
|
20
|
+
import type { ResumeAfterRestart } from '../../packages/core/src/types/session';
|
|
21
|
+
import {
|
|
22
|
+
parseDocSubscriptionConfig,
|
|
23
|
+
SubscriptionStore,
|
|
24
|
+
} from '../../plugins/context/doc-subscription/src/index';
|
|
25
|
+
import {
|
|
26
|
+
adoptBackgroundJobs,
|
|
27
|
+
configureBackgroundJobsDataDir,
|
|
28
|
+
} from '../../plugins/tools/basic-tools/src/index';
|
|
29
|
+
import { createAgentControl } from '../agent/agent-control';
|
|
30
|
+
import { type AgentOwnerServer, startAgentOwnerServer } from '../agent/agent-owner-server';
|
|
31
|
+
import { createAgentServiceWiring } from '../agent/agent-service-wiring';
|
|
32
|
+
import type { MemberPermissionMode, resolveAgentWiring } from '../agent/agent-wiring';
|
|
33
|
+
import { createPeerNoticeRouter, type PeerNoticeRouter } from '../agent/peer-notices';
|
|
34
|
+
import { peerSource } from '../agent/peer-source';
|
|
35
|
+
import {
|
|
36
|
+
createTeamHumanDelivery,
|
|
37
|
+
createTeamLocalMemberDelivery,
|
|
38
|
+
type LocalHumanTarget,
|
|
39
|
+
type LocalMemberTarget,
|
|
40
|
+
} from '../agent/team-human-delivery';
|
|
41
|
+
import { registerRefsNoticeHook, registerRuntimeNoticeHook } from '../config/hot-apply-assembly';
|
|
42
|
+
import { visionSurfaceOf } from '../config/vision-settings';
|
|
43
|
+
import { createConfigAttachmentIngest } from '../data/attachment-ingest';
|
|
44
|
+
import { resolveAgentCwd } from '../data/path-resolution';
|
|
45
|
+
import type { FederationRuntimeOptions } from '../federation/federation-config';
|
|
46
|
+
import { loadFederationPeerSecrets } from '../federation/federation-secrets';
|
|
47
|
+
import { createFederationSendPort } from '../federation/federation-send-port';
|
|
48
|
+
import { createHubRuntime } from '../hub/hub-wiring';
|
|
49
|
+
import { resumeInterruptedRuns } from '../node/node-auto-resume';
|
|
50
|
+
import { createNodeResumer } from '../node/node-resume';
|
|
51
|
+
import { scanResumeMeta } from '../node/resume-scan';
|
|
52
|
+
import { markStartup } from '../observability/startup-timing';
|
|
53
|
+
import { declarativePluginEntries, pluginConfigFor } from '../plugin/plugin-config';
|
|
54
|
+
import type { DurableRunHandleLike } from '../run/durable-wiring';
|
|
55
|
+
import { callbackRoute } from '../tools-engine/wiring';
|
|
56
|
+
import { type AgentActivityWatch, createAgentActivityWatch } from './agent-activity-watch';
|
|
57
|
+
import { bindAgentEventsService } from './agent-events-bridge';
|
|
58
|
+
import { registerBashJobDelivery } from './bash-job-delivery';
|
|
59
|
+
import { resolveDefaultTeamAnchor, resolveDefaultTeamWorkspace } from './bootstrap-connect';
|
|
60
|
+
import type { BootstrapResult } from './bootstrap-types';
|
|
61
|
+
import { busSource } from './bus-source';
|
|
62
|
+
import { createNodeHealthWatch, type NodeHealthWatch } from './node-health-watch';
|
|
63
|
+
import { createRuntimeNoticeBus, type RuntimeNoticeBus } from './runtime-notice';
|
|
64
|
+
import { isSubscriptionMuted, warmSubscriptionMuteMirror } from './subscription-mute-bridge';
|
|
65
|
+
import { bindTeamLogService } from './team-log-bridge';
|
|
66
|
+
import type { TenantRuntimeBundle } from './tenant-runtime-factory';
|
|
67
|
+
import { bindThinkingAgentService, thinkingLevelError } from './thinking-agent-bridge';
|
|
68
|
+
|
|
69
|
+
// q-sub-unify-p2 M4(D-2):固定推送源 facade 装配期复核(各模块加载已自断言,
|
|
70
|
+
// 此处显式引用保证装配路径加载 + 投递族不变量可见):bus/peer 走 ambient 注入族。
|
|
71
|
+
if (busSource.delivery !== 'ambient' || peerSource.delivery !== 'ambient') {
|
|
72
|
+
throw new Error('source-module invariant: bus/peer facades must be ambient');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** 装配输入:全部为 trunk 的稳定 const 引用(destructure 后移动体逐字节不变)。 */
|
|
76
|
+
export interface AgentAssemblyContext {
|
|
77
|
+
config: VesselConfig;
|
|
78
|
+
liveConfigRef: { current: VesselConfig };
|
|
79
|
+
bundle: TenantRuntimeBundle;
|
|
80
|
+
executionRuntime: Runtime;
|
|
81
|
+
engineClient: EngineClient;
|
|
82
|
+
currentSessionId: string;
|
|
83
|
+
interactiveHumanAvailable: boolean;
|
|
84
|
+
headless: boolean;
|
|
85
|
+
logger: Logger;
|
|
86
|
+
dataDir: string;
|
|
87
|
+
nodeId: string;
|
|
88
|
+
nodeName: string;
|
|
89
|
+
tenantId: string;
|
|
90
|
+
agentPlan: ReturnType<typeof resolveAgentWiring>;
|
|
91
|
+
termination: { maxIterations: number | undefined; maxRuntimeSeconds: number | undefined };
|
|
92
|
+
limits: NonNullable<VesselConfig['limits']>;
|
|
93
|
+
permission: { default: 'allow' | 'ask'; autoApprove: string[]; neverAutoApprove: string[] };
|
|
94
|
+
/** trunk 的标记单写口(函数声明提升;finishAgentAssembly 用)。 */
|
|
95
|
+
updateResumeMarker: (
|
|
96
|
+
sessionId: string,
|
|
97
|
+
key: { run_id: string; interrupted_at: number },
|
|
98
|
+
transform: (marker: ResumeAfterRestart) => ResumeAfterRestart | undefined,
|
|
99
|
+
) => Promise<boolean>;
|
|
100
|
+
/** q-restart-p1:durable resume 面(run 锁 + ask 注入);启动 auto-resume 接线用。 */
|
|
101
|
+
startResume: (runId: string) => Promise<DurableRunHandleLike>;
|
|
102
|
+
/** notice router flush 时读 trunk 的 noticeAgentService 活引用(shutdown 会清它)。 */
|
|
103
|
+
resolveNoticeAgentService: () => AgentService | undefined;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
type AgentServiceWiring = Awaited<ReturnType<typeof createAgentServiceWiring>>;
|
|
107
|
+
|
|
108
|
+
/** assembleAgentWiring 的产出:wiring + 需回填 trunk let 的晚绑定面。 */
|
|
109
|
+
export interface AgentWiringAssembly {
|
|
110
|
+
wiring: AgentServiceWiring;
|
|
111
|
+
noticeBus: RuntimeNoticeBus | undefined;
|
|
112
|
+
peerNotices: PeerNoticeRouter | undefined;
|
|
113
|
+
nodeHealthWatch: NodeHealthWatch | undefined;
|
|
114
|
+
agentActivityWatch: AgentActivityWatch | undefined;
|
|
115
|
+
federationApply: ((next: FederationRuntimeOptions) => void) | undefined;
|
|
116
|
+
feishuTeamId: string | undefined;
|
|
117
|
+
feishuAgentService: AgentService | undefined;
|
|
118
|
+
noticeAgentService: AgentService | undefined;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* agent 装配前半(原 bootstrap `if (agentServiceEnabled)` 块自 A3c 至工具名闸):
|
|
123
|
+
* federation/通知总线/peer router → createAgentServiceWiring → 回填 → agent 工具注册。
|
|
124
|
+
* startOwner 调用点留主干(顺序可见),不在本函数内。
|
|
125
|
+
*/
|
|
126
|
+
export async function assembleAgentWiring(ctx: AgentAssemblyContext): Promise<AgentWiringAssembly> {
|
|
127
|
+
const {
|
|
128
|
+
config,
|
|
129
|
+
liveConfigRef,
|
|
130
|
+
bundle,
|
|
131
|
+
executionRuntime,
|
|
132
|
+
engineClient,
|
|
133
|
+
currentSessionId,
|
|
134
|
+
interactiveHumanAvailable,
|
|
135
|
+
headless,
|
|
136
|
+
logger,
|
|
137
|
+
dataDir,
|
|
138
|
+
nodeId,
|
|
139
|
+
nodeName,
|
|
140
|
+
tenantId,
|
|
141
|
+
agentPlan,
|
|
142
|
+
termination,
|
|
143
|
+
limits,
|
|
144
|
+
permission,
|
|
145
|
+
resolveNoticeAgentService,
|
|
146
|
+
} = ctx;
|
|
147
|
+
const {
|
|
148
|
+
providerModel,
|
|
149
|
+
providerModelRef,
|
|
150
|
+
session,
|
|
151
|
+
sessionControl,
|
|
152
|
+
pluginHost: finalPluginHost,
|
|
153
|
+
runtimeEvents,
|
|
154
|
+
runStore,
|
|
155
|
+
eventLog,
|
|
156
|
+
} = bundle;
|
|
157
|
+
// 晚绑定面(原 trunk 函数级 let;装配后经返回值回填 trunk,时序不变)。
|
|
158
|
+
// federationApply 条件赋值保持 let;其余单赋值用 const(biome useConst,语义等价)。
|
|
159
|
+
let federationApply: ((next: FederationRuntimeOptions) => void) | undefined;
|
|
160
|
+
// A3c:交互入口成员 ask 经父事件流弹现有权限卡片;headless 直接 allow。
|
|
161
|
+
const memberPermissionMode: MemberPermissionMode = agentPlan.permissionMode;
|
|
162
|
+
const memberTermination =
|
|
163
|
+
agentPlan.termination !== undefined
|
|
164
|
+
? {
|
|
165
|
+
maxIterations: agentPlan.termination.maxIterations ?? termination.maxIterations,
|
|
166
|
+
maxRuntimeSeconds:
|
|
167
|
+
agentPlan.termination.maxRuntimeSeconds ?? termination.maxRuntimeSeconds,
|
|
168
|
+
}
|
|
169
|
+
: termination;
|
|
170
|
+
// 0.19 S3:配置声明(camelCase → TeamDeclaration 的 snake_case)+ 默认 workspace。
|
|
171
|
+
const teamDeclarations: TeamDeclaration[] = (config.teams ?? []).map((team) => ({
|
|
172
|
+
...(team.name !== undefined ? { name: team.name } : {}),
|
|
173
|
+
workspace: team.workspace,
|
|
174
|
+
...(team.policy !== undefined ? { policy: team.policy } : {}),
|
|
175
|
+
}));
|
|
176
|
+
// 0.28 C3:打开目录即建 Team。声明命中优先;否则交互 / serve 入口用 agent.cwd,
|
|
177
|
+
// 未配置时用 dataDir 派生的稳定锚点(不是各进程 cwd,TUI 与 gateway 的 node 子进程
|
|
178
|
+
// 因此共用同一个默认 Team)。headless(`--run` / 管道)保持 undefined:
|
|
179
|
+
// 一次性进程不该在数据目录里留空 Team。
|
|
180
|
+
const defaultWorkspace =
|
|
181
|
+
resolveDefaultTeamWorkspace(config, teamDeclarations, logger) ??
|
|
182
|
+
(headless ? undefined : (resolveAgentCwd(config) ?? resolveDefaultTeamAnchor(dataDir)));
|
|
183
|
+
// 0.27:发给人类的 send 直接写本机 Team 日志(异步委派,不阻塞 agent)。
|
|
184
|
+
// Team 服务在 createAgentServiceWiring 之后才存在,这里用晚绑定 getter 回填。
|
|
185
|
+
let localHuman: LocalHumanTarget | undefined;
|
|
186
|
+
let localMember: LocalMemberTarget | undefined;
|
|
187
|
+
// 0.21 S8.2:federation 缺省启用;显式 `federation.enabled: false` 才不注入。
|
|
188
|
+
// 语义不只是「跨节点所以关掉就没」:本机人类投递也挂在这个端口上,关掉 federation
|
|
189
|
+
// 等于连「agent 找本机人类」一起关掉。见下方 localHuman 的构造。
|
|
190
|
+
// q-fed-simple:`tokenSecret` peer 的 token 先从 SecretStore 预加载进内存。
|
|
191
|
+
const federationSecrets = await loadFederationPeerSecrets({
|
|
192
|
+
dataDir,
|
|
193
|
+
federation: config.federation,
|
|
194
|
+
logger,
|
|
195
|
+
});
|
|
196
|
+
// q-health-subscription:node 健康订阅 watcher(doc-subscription health 源的宿主侧)。
|
|
197
|
+
// 需求驱动:扫到 health 订阅才探测;快照落插件 stateDir,插件 run 边界读快照发通知
|
|
198
|
+
//(与文件订阅同一投递路径)。federation 关掉也建:本机 node 订阅不依赖 federation。
|
|
199
|
+
const nodeHealthWatch = createNodeHealthWatch({
|
|
200
|
+
getConfig: () => liveConfigRef.current,
|
|
201
|
+
dataDir,
|
|
202
|
+
nodeId,
|
|
203
|
+
secrets: federationSecrets,
|
|
204
|
+
logger,
|
|
205
|
+
});
|
|
206
|
+
nodeHealthWatch.start();
|
|
207
|
+
const federation =
|
|
208
|
+
config.federation?.enabled !== false
|
|
209
|
+
? createFederationSendPort({
|
|
210
|
+
federation: config.federation ?? {},
|
|
211
|
+
nodeId,
|
|
212
|
+
secrets: federationSecrets,
|
|
213
|
+
// 展示名只用于把指向本机的 `to` 归一化,不参与向外的 from。
|
|
214
|
+
nodeName,
|
|
215
|
+
localHuman: () => localHuman,
|
|
216
|
+
localMember: () => localMember,
|
|
217
|
+
// 4.1:durable outbox —— peer down 的出站消息持久化待投递(bounded
|
|
218
|
+
// retry + 重连补投 + 幂等),进程重启续投;事件进结构日志(不含 token)。
|
|
219
|
+
outboxDir: dataDir,
|
|
220
|
+
onOutboxEvent: (event) => {
|
|
221
|
+
if (
|
|
222
|
+
event.kind === 'exhausted' ||
|
|
223
|
+
event.kind === 'full' ||
|
|
224
|
+
event.kind === 'load_failed'
|
|
225
|
+
) {
|
|
226
|
+
logger.warn(`federation.outbox.${event.kind}`, { ...event });
|
|
227
|
+
} else {
|
|
228
|
+
logger.info(`federation.outbox.${event.kind}`, { ...event });
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
})
|
|
232
|
+
: undefined;
|
|
233
|
+
if (federation !== undefined) {
|
|
234
|
+
federationApply = (next) => federation.applyFederationOptions(next);
|
|
235
|
+
}
|
|
236
|
+
// 运行期通知总线(CONTRACT-hot-apply §3):热应用 / 版本检查 / 成员停下共用同一条
|
|
237
|
+
// 总线与同一个 BeforeLlm hook —— 两个总线会让两个 hook 争同一个注册名(后者被跳过)。
|
|
238
|
+
// 建在这里而不是 serve 壳里:TUI 入口同样要看到成员停下通知,serve 复用这一个实例。
|
|
239
|
+
const noticeBus = createRuntimeNoticeBus({
|
|
240
|
+
events: runtimeEvents,
|
|
241
|
+
tenantId,
|
|
242
|
+
// P2:off 在 publish 入口丢(live getter);诊断日志走中枢。
|
|
243
|
+
envInjection: () => liveConfigRef.current.envInjection,
|
|
244
|
+
logger,
|
|
245
|
+
// q-sub-unify-p2 M3b(§4.3):bus:<scope> 静音闸——游标照常推进内容丢弃。
|
|
246
|
+
isMuted: (sessionId, scope) => isSubscriptionMuted(sessionId, `bus:${scope}`),
|
|
247
|
+
});
|
|
248
|
+
registerRuntimeNoticeHook(
|
|
249
|
+
finalPluginHost,
|
|
250
|
+
noticeBus,
|
|
251
|
+
eventLog,
|
|
252
|
+
() => liveConfigRef.current.envInjection,
|
|
253
|
+
);
|
|
254
|
+
// 0.52:附件引用的环境信息行(模型据此知道有附件、该用 media 工具读)。
|
|
255
|
+
// 0.56 P1:带上视觉面探针——有 `provider.vision` 且没被 kill switch 关时,尾注改说
|
|
256
|
+
// 「图已随本条消息附上,不要再读」(避免模型把图再 media: read 一遍 = 双倍花费)。
|
|
257
|
+
registerRefsNoticeHook(finalPluginHost, {
|
|
258
|
+
vision: () => visionSurfaceOf({ config, backend: bundle.provider.vision }),
|
|
259
|
+
});
|
|
260
|
+
const peerNotices = createPeerNoticeRouter({
|
|
261
|
+
bus: noticeBus,
|
|
262
|
+
events: runtimeEvents,
|
|
263
|
+
logger,
|
|
264
|
+
// 0.53 notice-rotate:变更上的 `parent_session_id` 是报告时刻父 body 的 session;
|
|
265
|
+
// 合并窗口内父若 rotate,新 body 换了 session,这条 notice 就只落到旧 body 上。
|
|
266
|
+
// 真正投递那一刻用这条链接重解析父成员**当前** primary body 的 session
|
|
267
|
+
// (`AgentService.peerParentSessionOf` 内部即 `currentBindingSession`)。
|
|
268
|
+
// 注意入参是**上报变更的成员(子)id**(`PeerStopChange.agent_id`),不是父 id。
|
|
269
|
+
// 晚绑定:router 建在 wiring 之前,闭包在 flush 时才读。
|
|
270
|
+
resolveParentSession: (memberId) => resolveNoticeAgentService()?.peerParentSessionOf(memberId),
|
|
271
|
+
// ★D5(subscription-unify errata 用户裁定 + main 裁 A 补注):peer 停下是 agent 源类
|
|
272
|
+
// 隐式实例,cadence 统一读 agent 词(废 peer 独立旋钮)。默认 run = hold 到父 run
|
|
273
|
+
// 收口一轮一条(完全统一终态,不新增实例级默认机制);逃生门 agent:request 恢复
|
|
274
|
+
// mid-run 即发(原 q-peer-notice-cadence 的 request 语义);off = 静默。
|
|
275
|
+
// live resolver:report / schedule / flush 实时求值 ⇒ 热改即时生效。
|
|
276
|
+
cadence: () => resolveEnvCadence('agent', liveConfigRef.current.envInjection),
|
|
277
|
+
// q-sub-unify-p2 M3c(D-4):agent:<child> 静音闸——report 入口 + flush 复查。
|
|
278
|
+
isMuted: (parentSessionId, childAgentId) =>
|
|
279
|
+
isSubscriptionMuted(parentSessionId, `agent:${childAgentId}`),
|
|
280
|
+
});
|
|
281
|
+
const wiring = await createAgentServiceWiring({
|
|
282
|
+
// 来源行的 node 段与 federation 端口共用 nodeIdentity:federation 关掉时
|
|
283
|
+
// 来源行仍要本机 node 段,不能只挂在 send port 上。
|
|
284
|
+
nodeId,
|
|
285
|
+
// q-addr-display:node 名同源传入(name 档来源行);显示风格读 ui.addressStyle,
|
|
286
|
+
// 装配期取值(重启生效;hot-apply 留扩展位)。缺省由执行内核兜底 name。
|
|
287
|
+
nodeName,
|
|
288
|
+
...(config.ui?.addressStyle !== undefined ? { addressStyle: config.ui.addressStyle } : {}),
|
|
289
|
+
tenantId,
|
|
290
|
+
dataDir,
|
|
291
|
+
sessionId: currentSessionId,
|
|
292
|
+
pluginHost: finalPluginHost,
|
|
293
|
+
// q-sub-unify-p2 M3a(§4.3):inbox 计数静音闸——镜像桥同步查询(session 键)。
|
|
294
|
+
isSourceMuted: (sessionId, source, target) =>
|
|
295
|
+
isSubscriptionMuted(sessionId, `${source}:${target}`),
|
|
296
|
+
// Stage 4:成员 EU 经同一 Runtime 的 getOrCreateExecutionUnit 取得;
|
|
297
|
+
// agentId 绑定保证同 session 不会被 tenant / 成员两条路径静默复用。
|
|
298
|
+
runtime: executionRuntime,
|
|
299
|
+
// 成员 run durable:RunRecord 与 tenant run 同一条 journal 写路径。
|
|
300
|
+
...(runStore !== undefined ? { runStore } : {}),
|
|
301
|
+
// 第 6 修(SPAWN-02):宿主缺省存**ref**(条目键 / legacy 透传 ref)而非 wire——
|
|
302
|
+
// spawn 继承 member.model ?? this.model 经 resolveModelRef 解析,裸 wire 名在
|
|
303
|
+
// legacyPresent=false(纯 registry / provider 块已删)时无命中 → spawn_failed,
|
|
304
|
+
// 全新 dataDir 的 main 创建(createOrRestoreOwner 不带 model)即 boot 死。
|
|
305
|
+
// 展示面(selfCard / REPL / summary)仍用 wire:modelWire 与缺省 ref 分离。
|
|
306
|
+
// config.agent.model 是用户显式值,原样作 ref(与旧语义字节等价)。
|
|
307
|
+
model: agentPlan.model ?? providerModelRef,
|
|
308
|
+
modelWire: agentPlan.model ?? providerModel,
|
|
309
|
+
// 第 6 修(CHAIN-11/SPAWN-05):tool 层 create/hire 显式 pin 与 RPC 同闸。
|
|
310
|
+
...(bundle.validateModelRefDetailed !== undefined
|
|
311
|
+
? { modelRefError: bundle.validateModelRefDetailed }
|
|
312
|
+
: {}),
|
|
313
|
+
// thinking 档位枚举闸(q-thinking-agent-level-b2):单源 = 插件 isLevel,经桥注入。
|
|
314
|
+
thinkingLevelError,
|
|
315
|
+
limits: agentPlan.limits ?? limits,
|
|
316
|
+
termination: memberTermination,
|
|
317
|
+
...(agentPlan.readOnlyTools !== undefined ? { readOnlyTools: agentPlan.readOnlyTools } : {}),
|
|
318
|
+
// 0.51:成员工具面 = 节点全量(只剩 deny 只读档与 bridge 两条闸),`ask` 不再由
|
|
319
|
+
// 装配层点名放行。它的可用性现在完全由两条真实事实决定:父宿主真的注册了 `ask`
|
|
320
|
+
// (按入口 + `ui.askUser` 决定),且这具身体能 bridge(`permissionMode: 'bridge'`
|
|
321
|
+
// + 父事件流);缺任何一条就不进工具面,而不是靠这里传一个名字。详见
|
|
322
|
+
// `packages/agent/src/runtime.ts` 的 `toolBlocked`。
|
|
323
|
+
...(config.context?.maxTokens !== undefined
|
|
324
|
+
? { contextMaxTokens: config.context.maxTokens }
|
|
325
|
+
: {}),
|
|
326
|
+
...(config.context?.compactThreshold !== undefined
|
|
327
|
+
? { contextCompactThreshold: config.context.compactThreshold }
|
|
328
|
+
: {}),
|
|
329
|
+
// q-tool-result-whitelist:成员窗口与 owner 同一口径(缺省 ⇒ core 内置默认)。
|
|
330
|
+
...(config.context?.toolResultWhitelist !== undefined
|
|
331
|
+
? { contextToolResultWhitelist: config.context.toolResultWhitelist }
|
|
332
|
+
: {}),
|
|
333
|
+
// 注入粒度框架:self-card hook 的检测节奏(缺省不传 ⇒ 内置默认表,零回归)。
|
|
334
|
+
// P2:读 live ref ⇒ 热应用后新 spawn 的 body 用新配置(live body 的 hook 走 resolver)。
|
|
335
|
+
...(liveConfigRef.current.envInjection !== undefined
|
|
336
|
+
? { envInjection: liveConfigRef.current.envInjection }
|
|
337
|
+
: {}),
|
|
338
|
+
// P2 热加载:self-card hook 的 cadence/channel/off resolver 读 live ref(live body 同步)。
|
|
339
|
+
getEnvInjection: () => liveConfigRef.current.envInjection,
|
|
340
|
+
permission,
|
|
341
|
+
permissionMode: memberPermissionMode,
|
|
342
|
+
// 0.31:按**入口是否真有进程内应答者**判定,而不是 `!headless`:feishu 非 TTY
|
|
343
|
+
// (headless=false)既没有 TUI 也没有 gateway 权限卡片,用 !headless 会让
|
|
344
|
+
// rotate 请求永远等不到人。0.33 起 headless 注册 ask 但不等于有应答者,
|
|
345
|
+
// 所以这里用 interactiveHumanAvailable(排除 headless)。
|
|
346
|
+
humanApproval: interactiveHumanAvailable,
|
|
347
|
+
// 成员 bridge 请求 / 应答与 TUI 订阅的是同一条父事件流。
|
|
348
|
+
parentEvents: runtimeEvents,
|
|
349
|
+
// 好友边投影(q-sub-unify-p1 M6):读 viewer 当前 primary 会话状态的 friend 块。
|
|
350
|
+
// 晚绑定:wiring 之后才有 service;只读 load,不与插件 store 写链竞态。
|
|
351
|
+
friendsOf: async (viewerId: string) => {
|
|
352
|
+
const svc = resolveNoticeAgentService();
|
|
353
|
+
if (svc === undefined) return new Set<string>();
|
|
354
|
+
const members = await svc.list();
|
|
355
|
+
const session = members.find((member) => member.id === viewerId)?.session_id;
|
|
356
|
+
if (session === undefined) return new Set<string>();
|
|
357
|
+
const live = liveConfigRef.current;
|
|
358
|
+
const stateDir = parseDocSubscriptionConfig(
|
|
359
|
+
pluginConfigFor('doc-subscription', live.plugins, declarativePluginEntries(live)),
|
|
360
|
+
).stateDir;
|
|
361
|
+
const state = await new SubscriptionStore(stateDir).load(session);
|
|
362
|
+
const ids = new Set<string>();
|
|
363
|
+
for (const entry of Object.values(state.subscriptions)) {
|
|
364
|
+
if (entry.source === 'agent' && entry.friend !== undefined) ids.add(entry.path);
|
|
365
|
+
}
|
|
366
|
+
return ids;
|
|
367
|
+
},
|
|
368
|
+
// 0.27(spec §5.1):每 tenant 唯一 scheduler,由 tenant bundle 构造。
|
|
369
|
+
scheduler: bundle.scheduler,
|
|
370
|
+
...(config.agent?.ownerId !== undefined ? { ownerId: config.agent.ownerId } : {}),
|
|
371
|
+
// 成员停下 / 被关闭 → 定向到父 session 的一条 runtime.notice(scope agent,★D5)。
|
|
372
|
+
...(peerNotices !== undefined ? { peerStops: peerNotices.report } : {}),
|
|
373
|
+
// tools-engine P2 批次 3:inbox 逐 body 接线(原闭包含 agentId,callback 经 pending
|
|
374
|
+
// 关联执行,成员身份不由 engine 提供)。spawn / 热刷新都经 inboxTool() 触发;喂账本
|
|
375
|
+
// 幂等全量(指纹不变 engine 侧 no-op),失败只记日志。
|
|
376
|
+
wireInboxTool: (tool) => {
|
|
377
|
+
engineClient.wireTool(tool, callbackRoute('inbox'));
|
|
378
|
+
void engineClient.pushRegistry().catch((error: unknown) => {
|
|
379
|
+
logger.warn('tools-engine registry push failed (inbox)', {
|
|
380
|
+
message: error instanceof Error ? error.message : String(error),
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
|
+
},
|
|
384
|
+
logger,
|
|
385
|
+
// 成员 ExecutionUnit 与父级共用 tenant 存储:同 session_id 可在新进程恢复历史。
|
|
386
|
+
session,
|
|
387
|
+
...(eventLog !== undefined ? { eventLog } : {}),
|
|
388
|
+
...(bundle.leaseService !== undefined ? { leaseService: bundle.leaseService } : {}),
|
|
389
|
+
// 0.56(决策 2:上传即落):引用到达节点的第一刻就算 sha256 + 落 blob。
|
|
390
|
+
// 边界从活的 basic-tools 配置来(与 `attachments.list` 同一份判定)。
|
|
391
|
+
attachIngest: createConfigAttachmentIngest({ getConfig: () => config }),
|
|
392
|
+
...(bundle.summarizer !== undefined ? { summarizer: bundle.summarizer } : {}),
|
|
393
|
+
...(bundle.summarizerForSession !== undefined
|
|
394
|
+
? { summarizerForSession: bundle.summarizerForSession }
|
|
395
|
+
: {}),
|
|
396
|
+
teamDeclarations,
|
|
397
|
+
...(defaultWorkspace !== undefined ? { defaultWorkspace } : {}),
|
|
398
|
+
...(federation !== undefined ? { federation } : {}),
|
|
399
|
+
...(config.agent?.temporaryTtlHours !== undefined
|
|
400
|
+
? { temporaryTtlHours: config.agent.temporaryTtlHours }
|
|
401
|
+
: {}),
|
|
402
|
+
...(config.agent?.inboxMaxMessages !== undefined
|
|
403
|
+
? { inboxMaxMessages: config.agent.inboxMaxMessages }
|
|
404
|
+
: {}),
|
|
405
|
+
...(config.agent?.teamMemberLimit !== undefined
|
|
406
|
+
? { teamMemberLimit: config.agent.teamMemberLimit }
|
|
407
|
+
: {}),
|
|
408
|
+
// CREATE-0.39 §2.5:seeded create 的失败清理走 core 的 session-data 删除路径
|
|
409
|
+
// (先 detach 再删 event log / SessionState / RunRecord)。
|
|
410
|
+
deleteSessionData: async (sessionId: string) => {
|
|
411
|
+
await sessionControl.delete(sessionId);
|
|
412
|
+
},
|
|
413
|
+
});
|
|
414
|
+
// 0.27:回填本机投递端口(federation 端口的 getter 在此之后才读得到)。
|
|
415
|
+
// 0.57:`agent` 段(1s 级)拆开记账:装配(TeamStore / AgentService)与派生 `main`
|
|
416
|
+
// 是两件不同的事,谁的代价大要能直接读出来。
|
|
417
|
+
markStartup('agent.wiring');
|
|
418
|
+
localHuman = createTeamHumanDelivery(wiring.team);
|
|
419
|
+
localMember = createTeamLocalMemberDelivery(wiring.team);
|
|
420
|
+
// 0.28 F2:回填飞书成员复活用的 Team(默认 workspace 的 Team;缺省不复活)。
|
|
421
|
+
const feishuTeamId = wiring.defaultTeam?.team_id;
|
|
422
|
+
// 0.28:回填渠道执行面(渠道 `start()` 时才读取;此处不提前构造 / 不改变次序)。
|
|
423
|
+
const feishuAgentService = wiring.service;
|
|
424
|
+
// 0.53 notice-rotate:回填通知的重解析口(router 早在上面就建好了,flush 时才读)。
|
|
425
|
+
const noticeAgentService = wiring.service;
|
|
426
|
+
// q-sub-unify-p1 M4a:agent 活动订阅 watcher(doc-subscription agent 源的宿主侧)。
|
|
427
|
+
// 双流事件驱动(lead 裁定 R1):service.subscribe(agent.* 白名单)+ runtimeEvents
|
|
428
|
+
//(run.* 终态父流,与 TeamService/peer-notices 同源)。需求驱动:扫到 agent 订阅才写快照。
|
|
429
|
+
const agentActivityWatch = createAgentActivityWatch({
|
|
430
|
+
getConfig: () => liveConfigRef.current,
|
|
431
|
+
service: wiring.service,
|
|
432
|
+
parentEvents: runtimeEvents,
|
|
433
|
+
logger,
|
|
434
|
+
});
|
|
435
|
+
agentActivityWatch.start();
|
|
436
|
+
// q-sub-unify-p1 M6:好友边事件桥接上真实 service(install 时注册的 listener 即刻生效)。
|
|
437
|
+
bindAgentEventsService(wiring.service);
|
|
438
|
+
// q-sub-unify-p2 M2(D-1):静音镜像 warm——逐成员当前 primary session load 入镜像,
|
|
439
|
+
// 覆盖重启后首 run 前窗口(best-effort,空镜像=on fail-open;hook 每 run 兜底 refresh)。
|
|
440
|
+
void warmSubscriptionMuteMirror(wiring.service);
|
|
441
|
+
// q-sub-unify-p2 M6:team-log 端口桥接上真实 service / dataDir / tenantId
|
|
442
|
+
// (install 时插件已拿端口;canRead fail-closed 只订本 team)。
|
|
443
|
+
bindTeamLogService(wiring.service, ctx.dataDir, ctx.tenantId);
|
|
444
|
+
// q-thinking-agent-level-b2:thinking agent 级端口桥接上真实 service(同范式)——
|
|
445
|
+
// 插件读/写 agent 记录 thinkingLevel 单源(sessionLevels 已退役,零副本)。
|
|
446
|
+
bindThinkingAgentService(wiring.service);
|
|
447
|
+
// q-restart-pa:作业元数据持久化 / 重启意图判据的权威 dataDir(进程级单槽,先于任何
|
|
448
|
+
// 作业起步注入;缺省回退 env VESSEL_DATA_DIR)。
|
|
449
|
+
configureBackgroundJobsDataDir(ctx.dataDir);
|
|
450
|
+
registerBashJobDelivery({ service: wiring.service, logger });
|
|
451
|
+
logger.debug('agent.bash_job.delivery_ready', {});
|
|
452
|
+
finalPluginHost.registerTool(wiring.tool);
|
|
453
|
+
// tools-engine P2 批次 3:agent 恒 callback(Team 注册表 / body spawn / SessionStore
|
|
454
|
+
// 状态留 host;内部端点 = 原 handler 闭包)。注册后立即接线,先于 startOwner(spawn
|
|
455
|
+
// 顺序不变式);喂账本失败只记日志(engine disabled → fail-closed)。
|
|
456
|
+
engineClient.wireTool(wiring.tool, callbackRoute('agent'));
|
|
457
|
+
try {
|
|
458
|
+
await engineClient.pushRegistry();
|
|
459
|
+
} catch (error) {
|
|
460
|
+
logger.warn('tools-engine registry push failed (agent)', {
|
|
461
|
+
message: error instanceof Error ? error.message : String(error),
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
// 0.55:装配收尾的工具名闸(`agent` 工具是插件装完之后才注册的,所以要在这一句之后)。
|
|
465
|
+
// 内置 / 插件工具名不合规 ⇒ 启动失败并列出全部违规项;外部(MCP)工具名只记 warning。
|
|
466
|
+
for (const warning of assertToolNameLegality(finalPluginHost, 'bootstrap.final').warnings) {
|
|
467
|
+
logger.warn('external tool name is not snake_case; passed through as-is', {
|
|
468
|
+
tool_name: warning.name,
|
|
469
|
+
suggestion: warning.suggestion,
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
return {
|
|
473
|
+
wiring,
|
|
474
|
+
noticeBus,
|
|
475
|
+
peerNotices,
|
|
476
|
+
nodeHealthWatch,
|
|
477
|
+
agentActivityWatch,
|
|
478
|
+
federationApply,
|
|
479
|
+
feishuTeamId,
|
|
480
|
+
feishuAgentService,
|
|
481
|
+
noticeAgentService,
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* agent 装配后半(原 startOwner 之后至 agentControl 组装):启动即扫恢复 →
|
|
487
|
+
* hub 投影 → canonical 控制面 → owner 端点(headless 不监听)→ agentControl。
|
|
488
|
+
*/
|
|
489
|
+
export async function finishAgentAssembly(
|
|
490
|
+
ctx: AgentAssemblyContext,
|
|
491
|
+
wiring: AgentServiceWiring,
|
|
492
|
+
owner: MemberStatus,
|
|
493
|
+
): Promise<BootstrapResult['agent']> {
|
|
494
|
+
const { headless, logger, dataDir, nodeName, tenantId, updateResumeMarker, startResume } = ctx;
|
|
495
|
+
const { session, sessionControl, runtimeEvents, runStore, eventLog, journalFactory } = ctx.bundle;
|
|
496
|
+
// 0.53:**启动即扫**。gateway / 本地 dispatcher 开始收 RPC 之前,把「进程死亡时还没
|
|
497
|
+
// 变成 run input 的 human 输入」重新投递一次(判据、幂等、上限 8 会话见
|
|
498
|
+
// `AgentService.recoverPendingInputs`:unread + 未 held + 有 session_id + human 源)。
|
|
499
|
+
// 放在 `startOwner()` 之后:成员 EU spawn 时快照父宿主工具列表,恢复出来的 run 要用同一批。
|
|
500
|
+
// headless(`--run` / 管道)是一次性进程:不替别的会话恢复队列,退出时会留半截 run。
|
|
501
|
+
//
|
|
502
|
+
// 0.52 S1c:顺序改成「先发卡、再重放、准入后清标记」——
|
|
503
|
+
// 1) 读 `resume_after_restart` 标记(落盘 SessionState 是唯一权威);
|
|
504
|
+
// 2) 每个带标记的会话发一张「重启恢复」环境信息卡:一次 `runtime.notice`,
|
|
505
|
+
// 由环境信息通道在下一次请求的用户输入之前注入 ⇒ 同一份文本既进模型上下文,
|
|
506
|
+
// 也在聊天流里渲染成 EnvCard(用户裁定:不是隐藏输入,两边可见一致);
|
|
507
|
+
// 3) 卡之后才调既有的 `recoverPendingInputs()` 重放**已接受**的输入(最早 ts FIFO);
|
|
508
|
+
// 4) 卡片落成消息且随请求进了模型上下文之后才清标记(清标记走 RunJournal 单写口)。
|
|
509
|
+
// 任何一步失败都不阻断启动:标记与 unread 条目都还在,下次启动再判(幂等)。
|
|
510
|
+
//
|
|
511
|
+
// q-restart-p1:intent='restart' 标记的 auto-resume(续同一 run)在发卡**之前**提交;
|
|
512
|
+
// 降级出来的普通标记恰好被随后的 node-resume 发卡。node-resume 跳过 intent='restart' 标记。
|
|
513
|
+
// (标记单写口更新 updateResumeMarker 是函数声明,提升在本函数作用域,见 selfRestart 旁。)
|
|
514
|
+
// q-restart-p2b 启动序终定(§11.1):恢复链(auto-resume→node-resume→recover)延迟到
|
|
515
|
+
// cli.ts 的 liveness sweep **之后**执行(sweep 先把硬崩 stale running 修成 interrupted,
|
|
516
|
+
// auto-resume 再判标记)。重 attach 扫描 / 对账 / background_stopped 诚实化仍在下方先行。
|
|
517
|
+
let runStartupRecovery: (() => Promise<void>) | undefined;
|
|
518
|
+
if (!headless) {
|
|
519
|
+
// q-restart-pa:重 attach 扫描置于对账 / auto-resume **之前**(作业先重 attach 再续 run,
|
|
520
|
+
// 通知流正确):活过重启的 detached 作业恢复通知槽(完成投递复用 bash-job-delivery 链),
|
|
521
|
+
// 死作业 / pid 复用标 lost;上一进程 exit sweep 杀掉的 live job 清单用于诚实化。
|
|
522
|
+
// 失败不阻断启动(盘上清单还在,下次启动再判)。
|
|
523
|
+
let adoptedJobIds: ReadonlySet<string> | undefined;
|
|
524
|
+
// 诚实化清单 = exit sweep 杀掉的(killed_at_exit)+ 没活下来的(lost:force 杀 /
|
|
525
|
+
// 崩溃 / pid 复用)——凡没活过重启的作业都入 background_stopped 与有疤卡明细。
|
|
526
|
+
let stoppedJobs: Awaited<ReturnType<typeof adoptBackgroundJobs>>['killedAtExit'] = [];
|
|
527
|
+
try {
|
|
528
|
+
const adopt = await adoptBackgroundJobs();
|
|
529
|
+
adoptedJobIds = new Set(adopt.adopted);
|
|
530
|
+
stoppedJobs = [...adopt.killedAtExit, ...adopt.lost];
|
|
531
|
+
if (adopt.adopted.length > 0 || adopt.lost.length > 0 || adopt.killedAtExit.length > 0) {
|
|
532
|
+
logger.info('agent.bash_job.adopt_done', {
|
|
533
|
+
adopted: adopt.adopted.length,
|
|
534
|
+
lost: adopt.lost.length,
|
|
535
|
+
killed_at_exit: adopt.killedAtExit.length,
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
} catch (error) {
|
|
539
|
+
logger.warn('agent.bash_job.adopt_failed', {
|
|
540
|
+
error: error instanceof Error ? error.message : String(error),
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
// background_stopped 诚实化(lead 裁定替代路):有 live job 没活过重启(exit sweep
|
|
544
|
+
// 杀掉 / force 杀 / 崩溃死亡)⇒ 经既有 marker 单写口把 background_stopped 置 true
|
|
545
|
+
// (marker 不加新字段;清单单一真相源在 background-jobs.json,发卡时渲染进有疤卡)。
|
|
546
|
+
// 新进程注册表为空,journal 合并不会把旧值带回来。失败不阻断(卡仍按盘上 marker 渲染)。
|
|
547
|
+
if (stoppedJobs.length > 0) {
|
|
548
|
+
const sessions = new Set(
|
|
549
|
+
stoppedJobs
|
|
550
|
+
.map((record) => record.sessionId)
|
|
551
|
+
.filter((sessionId): sessionId is string => sessionId !== undefined),
|
|
552
|
+
);
|
|
553
|
+
for (const sessionId of sessions) {
|
|
554
|
+
try {
|
|
555
|
+
const state = await session.load(sessionId);
|
|
556
|
+
const marker = state?.resume_after_restart;
|
|
557
|
+
if (state === null || marker === undefined) continue;
|
|
558
|
+
await updateResumeMarker(
|
|
559
|
+
sessionId,
|
|
560
|
+
{ run_id: marker.run_id, interrupted_at: marker.interrupted_at },
|
|
561
|
+
(current) => ({ ...current, background_stopped: true }),
|
|
562
|
+
);
|
|
563
|
+
} catch (error) {
|
|
564
|
+
logger.warn('node.resume_marker.background_stopped_failed', {
|
|
565
|
+
session_id: sessionId,
|
|
566
|
+
error: error instanceof Error ? error.message : String(error),
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
// q-async-job-reconcile:对账孤儿异步作业占位卡,再走队列恢复。作业注册表是
|
|
572
|
+
// 进程内存、占位卡随 inbox 落盘 ⇒ 启动时盘上的 running 卡必属上一进程;重 attach
|
|
573
|
+
// 成功的 jobId 跳过(占位卡保持 running),其余原位回写 lost;quiet 留档不起 run,
|
|
574
|
+
// 与恢复链互不干扰。失败不阻断启动(卡保持 running,下次启动再试)。
|
|
575
|
+
try {
|
|
576
|
+
const reconciled = await wiring.service.reconcileAsyncJobs(
|
|
577
|
+
adoptedJobIds !== undefined ? { adoptedJobIds } : undefined,
|
|
578
|
+
);
|
|
579
|
+
if (reconciled.reconciled > 0 || reconciled.failed > 0) {
|
|
580
|
+
logger.info('agent.async_job.reconcile_done', { ...reconciled });
|
|
581
|
+
}
|
|
582
|
+
} catch (error) {
|
|
583
|
+
logger.warn('agent.async_job.reconcile_failed', {
|
|
584
|
+
error: error instanceof Error ? error.message : String(error),
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
// 恢复链整体延迟执行(runStartupRecovery):cli.ts 在 liveness sweep 之后调用,
|
|
588
|
+
// 保证 sweep(修 stale running)先于 auto-resume 判标记。内部顺序不变:
|
|
589
|
+
// auto-resume → node-resume 有疤卡 → recoverPendingInputs(skipSessions 防双投)。
|
|
590
|
+
runStartupRecovery = async () => {
|
|
591
|
+
try {
|
|
592
|
+
if (eventLog === undefined) {
|
|
593
|
+
// memory 后端 / 只读执行面没有事件日志:拿不到「卡发过没、准入没」的证据,
|
|
594
|
+
// 不另造一套状态 —— 退回 0.53 的队列重放(不发卡)。
|
|
595
|
+
const recovered = await wiring.service.recoverPendingInputs();
|
|
596
|
+
if (recovered.recovered > 0 || recovered.deferred > 0 || recovered.failed > 0) {
|
|
597
|
+
logger.info('agent.inbox.recover_done', { ...recovered });
|
|
598
|
+
}
|
|
599
|
+
} else {
|
|
600
|
+
// q-restart-p1(§3.2):auto-resume 先行——intent='restart' 标记的 run 仍
|
|
601
|
+
// interrupted/running 时经 durable 面续**同一 run**(fire-and-forget,收口后
|
|
602
|
+
// 才清标记);completed 静默清;failed/cancelled/缺失/hardStop/attempts 超限
|
|
603
|
+
// 降级普通标记,由下面 node-resume 发卡。先 submit 后重放(recoverPendingInputs),
|
|
604
|
+
// scheduler 串行消化;headless 不进此分支(一次性进程不替别的会话续跑)。
|
|
605
|
+
// q-restart-p2b:auto-resume 接管的会话集合——recoverPendingInputs 跳过这些会话
|
|
606
|
+
// 的重放(防与续跑 run 抢单 run 守卫 / 双点火);输入留 inbox 由续跑 run 拾取。
|
|
607
|
+
let autoResumedSessions: ReadonlySet<string> = new Set();
|
|
608
|
+
// q-read-metadata-a V1:resume 链共享单扫——枚举全会话取 resume 元数据**一次**
|
|
609
|
+
// (头部快路径免整壳 load;旧壳退回整份 parse),auto-resume 与 node-resume 共用
|
|
610
|
+
// 这一份结果,消掉原来两轮各扫一遍的 ×2 整壳放大。扫描失败 ⇒ undefined ⇒ 两轮
|
|
611
|
+
// 各自退回自扫(fail-safe,不阻断启动)。
|
|
612
|
+
let resumePrescan: Awaited<ReturnType<typeof scanResumeMeta>> | undefined;
|
|
613
|
+
try {
|
|
614
|
+
resumePrescan = await scanResumeMeta(session, {
|
|
615
|
+
warn: (event, meta) => logger.warn(event, meta),
|
|
616
|
+
});
|
|
617
|
+
} catch (error) {
|
|
618
|
+
logger.warn('node.resume_scan.failed', {
|
|
619
|
+
error: error instanceof Error ? error.message : String(error),
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
if (runStore !== undefined) {
|
|
623
|
+
try {
|
|
624
|
+
const autoResume = await resumeInterruptedRuns({
|
|
625
|
+
session,
|
|
626
|
+
prescan: resumePrescan,
|
|
627
|
+
runStatus: async (runId) => (await runStore.load(runId))?.status,
|
|
628
|
+
startResume,
|
|
629
|
+
hardStop: (sessionId) => wiring.service.sessionHardStop(sessionId) !== undefined,
|
|
630
|
+
updateMarker: updateResumeMarker,
|
|
631
|
+
clearRegistry: (sessionId) => ctx.bundle.resumeMarkers.clear(sessionId),
|
|
632
|
+
armRegistry: (sessionId, marker) => {
|
|
633
|
+
ctx.bundle.resumeMarkers.arm(sessionId, marker);
|
|
634
|
+
},
|
|
635
|
+
// q-restart-p2b:逃生门(node.drain.auto_resume,缺省 true)。
|
|
636
|
+
autoResume: ctx.config.node?.drain?.autoResume !== false,
|
|
637
|
+
warn: (event, meta) => logger.warn(event, meta),
|
|
638
|
+
info: (event, meta) => logger.info(event, meta),
|
|
639
|
+
});
|
|
640
|
+
autoResumedSessions = new Set(autoResume.resumed);
|
|
641
|
+
if (autoResume.found > 0) {
|
|
642
|
+
logger.info('node.auto_resume.done', { ...autoResume });
|
|
643
|
+
}
|
|
644
|
+
} catch (error) {
|
|
645
|
+
// auto-resume 扫描失败不阻断启动:标记仍在盘上,下次启动再试。
|
|
646
|
+
logger.warn('node.auto_resume.failed', {
|
|
647
|
+
error: error instanceof Error ? error.message : String(error),
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
const restarted = createNodeResumer({
|
|
652
|
+
session,
|
|
653
|
+
prescan: resumePrescan,
|
|
654
|
+
eventLog,
|
|
655
|
+
// q-restart-pa:被杀 live job 清单入有疤卡(background_stopped 诚实化的明细面)。
|
|
656
|
+
backgroundJobs: stoppedJobs.map((record) => ({
|
|
657
|
+
job_id: record.jobId,
|
|
658
|
+
command: record.command,
|
|
659
|
+
...(record.sessionId !== undefined ? { session_id: record.sessionId } : {}),
|
|
660
|
+
})),
|
|
661
|
+
// q-restart-p2b:逃生门同口径——auto_resume=false 时不跳过任何标记(全发卡)。
|
|
662
|
+
autoResume: ctx.config.node?.drain?.autoResume !== false,
|
|
663
|
+
// q-env-notice-dedup P3(B-1):跨重启工具面差入 restart 卡摘要行。
|
|
664
|
+
// 经 service.toolSurface 真实注册路径取数(活体实读 / 无活体按 spawn 同一套
|
|
665
|
+
// 推导),与 EU 请求 pin 同源;答不出 ⇒ undefined ⇒ 不出行(未知 ≠ 变更)。
|
|
666
|
+
currentToolsCount: async (sessionId) => {
|
|
667
|
+
const members = await wiring.service.list();
|
|
668
|
+
const record = members.find((member) => member.session_id === sessionId);
|
|
669
|
+
if (record === undefined) return undefined;
|
|
670
|
+
return wiring.service.toolSurface(record.id)?.length;
|
|
671
|
+
},
|
|
672
|
+
announce: (sessionId, text) => wiring.service.announceEnvironmentCard(sessionId, text),
|
|
673
|
+
// 清标记:只清「还是同一份标记」的那一个;拷贝里去掉该字段,
|
|
674
|
+
// 落盘仍走 RunJournal(`saveSessionState` 是 SessionState 的唯一写口)。
|
|
675
|
+
clearMarker: async (sessionId, marker) => {
|
|
676
|
+
const state = await session.load(sessionId);
|
|
677
|
+
if (state === null) return false;
|
|
678
|
+
if (!sameRestartMarker(state.resume_after_restart, marker)) return false;
|
|
679
|
+
const { resume_after_restart: _cleared, ...rest } = state;
|
|
680
|
+
const journal = journalFactory.transient({
|
|
681
|
+
runId: 'manual',
|
|
682
|
+
events: runtimeEvents,
|
|
683
|
+
sessionId,
|
|
684
|
+
});
|
|
685
|
+
await journal.saveSessionState(rest);
|
|
686
|
+
return true;
|
|
687
|
+
},
|
|
688
|
+
replay: async () => {
|
|
689
|
+
const recovered = await wiring.service.recoverPendingInputs({
|
|
690
|
+
skipSessions: autoResumedSessions,
|
|
691
|
+
});
|
|
692
|
+
return { recovered: recovered.recovered, sessions: recovered.sessions };
|
|
693
|
+
},
|
|
694
|
+
// P0-run-stops P3 僵尸标记判据的另一半:会话已完成。与 announce 的
|
|
695
|
+
// `no_member` 原因联合成立时,node-resume 经 clearMarker(单写口)清掉
|
|
696
|
+
// 永远不可能准入的标记(headless CLI 会话遗留),不再只增不减。
|
|
697
|
+
unrecoverable: async (sessionId) => {
|
|
698
|
+
const state = await session.load(sessionId);
|
|
699
|
+
return state !== null && state.status === 'completed';
|
|
700
|
+
},
|
|
701
|
+
warn: (event, meta) => logger.warn(event, meta),
|
|
702
|
+
});
|
|
703
|
+
const report = await restarted.beginResume();
|
|
704
|
+
markStartup('agent.resume');
|
|
705
|
+
if (report.marked > 0 || report.replayed_inputs > 0) {
|
|
706
|
+
logger.info('agent.resume.recover_done', {
|
|
707
|
+
marked: report.marked,
|
|
708
|
+
announced: report.announced,
|
|
709
|
+
deduped: report.deduped,
|
|
710
|
+
skipped: report.skipped,
|
|
711
|
+
replayed_inputs: report.replayed_inputs,
|
|
712
|
+
replayed_sessions: report.replayed_sessions,
|
|
713
|
+
// P0-run-stops P4:per-session skip 原因聚合(只扩日志内容)——
|
|
714
|
+
// skipped=9 这种读数必须能直接看出「为什么」,不用回去翻代码。
|
|
715
|
+
...(report.skipped > 0
|
|
716
|
+
? {
|
|
717
|
+
skipped_sessions: report.marks
|
|
718
|
+
.filter((mark) => mark.card === 'skipped')
|
|
719
|
+
.map((mark) => ({
|
|
720
|
+
session_id: mark.session_id,
|
|
721
|
+
reason: mark.skip_reason ?? 'unknown',
|
|
722
|
+
})),
|
|
723
|
+
}
|
|
724
|
+
: {}),
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
// 准入是异步的(要等下一轮请求真的发出):不阻塞启动,只在后台收尾清标记。
|
|
728
|
+
void restarted.whenSettled().then((final) => {
|
|
729
|
+
if (final.cleared.length > 0 || final.settle === 'timeout') {
|
|
730
|
+
logger.info('agent.resume.settle_done', {
|
|
731
|
+
cleared: final.cleared,
|
|
732
|
+
settle: final.settle,
|
|
733
|
+
marked: final.marked,
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
} catch (error) {
|
|
739
|
+
// 恢复失败不阻断启动:条目仍是 unread,标记仍落盘,下次启动再试。
|
|
740
|
+
logger.warn('agent.inbox.recover_failed', {
|
|
741
|
+
error: error instanceof Error ? error.message : String(error),
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// S5:hub 目录投影(node → hub 出站快照)。
|
|
748
|
+
const hubRuntime = await createHubRuntime({
|
|
749
|
+
service: wiring.service,
|
|
750
|
+
// S6:真实 TeamService 作为 hub 指针源(只带 team_id / kind / message_id)。
|
|
751
|
+
teamSource: wiring.team,
|
|
752
|
+
nodeName,
|
|
753
|
+
logger,
|
|
754
|
+
});
|
|
755
|
+
|
|
756
|
+
// owner 端点与 gateway 共用同一 canonical 控制面适配器。
|
|
757
|
+
// CREATE-0.39 §2.1:mode=both 的 git restore 需要 agent 所属 Team 的 workspace。
|
|
758
|
+
const agentControlLike = createAgentControl(wiring.service, tenantId, {
|
|
759
|
+
resolveWorkspace: async (agentId: string) => {
|
|
760
|
+
const status = await wiring.service.identify(agentId);
|
|
761
|
+
const teamId = status?.team_id;
|
|
762
|
+
return teamId === undefined ? undefined : wiring.teamStore.get(teamId)?.workspace;
|
|
763
|
+
},
|
|
764
|
+
});
|
|
765
|
+
// 0.34 Stage 3:CLI / TUI / gateway 的所有 delete 入口共用同一个前置钩子。
|
|
766
|
+
sessionControl.setDetachSession((sessionId) => wiring.service.detachSession(sessionId));
|
|
767
|
+
let ownerServer: AgentOwnerServer | undefined;
|
|
768
|
+
// owner 端点只服务交互 REPL / serve 的 CLI attach;headless(`--run` / 管道)
|
|
769
|
+
// 是一次性进程,不监听端口。AgentService / Team 仍在进程内可用。
|
|
770
|
+
if (!headless) {
|
|
771
|
+
try {
|
|
772
|
+
ownerServer = await startAgentOwnerServer({
|
|
773
|
+
control: agentControlLike,
|
|
774
|
+
sessionFor: () => session,
|
|
775
|
+
teams: wiring.team,
|
|
776
|
+
ownerId: wiring.ownerId,
|
|
777
|
+
dataDir,
|
|
778
|
+
tenantId,
|
|
779
|
+
logger,
|
|
780
|
+
});
|
|
781
|
+
} catch (error) {
|
|
782
|
+
// 同一 dataDir 已有 owner 时第二个 REPL 仍可用进程内工具;
|
|
783
|
+
// CLI attach 保持在原 owner 上。
|
|
784
|
+
console.warn(
|
|
785
|
+
`⚠ agent owner endpoint unavailable: ${
|
|
786
|
+
error instanceof Error ? error.message : String(error)
|
|
787
|
+
}`,
|
|
788
|
+
);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
const agentControl: BootstrapResult['agent'] = {
|
|
793
|
+
service: wiring.service,
|
|
794
|
+
team: wiring.team,
|
|
795
|
+
owner,
|
|
796
|
+
ownerId: wiring.ownerId,
|
|
797
|
+
...(ownerServer !== undefined ? { ownerServer } : {}),
|
|
798
|
+
hubControl: hubRuntime.hubControl,
|
|
799
|
+
control: agentControlLike,
|
|
800
|
+
applyDefaultModel: wiring.applyDefaultModel,
|
|
801
|
+
// q-restart-p2b 启动序终定:恢复链延迟到 cli.ts liveness sweep 之后调用(§11.1)。
|
|
802
|
+
...(runStartupRecovery !== undefined ? { runStartupRecovery } : {}),
|
|
803
|
+
dispose: async () => {
|
|
804
|
+
await ownerServer?.stop();
|
|
805
|
+
// 回收定时器必须先停:否则 drain 期间 sweep 仍可能回收正要收口的 agent。
|
|
806
|
+
wiring.stopSweep();
|
|
807
|
+
// 成员轮必须在 tenant eventLog 关闭前收口:否则尾部事件 append 会被
|
|
808
|
+
// `session_event_log_closed` 拒绝,子会话审计缺尾。
|
|
809
|
+
await wiring.service.drain({ timeoutMs: 5000 });
|
|
810
|
+
// Team 退订后再 flush 日志写链,避免关闭期间又追加系统消息。
|
|
811
|
+
wiring.team.dispose();
|
|
812
|
+
await wiring.teamStore.flush();
|
|
813
|
+
await wiring.conversationStore?.flush();
|
|
814
|
+
await wiring.service.flushSnapshot();
|
|
815
|
+
},
|
|
816
|
+
};
|
|
817
|
+
return agentControl;
|
|
818
|
+
}
|