nova-personal-agent-server 0.0.0-stage → 0.4.1
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 +201 -0
- package/README.md +30 -2
- package/bin/novapersonal-server.mjs +4 -0
- package/package.json +61 -4
- package/resources/endpointing/volcengine-v1/LICENSE.silero-vad.txt +21 -0
- package/resources/endpointing/volcengine-v1/MANIFEST.json +31 -0
- package/resources/endpointing/volcengine-v1/silence-16k-s16le.pcm +0 -0
- package/resources/endpointing/volcengine-v1/speech-16k-s16le.pcm +0 -0
- package/resources/native/codex-sandbox-probe +0 -0
- package/resources/native/project-native/nova_project_native.node +0 -0
- package/resources/native-resources-v1.json +1 -0
- package/runtime/dist/eval/demos.js +156 -0
- package/runtime/dist/eval/fixture-host.js +385 -0
- package/runtime/dist/eval/fixtures.js +319 -0
- package/runtime/dist/eval/realtime/session-fixtures.js +474 -0
- package/runtime/dist/eval/scorecard.js +285 -0
- package/runtime/dist/eval/sim.js +43 -0
- package/runtime/dist/src/cascaded-text-provider.js +31 -0
- package/runtime/dist/src/cli.js +96 -0
- package/runtime/dist/src/composition/assembly.js +352 -0
- package/runtime/dist/src/composition/cascaded-realtime-assembly.js +455 -0
- package/runtime/dist/src/composition/production-composition.js +389 -0
- package/runtime/dist/src/composition/realtime-assembly.js +1330 -0
- package/runtime/dist/src/config/capability-registry.js +315 -0
- package/runtime/dist/src/config/cascaded-realtime-config.js +146 -0
- package/runtime/dist/src/config/coding-backends.js +8 -0
- package/runtime/dist/src/config/coding-profiles.js +98 -0
- package/runtime/dist/src/config/config.js +857 -0
- package/runtime/dist/src/config/diagnostics.js +139 -0
- package/runtime/dist/src/config/environment-contract.js +202 -0
- package/runtime/dist/src/config/self-hosted.js +23 -0
- package/runtime/dist/src/connectors/composio/client.js +195 -0
- package/runtime/dist/src/connectors/composio/google.js +208 -0
- package/runtime/dist/src/connectors/composio/index.js +334 -0
- package/runtime/dist/src/connectors/feishu/cli.js +220 -0
- package/runtime/dist/src/connectors/feishu/index.js +980 -0
- package/runtime/dist/src/connectors/macos/calendar.js +35 -0
- package/runtime/dist/src/connectors/macos/mail.js +32 -0
- package/runtime/dist/src/connectors/macos/reader.js +62 -0
- package/runtime/dist/src/conversation-voice-provider.js +41 -0
- package/runtime/dist/src/core/approval-port.js +9 -0
- package/runtime/dist/src/core/approval.js +1328 -0
- package/runtime/dist/src/core/calls.js +35 -0
- package/runtime/dist/src/core/camera-session.js +32 -0
- package/runtime/dist/src/core/causal-runtime.js +650 -0
- package/runtime/dist/src/core/clock.js +139 -0
- package/runtime/dist/src/core/context-view.js +156 -0
- package/runtime/dist/src/core/effects.js +62 -0
- package/runtime/dist/src/core/events.js +217 -0
- package/runtime/dist/src/core/executor-diagnostic.js +9 -0
- package/runtime/dist/src/core/ids.js +32 -0
- package/runtime/dist/src/core/media-store.js +104 -0
- package/runtime/dist/src/core/memory.js +296 -0
- package/runtime/dist/src/core/pending-decision.js +64 -0
- package/runtime/dist/src/core/ports.js +125 -0
- package/runtime/dist/src/core/runtime.js +1459 -0
- package/runtime/dist/src/core/schedule-tools.js +15 -0
- package/runtime/dist/src/core/sims.js +186 -0
- package/runtime/dist/src/core/slots.js +97 -0
- package/runtime/dist/src/core/source-processing-instructions.js +3 -0
- package/runtime/dist/src/core/source-processing-tools.js +12 -0
- package/runtime/dist/src/core/suggestions.js +143 -0
- package/runtime/dist/src/core/task-tools.js +22 -0
- package/runtime/dist/src/core/tool-schema.js +212 -0
- package/runtime/dist/src/core/trace.js +34 -0
- package/runtime/dist/src/core/work-tools.js +94 -0
- package/runtime/dist/src/desktop/desktop-camera-source.js +31 -0
- package/runtime/dist/src/desktop/desktop-camera.js +281 -0
- package/runtime/dist/src/desktop/desktop-control.js +140 -0
- package/runtime/dist/src/desktop/desktop-progress.js +162 -0
- package/runtime/dist/src/desktop/desktop-session.js +2106 -0
- package/runtime/dist/src/desktop/desktop-tasks.js +80 -0
- package/runtime/dist/src/desktop/desktop-wire.js +605 -0
- package/runtime/dist/src/desktop/phone-desktop-entry.js +17 -0
- package/runtime/dist/src/desktop/startup-error.js +18 -0
- package/runtime/dist/src/desktop/workbench-acceptance.js +262 -0
- package/runtime/dist/src/desktop-entry.js +106 -0
- package/runtime/dist/src/desktop.js +1092 -0
- package/runtime/dist/src/executors/acp/backends.js +105 -0
- package/runtime/dist/src/executors/acp/mcp.js +81 -0
- package/runtime/dist/src/executors/acp/preflight.js +14 -0
- package/runtime/dist/src/executors/acp/process-owner.js +112 -0
- package/runtime/dist/src/executors/acp/transport.js +760 -0
- package/runtime/dist/src/executors/acp/windows-launch.js +68 -0
- package/runtime/dist/src/executors/agent-controller.js +244 -0
- package/runtime/dist/src/executors/autoglm.js +376 -0
- package/runtime/dist/src/executors/browser-device.js +102 -0
- package/runtime/dist/src/executors/browser.js +61 -0
- package/runtime/dist/src/executors/camera.js +101 -0
- package/runtime/dist/src/executors/chromium-frame-source.js +173 -0
- package/runtime/dist/src/executors/codex/adapter-live.js +292 -0
- package/runtime/dist/src/executors/codex/adapter-project.js +1306 -0
- package/runtime/dist/src/executors/codex/app-server-schema.js +712 -0
- package/runtime/dist/src/executors/codex/app-server-transport.js +1798 -0
- package/runtime/dist/src/executors/codex/approval-protocol.js +439 -0
- package/runtime/dist/src/executors/codex/common.js +655 -0
- package/runtime/dist/src/executors/codex/contract.js +581 -0
- package/runtime/dist/src/executors/codex/controller.js +141 -0
- package/runtime/dist/src/executors/codex/credential-snapshot.js +195 -0
- package/runtime/dist/src/executors/codex/factory.js +463 -0
- package/runtime/dist/src/executors/codex/host-config.js +238 -0
- package/runtime/dist/src/executors/codex/host.js +17 -0
- package/runtime/dist/src/executors/codex/index.js +19 -0
- package/runtime/dist/src/executors/codex/launch-profile.js +37 -0
- package/runtime/dist/src/executors/codex/local-sessions.js +119 -0
- package/runtime/dist/src/executors/codex/managed-mcp.js +196 -0
- package/runtime/dist/src/executors/codex/process-owner.js +398 -0
- package/runtime/dist/src/executors/codex/production-host.js +887 -0
- package/runtime/dist/src/executors/codex/progress-instructions.js +10 -0
- package/runtime/dist/src/executors/codex/protocol.js +581 -0
- package/runtime/dist/src/executors/codex/safe-json.js +87 -0
- package/runtime/dist/src/executors/codex/session-title.js +61 -0
- package/runtime/dist/src/executors/codex/shared-home.js +29 -0
- package/runtime/dist/src/executors/codex/spawn-env.js +162 -0
- package/runtime/dist/src/executors/codex/turn-projection.js +435 -0
- package/runtime/dist/src/executors/codex/version.js +38 -0
- package/runtime/dist/src/executors/codex/windows-guardian.js +716 -0
- package/runtime/dist/src/executors/coding/intake-model.js +103 -0
- package/runtime/dist/src/executors/coding/intake.js +824 -0
- package/runtime/dist/src/executors/coding/json-completion.js +14 -0
- package/runtime/dist/src/executors/coding/target-resolution.js +61 -0
- package/runtime/dist/src/executors/coding/work-order.js +50 -0
- package/runtime/dist/src/executors/coding-executor.js +23 -0
- package/runtime/dist/src/executors/computer-backend.js +188 -0
- package/runtime/dist/src/executors/computer-device.js +187 -0
- package/runtime/dist/src/executors/computer-worker.js +125 -0
- package/runtime/dist/src/executors/computer.js +100 -0
- package/runtime/dist/src/executors/device-lock.js +127 -0
- package/runtime/dist/src/executors/frame-source.js +29 -0
- package/runtime/dist/src/executors/gui-evidence.js +30 -0
- package/runtime/dist/src/executors/gui-execution.js +237 -0
- package/runtime/dist/src/executors/gui-runner.js +88 -0
- package/runtime/dist/src/executors/host-executor-capability.js +12 -0
- package/runtime/dist/src/executors/index.js +13 -0
- package/runtime/dist/src/executors/mcp-client.js +198 -0
- package/runtime/dist/src/executors/mcp.js +210 -0
- package/runtime/dist/src/executors/mobile-android.js +180 -0
- package/runtime/dist/src/executors/mobile-ios.js +303 -0
- package/runtime/dist/src/executors/mobile.js +78 -0
- package/runtime/dist/src/executors/search-mcp.js +146 -0
- package/runtime/dist/src/executors/search.js +524 -0
- package/runtime/dist/src/executors/task-resources.js +38 -0
- package/runtime/dist/src/executors/vision/assess.js +296 -0
- package/runtime/dist/src/executors/vision/controller-core.js +373 -0
- package/runtime/dist/src/executors/vision/controller.js +164 -0
- package/runtime/dist/src/executors/vision/lifecycle.js +69 -0
- package/runtime/dist/src/executors/vision.js +5 -0
- package/runtime/dist/src/executors/watcher.js +718 -0
- package/runtime/dist/src/http/bounded-response.js +37 -0
- package/runtime/dist/src/index.js +56 -0
- package/runtime/dist/src/knowledge/assembly.js +60 -0
- package/runtime/dist/src/knowledge/documents.js +520 -0
- package/runtime/dist/src/knowledge/embeddings.js +201 -0
- package/runtime/dist/src/knowledge/mcp.js +218 -0
- package/runtime/dist/src/knowledge/parse-worker.js +122 -0
- package/runtime/dist/src/knowledge/references.js +51 -0
- package/runtime/dist/src/knowledge/service.js +526 -0
- package/runtime/dist/src/knowledge/store-client.js +185 -0
- package/runtime/dist/src/knowledge/store-worker.js +843 -0
- package/runtime/dist/src/knowledge/types.js +2 -0
- package/runtime/dist/src/mcp/http-server.js +177 -0
- package/runtime/dist/src/mem0/resource.js +35 -0
- package/runtime/dist/src/mem0/store-worker.js +330 -0
- package/runtime/dist/src/memory/blackboard-session.js +205 -0
- package/runtime/dist/src/memory/blackboard-store.js +194 -0
- package/runtime/dist/src/memory/blackboard-worker.js +369 -0
- package/runtime/dist/src/memory/entry.js +39 -0
- package/runtime/dist/src/memory/factory.js +20 -0
- package/runtime/dist/src/memory/personal-memory-inspection.js +18 -0
- package/runtime/dist/src/memory/personal-memory.js +10 -0
- package/runtime/dist/src/memory/prerecall.js +20 -0
- package/runtime/dist/src/memory/provenance.js +17 -0
- package/runtime/dist/src/memory/remote-personal-memory.js +194 -0
- package/runtime/dist/src/memory/retrieval.js +235 -0
- package/runtime/dist/src/memory/sensitivity.js +261 -0
- package/runtime/dist/src/memory-ledger/models.js +98 -0
- package/runtime/dist/src/memory-ledger/store-client.js +210 -0
- package/runtime/dist/src/memory-ledger/store-worker.js +130 -0
- package/runtime/dist/src/memory-ledger/store.js +597 -0
- package/runtime/dist/src/memory-substrate/candidates.js +16 -0
- package/runtime/dist/src/memory-substrate/consolidation.js +124 -0
- package/runtime/dist/src/memory-substrate/file-authority.js +111 -0
- package/runtime/dist/src/memory-substrate/life-operations.js +280 -0
- package/runtime/dist/src/memory-substrate/markdown-repository.js +610 -0
- package/runtime/dist/src/memory-substrate/migration.js +87 -0
- package/runtime/dist/src/memory-substrate/profile-source-input.js +9 -0
- package/runtime/dist/src/memory-substrate/purge.js +398 -0
- package/runtime/dist/src/memory-substrate/resolution.js +32 -0
- package/runtime/dist/src/memory-substrate/resource.js +867 -0
- package/runtime/dist/src/memory-substrate/retrieval.js +85 -0
- package/runtime/dist/src/memory-substrate/source-operations.js +306 -0
- package/runtime/dist/src/memory-substrate/source-processing.js +326 -0
- package/runtime/dist/src/memory-substrate/source-state.js +93 -0
- package/runtime/dist/src/memory-substrate/store.js +534 -0
- package/runtime/dist/src/memory-substrate/workspace-projections.js +106 -0
- package/runtime/dist/src/memory-substrate/workspace.js +21 -0
- package/runtime/dist/src/model/jev-client.js +25 -0
- package/runtime/dist/src/model/model-adapters.js +64 -0
- package/runtime/dist/src/model/model-gateway.js +399 -0
- package/runtime/dist/src/model/model-lane.js +34 -0
- package/runtime/dist/src/model/model-purpose.js +5 -0
- package/runtime/dist/src/model/personal-writer.js +361 -0
- package/runtime/dist/src/model/proactivity.js +72 -0
- package/runtime/dist/src/model/prompting.js +279 -0
- package/runtime/dist/src/model/task-verifier.js +217 -0
- package/runtime/dist/src/model/vision-capability.js +10 -0
- package/runtime/dist/src/news/feeds.js +114 -0
- package/runtime/dist/src/news/jev-ranking.js +25 -0
- package/runtime/dist/src/news/ranking.js +26 -0
- package/runtime/dist/src/news/service.js +262 -0
- package/runtime/dist/src/notifications/adapters/feishu.js +10 -0
- package/runtime/dist/src/notifications/adapters/nova.js +15 -0
- package/runtime/dist/src/notifications/content.js +15 -0
- package/runtime/dist/src/notifications/contracts.js +9 -0
- package/runtime/dist/src/notifications/feed.js +8 -0
- package/runtime/dist/src/notifications/service.js +412 -0
- package/runtime/dist/src/notifications/store.js +4 -0
- package/runtime/dist/src/personal-agent/app-context.js +113 -0
- package/runtime/dist/src/personal-agent/approval-scope.js +8 -0
- package/runtime/dist/src/personal-agent/coding-targets.js +82 -0
- package/runtime/dist/src/personal-agent/context-candidates.js +94 -0
- package/runtime/dist/src/personal-agent/contracts.js +32 -0
- package/runtime/dist/src/personal-agent/conversation-runtime.js +536 -0
- package/runtime/dist/src/personal-agent/conversations.js +187 -0
- package/runtime/dist/src/personal-agent/daily-brief.js +53 -0
- package/runtime/dist/src/personal-agent/host.js +2403 -0
- package/runtime/dist/src/personal-agent/intake-task.js +37 -0
- package/runtime/dist/src/personal-agent/life.js +260 -0
- package/runtime/dist/src/personal-agent/memory-overview.js +19 -0
- package/runtime/dist/src/personal-agent/profile-sources.js +34 -0
- package/runtime/dist/src/personal-agent/profile-warmup.js +244 -0
- package/runtime/dist/src/personal-agent/project-digests.js +242 -0
- package/runtime/dist/src/personal-agent/sampling.js +20 -0
- package/runtime/dist/src/personal-agent/schedule-agent.js +60 -0
- package/runtime/dist/src/personal-agent/schedule-api.js +61 -0
- package/runtime/dist/src/personal-agent/schedule-presets.js +13 -0
- package/runtime/dist/src/personal-agent/schedule-reference.js +3 -0
- package/runtime/dist/src/personal-agent/scheduled-response-scope.js +38 -0
- package/runtime/dist/src/personal-agent/scheduled-run-authority.js +44 -0
- package/runtime/dist/src/personal-agent/scheduled-tasks.js +280 -0
- package/runtime/dist/src/personal-agent/scheduled-time.js +99 -0
- package/runtime/dist/src/personal-agent/scheduled-tool-runtime.js +109 -0
- package/runtime/dist/src/personal-agent/source-priority.js +142 -0
- package/runtime/dist/src/personal-agent/source-processing-agent.js +158 -0
- package/runtime/dist/src/personal-agent/source-walk.js +25 -0
- package/runtime/dist/src/personal-agent/sources.js +1484 -0
- package/runtime/dist/src/personal-agent/store-lock-worker.js +17 -0
- package/runtime/dist/src/personal-agent/store.js +146 -0
- package/runtime/dist/src/personal-agent/task-loop.js +163 -0
- package/runtime/dist/src/personal-agent/tasks.js +920 -0
- package/runtime/dist/src/personal-agent/turn-deadline.js +55 -0
- package/runtime/dist/src/personal-agent/understanding.js +160 -0
- package/runtime/dist/src/personal-agent/workbench-context.js +239 -0
- package/runtime/dist/src/projects/confirmed-project-capability.js +60 -0
- package/runtime/dist/src/projects/host-paths.js +133 -0
- package/runtime/dist/src/projects/managed-workspace-maintenance.js +351 -0
- package/runtime/dist/src/projects/project-confirmation.js +486 -0
- package/runtime/dist/src/projects/project-native-resource.js +284 -0
- package/runtime/dist/src/projects/project-node-files.js +169 -0
- package/runtime/dist/src/projects/project-root-file.js +16 -0
- package/runtime/dist/src/projects/project-state.js +504 -0
- package/runtime/dist/src/projects/project-store-files.js +1271 -0
- package/runtime/dist/src/projects/project-store.js +1345 -0
- package/runtime/dist/src/realtime/aoq.js +141 -0
- package/runtime/dist/src/realtime/bridge.js +652 -0
- package/runtime/dist/src/realtime/cascaded/adapter.js +1669 -0
- package/runtime/dist/src/realtime/cascaded/ark-llm.js +219 -0
- package/runtime/dist/src/realtime/cascaded/chat-completions-llm.js +478 -0
- package/runtime/dist/src/realtime/cascaded/gemini-speech.js +232 -0
- package/runtime/dist/src/realtime/cascaded/llm.js +37 -0
- package/runtime/dist/src/realtime/cascaded/ports.js +2 -0
- package/runtime/dist/src/realtime/cascaded/provider.js +216 -0
- package/runtime/dist/src/realtime/cascaded/qwen-llm.js +7 -0
- package/runtime/dist/src/realtime/cascaded/self-hosted-asr.js +110 -0
- package/runtime/dist/src/realtime/cascaded/self-hosted-tts.js +137 -0
- package/runtime/dist/src/realtime/cascaded/transcribe.js +42 -0
- package/runtime/dist/src/realtime/coding-progress-narration.js +28 -0
- package/runtime/dist/src/realtime/confirmation-turn-isolation.js +586 -0
- package/runtime/dist/src/realtime/dictation.js +28 -0
- package/runtime/dist/src/realtime/evidence.js +276 -0
- package/runtime/dist/src/realtime/floor.js +43 -0
- package/runtime/dist/src/realtime/frontend-instructions.js +195 -0
- package/runtime/dist/src/realtime/gemini.js +517 -0
- package/runtime/dist/src/realtime/history.js +122 -0
- package/runtime/dist/src/realtime/host-delivery.js +1711 -0
- package/runtime/dist/src/realtime/integrated-wire-profile.js +128 -0
- package/runtime/dist/src/realtime/memory-board.js +105 -0
- package/runtime/dist/src/realtime/openai-wire-profile.js +46 -0
- package/runtime/dist/src/realtime/playback.js +242 -0
- package/runtime/dist/src/realtime/project-confirmation-flow.js +1428 -0
- package/runtime/dist/src/realtime/prompt-language.js +17 -0
- package/runtime/dist/src/realtime/protocol.js +428 -0
- package/runtime/dist/src/realtime/provider-projection.js +526 -0
- package/runtime/dist/src/realtime/provider-session.js +491 -0
- package/runtime/dist/src/realtime/qwen-transport.js +144 -0
- package/runtime/dist/src/realtime/qwen.js +1377 -0
- package/runtime/dist/src/realtime/recall.js +341 -0
- package/runtime/dist/src/realtime/service-ports.js +8 -0
- package/runtime/dist/src/realtime/service-state.js +259 -0
- package/runtime/dist/src/realtime/service.js +1726 -0
- package/runtime/dist/src/realtime/session-state.js +684 -0
- package/runtime/dist/src/realtime/session.js +1976 -0
- package/runtime/dist/src/realtime/speech-prep.js +63 -0
- package/runtime/dist/src/realtime/streaming-speech.js +120 -0
- package/runtime/dist/src/realtime/system-prompts.en.js +136 -0
- package/runtime/dist/src/realtime/telemetry.js +144 -0
- package/runtime/dist/src/realtime/tool-continuations.js +1510 -0
- package/runtime/dist/src/realtime/transport.js +8 -0
- package/runtime/dist/src/realtime/usage.js +55 -0
- package/runtime/dist/src/realtime/user-origin-binding.js +173 -0
- package/runtime/dist/src/realtime/volcengine/ark.js +428 -0
- package/runtime/dist/src/realtime/volcengine/asr.js +573 -0
- package/runtime/dist/src/realtime/volcengine/audio.js +39 -0
- package/runtime/dist/src/realtime/volcengine/endpointing-capability.js +834 -0
- package/runtime/dist/src/realtime/volcengine/livekit-endpointing.js +714 -0
- package/runtime/dist/src/realtime/volcengine/local-eot-executor.js +33 -0
- package/runtime/dist/src/realtime/volcengine/protocol.js +247 -0
- package/runtime/dist/src/realtime/volcengine/silence-endpointing.js +237 -0
- package/runtime/dist/src/realtime/volcengine/tts.js +444 -0
- package/runtime/dist/src/realtime/volcengine/websocket.js +293 -0
- package/runtime/dist/src/server/aoq-chat-server.js +497 -0
- package/runtime/dist/src/server/client-pairing.js +192 -0
- package/runtime/dist/src/server/client-protocol.js +87 -0
- package/runtime/dist/src/server/client-server.js +312 -0
- package/runtime/dist/src/server/server-config.js +72 -0
- package/runtime/dist/src/server-entry.js +135 -0
- package/runtime/dist/src/storage/bounded-json.js +63 -0
- package/runtime/dist/src/storage/native-file-lock.js +8 -0
- package/runtime/dist/src/storage/native-resource-snapshot.js +41 -0
- package/runtime/dist/src/storage/private-database.js +120 -0
- package/runtime/dist/src/text/canonical-json.js +60 -0
- package/runtime/dist/src/text/python-number.js +18 -0
- package/runtime/dist/src/text/python-text.js +92 -0
- package/runtime/dist/src/text/unicode-casefold.js +29 -0
- package/runtime/dist/src/text/unicode-normalize.js +138 -0
- package/runtime/dist/src/text/unicode-tables.js +210 -0
- package/runtime/dist/src/understanding/candidates.js +77 -0
- package/runtime/dist/src/understanding/fixture.js +7 -0
- package/runtime/dist/src/understanding/jev.js +20 -0
- package/runtime/dist/src/understanding/pipeline.js +38 -0
- package/runtime/dist/src/voicemem/store-client.js +476 -0
- package/runtime/dist/src/voicemem/store-worker.js +380 -0
- package/runtime/dist/src/voicemem/versioned-memory.js +170 -0
- package/runtime/scripts/pair-device.mjs +109 -0
- package/src/command.mjs +48 -0
|
@@ -0,0 +1,526 @@
|
|
|
1
|
+
import { notificationResultText } from '../notifications/content.js';
|
|
2
|
+
import { canonicalJson } from '../text/canonical-json.js';
|
|
3
|
+
import { codingProgressSummary } from './coding-progress-narration.js';
|
|
4
|
+
import { validProgressSummary } from '../core/events.js';
|
|
5
|
+
import { isMonitorPolicy, isPreemptiveMonitorAlert, monitorAlertDelivery, parseMemoryRef } from '../core/memory.js';
|
|
6
|
+
import { stripLikePython } from '../text/python-text.js';
|
|
7
|
+
import { finalSpeechView, genericFinalSpeechView } from './evidence.js';
|
|
8
|
+
import { HIT_ALERT_MIN_PRIORITY, MAX_HOST_FACT_CHARS, PREEMPT_MIN_PRIORITY, PROGRESS_HOST_ITEM_TTL_S, diagnosticName, hostFactIntent } from './service-state.js';
|
|
9
|
+
import { activeExecutorContextData } from './session-state.js';
|
|
10
|
+
import {} from './session.js';
|
|
11
|
+
import { SPEECH_FINAL_LIMIT, prepareForSpeech } from './speech-prep.js';
|
|
12
|
+
function suggestionSpeechView(content) {
|
|
13
|
+
for (const key of ['observation', 'summary', 'message']) {
|
|
14
|
+
const value = content[key];
|
|
15
|
+
if (typeof value === 'string' && stripLikePython(value) !== '') {
|
|
16
|
+
return prepareForSpeech(value, { limit: SPEECH_FINAL_LIMIT }).text;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return '有一条新的提醒';
|
|
20
|
+
}
|
|
21
|
+
function monitorHitSpeechView(content) {
|
|
22
|
+
for (const key of ['observation', 'summary', 'message']) {
|
|
23
|
+
const value = content[key];
|
|
24
|
+
if (typeof value === 'string' && stripLikePython(value) !== '') {
|
|
25
|
+
return prepareForSpeech(`检测到了:${stripLikePython(value)}`, {
|
|
26
|
+
limit: SPEECH_FINAL_LIMIT,
|
|
27
|
+
}).text;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return '检测到了,提醒条件已经满足。';
|
|
31
|
+
}
|
|
32
|
+
export class ProviderProjection {
|
|
33
|
+
ports;
|
|
34
|
+
executorDisplayName(channel) {
|
|
35
|
+
const agent = this.ports.agentNameForChannel(channel);
|
|
36
|
+
if (agent !== null)
|
|
37
|
+
return agent;
|
|
38
|
+
const manifest = this.ports.runtime.executors.get(channel)?.manifest;
|
|
39
|
+
if (manifest !== undefined && isMonitorPolicy(manifest.policy)) {
|
|
40
|
+
return monitorAlertDelivery(manifest.policy) === 'deferred' ? '观察' : '监控';
|
|
41
|
+
}
|
|
42
|
+
return manifest?.display_name ?? channel;
|
|
43
|
+
}
|
|
44
|
+
/** A channel's manifest priority, or the default when there is no manifest for it. */
|
|
45
|
+
executorPriority(channel) {
|
|
46
|
+
if (channel === null)
|
|
47
|
+
return 50;
|
|
48
|
+
return this.ports.runtime.executors.get(channel)?.manifest.policy.priority ?? 50;
|
|
49
|
+
}
|
|
50
|
+
get executorState() { return this.#executorState; }
|
|
51
|
+
setExecutorStateForTest(state) { this.#executorState = state; this.ports.onExecutorState(state); }
|
|
52
|
+
/**
|
|
53
|
+
* Tell the renderer whether Codex is working, when that changes.
|
|
54
|
+
*
|
|
55
|
+
* Derived from the session's live delegates rather than counted here: the session is what knows
|
|
56
|
+
* when one finishes, and a separate counter would drift the moment a delegate ended by any route
|
|
57
|
+
* this layer does not see.
|
|
58
|
+
*/
|
|
59
|
+
publishExecutorState() {
|
|
60
|
+
const delegates = this.ports.session.snapshot().active_delegates;
|
|
61
|
+
const fingerprint = canonicalJson(activeExecutorContextData(delegates, channel => this.ports.agentNameForChannel(channel)));
|
|
62
|
+
if (fingerprint !== this.#activeWorkFingerprint) {
|
|
63
|
+
this.#activeWorkFingerprint = fingerprint;
|
|
64
|
+
if (!this.ports.clearingConversation()) {
|
|
65
|
+
try {
|
|
66
|
+
this.ports.onActiveWorkChanged();
|
|
67
|
+
}
|
|
68
|
+
catch (cause) {
|
|
69
|
+
this.ports.onDiagnostic(`[realtime-diagnostic] active_work_observer_failed type=${diagnosticName(cause)}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const next = delegates.some(([, record]) => record.channel === this.ports.coding?.channel)
|
|
74
|
+
? 'running'
|
|
75
|
+
: this.ports.preparing() ? 'preparing' : 'idle';
|
|
76
|
+
if (next === this.#executorState)
|
|
77
|
+
return;
|
|
78
|
+
this.#executorState = next;
|
|
79
|
+
try {
|
|
80
|
+
this.ports.onExecutorState(next);
|
|
81
|
+
}
|
|
82
|
+
catch (cause) {
|
|
83
|
+
// A renderer that cannot accept the state must not stop the service that produced it.
|
|
84
|
+
this.ports.onDiagnostic(`[realtime-diagnostic] codex_state_observer_failed type=${diagnosticName(cause)}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** Compact fingerprint of delegate progress for context refresh. */
|
|
88
|
+
#activeWorkFingerprint = canonicalJson(activeExecutorContextData([]));
|
|
89
|
+
#executorState = 'idle';
|
|
90
|
+
#lastProgressSummary = new Map();
|
|
91
|
+
#startedDelegates = new Set();
|
|
92
|
+
constructor(ports) {
|
|
93
|
+
this.ports = ports;
|
|
94
|
+
}
|
|
95
|
+
reset() { this.#lastProgressSummary.clear(); this.#startedDelegates.clear(); }
|
|
96
|
+
/** Resolve synchronous results before ordinary channel projection can consume them. */
|
|
97
|
+
projectRuntimeEvent(event, currentConversation = true) {
|
|
98
|
+
if (!currentConversation) {
|
|
99
|
+
this.#settleHistoricalRuntimeEvent(event);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (event.kind === 'handoff')
|
|
103
|
+
this.ports.telemetry?.record('tool.finished', {
|
|
104
|
+
executor: event.payload.channel, delegate_id: event.payload.delegate_id, outcome: event.payload.outcome,
|
|
105
|
+
});
|
|
106
|
+
if (event.kind === 'handoff' && this.ports.resolveSyncResult(event))
|
|
107
|
+
return;
|
|
108
|
+
if (event.kind === 'deadline') {
|
|
109
|
+
if (this.ports.expireSyncResult(event))
|
|
110
|
+
return;
|
|
111
|
+
this.#projectDeadline(event);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (event.kind !== 'progress' && event.kind !== 'observation' && event.kind !== 'handoff') {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const manifest = this.ports.runtime.executors.get(event.payload.channel)?.manifest;
|
|
118
|
+
if (manifest === undefined)
|
|
119
|
+
return;
|
|
120
|
+
if (event.payload.channel === this.ports.coding?.channel && this.ports.telemetry !== undefined) {
|
|
121
|
+
if (event.kind === 'progress') {
|
|
122
|
+
this.ports.telemetry.record('executor.progress', {
|
|
123
|
+
delegate_id: event.payload.delegate_id,
|
|
124
|
+
phase: event.payload.phase,
|
|
125
|
+
internal_activity: event.payload.internal_activity,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
else if (event.kind === 'handoff') {
|
|
129
|
+
this.ports.telemetry.record('executor.handoff', {
|
|
130
|
+
delegate_id: event.payload.delegate_id,
|
|
131
|
+
outcome: event.payload.outcome,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (event.kind === 'observation') {
|
|
136
|
+
this.#projectObservation(event, manifest);
|
|
137
|
+
}
|
|
138
|
+
else if (event.kind === 'progress') {
|
|
139
|
+
this.#projectProgress(event, manifest);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
this.#projectHandoff(event, manifest);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
#settleHistoricalRuntimeEvent(event) {
|
|
146
|
+
if (event.kind !== 'handoff' && event.kind !== 'deadline')
|
|
147
|
+
return;
|
|
148
|
+
const delegateId = event.payload.delegate_id;
|
|
149
|
+
let delegate;
|
|
150
|
+
if (event.kind === 'handoff') {
|
|
151
|
+
delegate = this.ports.runtime.claimedHandoff(event.seq);
|
|
152
|
+
if (delegate?.executor !== event.payload.channel)
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
else if (this.ports.runtime.terminatedByDeadline(event.seq, delegateId)) {
|
|
156
|
+
delegate = this.ports.runtime.delegateFor(delegateId);
|
|
157
|
+
}
|
|
158
|
+
if (delegate?.delegate_id !== delegateId)
|
|
159
|
+
return;
|
|
160
|
+
const channel = delegate.executor;
|
|
161
|
+
this.ports.session.registerDelegate(delegateId, {
|
|
162
|
+
summary: this.#delegateSummary(delegateId, this.executorDisplayName(channel)),
|
|
163
|
+
state: event.kind === 'deadline'
|
|
164
|
+
? 'unknown'
|
|
165
|
+
: event.payload.content.code === 'model_finished' && event.payload.content.verified === false ? 'unknown'
|
|
166
|
+
: event.payload.outcome === 'ok'
|
|
167
|
+
? 'completed'
|
|
168
|
+
: event.payload.outcome === 'refused'
|
|
169
|
+
? 'refused'
|
|
170
|
+
: event.payload.outcome === 'unknown' ? 'unknown' : 'failed',
|
|
171
|
+
channel,
|
|
172
|
+
progress_summary: null,
|
|
173
|
+
internal_activity: 0,
|
|
174
|
+
elapsed: 0,
|
|
175
|
+
});
|
|
176
|
+
this.#lastProgressSummary.delete(delegateId);
|
|
177
|
+
this.#startedDelegates.delete(delegateId);
|
|
178
|
+
this.publishExecutorState();
|
|
179
|
+
}
|
|
180
|
+
onSuggestionSelected(suggestion, reason) {
|
|
181
|
+
const progress = this.#isSelectedProgress(suggestion);
|
|
182
|
+
const coding = progress && suggestion.evidence_refs[0]?.startsWith(`${this.ports.coding?.channel}:`) === true;
|
|
183
|
+
if (coding && this.ports.codingProgressNarration.mode !== 'smart')
|
|
184
|
+
return;
|
|
185
|
+
const delegate = coding && reason.origin !== null ? this.ports.runtime.inFlightDelegate(reason.origin) : undefined;
|
|
186
|
+
if (coding && delegate?.executor !== this.ports.coding?.channel)
|
|
187
|
+
return;
|
|
188
|
+
if (coding) {
|
|
189
|
+
this.ports.rememberCodingProgressHostEvent(`suggestion:${suggestion.id}`);
|
|
190
|
+
this.ports.rememberDelegateHostEvent(reason.origin, `suggestion:${suggestion.id}`);
|
|
191
|
+
}
|
|
192
|
+
const hit = suggestion.content.hit === true;
|
|
193
|
+
this.ports.queueHostItem(hostFactIntent({
|
|
194
|
+
kind: this.#isSelectedProgress(suggestion) ? 'progress' : 'final',
|
|
195
|
+
host_item_id: this.ports.idFactory(),
|
|
196
|
+
event_id: `suggestion:${suggestion.id}`,
|
|
197
|
+
...(reason.origin === null ? {} : { source: this.#workSource(reason.origin) }),
|
|
198
|
+
content: suggestionSpeechView(suggestion.content),
|
|
199
|
+
}), {
|
|
200
|
+
priority: hit ? Math.max(reason.priority, HIT_ALERT_MIN_PRIORITY) : reason.priority,
|
|
201
|
+
preemptive: false,
|
|
202
|
+
...(coding ? { owner: { delegate_id: reason.origin, channel: delegate.executor }, expiresAt: this.ports.clock.now() + PROGRESS_HOST_ITEM_TTL_S } : {}),
|
|
203
|
+
stillWanted: () => suggestion.expires_at > this.ports.clock.now() && suggestion.evidence_refs.every(ref => { try {
|
|
204
|
+
const [channel, seq] = parseMemoryRef(ref);
|
|
205
|
+
return this.ports.runtime.memory?.channels.get(channel)?.items.some(item => item.seq === seq) === true;
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
return true;
|
|
209
|
+
} }),
|
|
210
|
+
}, undefined, typeof suggestion.content.personal_feed_id === 'string', suggestion.evidence_refs);
|
|
211
|
+
}
|
|
212
|
+
#isSelectedProgress(suggestion) {
|
|
213
|
+
if (suggestion.evidence_refs.length !== 1)
|
|
214
|
+
return false;
|
|
215
|
+
const summary = suggestion.content.summary;
|
|
216
|
+
if (typeof summary !== 'string')
|
|
217
|
+
return false;
|
|
218
|
+
const memory = this.ports.runtime.memory;
|
|
219
|
+
if (memory === undefined)
|
|
220
|
+
return false;
|
|
221
|
+
const reference = suggestion.evidence_refs[0];
|
|
222
|
+
if (reference === undefined)
|
|
223
|
+
return false;
|
|
224
|
+
let channelName;
|
|
225
|
+
let sequence;
|
|
226
|
+
try {
|
|
227
|
+
[channelName, sequence] = parseMemoryRef(reference);
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
const policy = memory.policies.get(channelName);
|
|
233
|
+
const evidence = memory.channels.get(channelName)?.items.find(item => item.seq === sequence);
|
|
234
|
+
return policy?.progress_via_surrogate === true
|
|
235
|
+
&& evidence?.channel === channelName
|
|
236
|
+
&& evidence.seq === sequence
|
|
237
|
+
&& evidence.content.phase === 'working'
|
|
238
|
+
&& evidence.content.summary === summary;
|
|
239
|
+
}
|
|
240
|
+
#projectDeadline(event) {
|
|
241
|
+
const delegateId = event.payload.delegate_id;
|
|
242
|
+
// This exact event, not "was terminated by a deadline at some point": a second deadline for the
|
|
243
|
+
// same delegate would otherwise announce the same timeout twice.
|
|
244
|
+
if (!this.ports.runtime.terminatedByDeadline(event.seq, delegateId))
|
|
245
|
+
return;
|
|
246
|
+
const delegate = this.ports.runtime.delegateFor(delegateId);
|
|
247
|
+
if (delegate === undefined)
|
|
248
|
+
return;
|
|
249
|
+
const manifest = this.ports.runtime.executors.get(delegate.executor)?.manifest;
|
|
250
|
+
const operation = manifest?.ops.find(candidate => candidate.name === delegate.op);
|
|
251
|
+
if (manifest === undefined || operation === undefined || operation.sync_result === true)
|
|
252
|
+
return;
|
|
253
|
+
const displayName = this.executorDisplayName(delegate.executor);
|
|
254
|
+
this.ports.session.registerDelegate(delegateId, {
|
|
255
|
+
summary: this.#delegateSummary(delegateId, displayName),
|
|
256
|
+
state: 'unknown',
|
|
257
|
+
channel: delegate.executor,
|
|
258
|
+
progress_summary: null,
|
|
259
|
+
internal_activity: 0,
|
|
260
|
+
elapsed: 0,
|
|
261
|
+
});
|
|
262
|
+
// A settled delegate leaves no dedup residue behind, or a later run of the same delegate id would
|
|
263
|
+
// inherit a summary it never produced.
|
|
264
|
+
this.#lastProgressSummary.delete(delegateId);
|
|
265
|
+
this.#startedDelegates.delete(delegateId);
|
|
266
|
+
this.publishExecutorState();
|
|
267
|
+
this.ports.queueHostItem(hostFactIntent({
|
|
268
|
+
kind: 'final',
|
|
269
|
+
host_item_id: this.ports.idFactory(),
|
|
270
|
+
event_id: `deadline:${delegateId}`,
|
|
271
|
+
source: this.#workSource(delegateId, event.seq),
|
|
272
|
+
content: `${displayName} 的委派任务超时,未能确认结果。`,
|
|
273
|
+
}), { priority: manifest.policy.priority });
|
|
274
|
+
}
|
|
275
|
+
#projectObservation(event, manifest) {
|
|
276
|
+
const delegate = this.#observationDelegate(event);
|
|
277
|
+
if (delegate === undefined)
|
|
278
|
+
return;
|
|
279
|
+
const displayName = this.executorDisplayName(event.payload.channel);
|
|
280
|
+
this.ports.session.registerDelegate(event.payload.delegate_id, {
|
|
281
|
+
summary: this.#delegateSummary(event.payload.delegate_id, displayName),
|
|
282
|
+
state: 'running',
|
|
283
|
+
channel: event.payload.channel,
|
|
284
|
+
});
|
|
285
|
+
this.publishExecutorState();
|
|
286
|
+
if (event.payload.content.hit !== true)
|
|
287
|
+
return;
|
|
288
|
+
if (manifest.policy.suggest === true && delegate.routing_class === 'ambient')
|
|
289
|
+
return;
|
|
290
|
+
const monitor = isMonitorPolicy(manifest.policy);
|
|
291
|
+
const delivery = monitorAlertDelivery(manifest.policy);
|
|
292
|
+
// A none monitor still records the hit and updates delegate state above, but does not address it
|
|
293
|
+
// to the user or take their floor.
|
|
294
|
+
if (monitor && delivery === 'none')
|
|
295
|
+
return;
|
|
296
|
+
const speechView = monitor
|
|
297
|
+
? monitorHitSpeechView(event.payload.content)
|
|
298
|
+
: genericFinalSpeechView(displayName, 'ok', event.payload.content);
|
|
299
|
+
const content = [...speechView]
|
|
300
|
+
.slice(0, MAX_HOST_FACT_CHARS)
|
|
301
|
+
.join('');
|
|
302
|
+
this.ports.queueHostItem(hostFactIntent({
|
|
303
|
+
kind: 'final',
|
|
304
|
+
host_item_id: this.ports.idFactory(),
|
|
305
|
+
event_id: `observation:${event.payload.delegate_id}:${event.seq}`,
|
|
306
|
+
source: this.#workSource(event.payload.delegate_id, event.seq),
|
|
307
|
+
content,
|
|
308
|
+
}), {
|
|
309
|
+
// A monitoring hit outranks routine executor announcements; only its policy may authorize a floor preempt.
|
|
310
|
+
priority: Math.max(manifest.policy.priority, HIT_ALERT_MIN_PRIORITY),
|
|
311
|
+
preemptive: monitor
|
|
312
|
+
? isPreemptiveMonitorAlert(manifest.policy)
|
|
313
|
+
: manifest.policy.priority >= PREEMPT_MIN_PRIORITY,
|
|
314
|
+
preemptiveAlert: isPreemptiveMonitorAlert(manifest.policy),
|
|
315
|
+
preemptiveAlertDelegateId: isPreemptiveMonitorAlert(manifest.policy) ? event.payload.delegate_id : null,
|
|
316
|
+
}, undefined, false, event.payload.refs);
|
|
317
|
+
}
|
|
318
|
+
#observationDelegate(event) {
|
|
319
|
+
const delegate = this.ports.runtime.inFlightDelegate(event.payload.delegate_id);
|
|
320
|
+
if (delegate === undefined)
|
|
321
|
+
return undefined;
|
|
322
|
+
if (event.payload.channel !== delegate.executor
|
|
323
|
+
|| event.payload.op !== delegate.op
|
|
324
|
+
|| event.payload.origin_ref !== delegate.origin_ref) {
|
|
325
|
+
return undefined;
|
|
326
|
+
}
|
|
327
|
+
return delegate;
|
|
328
|
+
}
|
|
329
|
+
#projectProgress(event, manifest) {
|
|
330
|
+
const payload = event.payload;
|
|
331
|
+
if (payload.op === ''
|
|
332
|
+
|| !Number.isInteger(payload.internal_activity)
|
|
333
|
+
|| !Number.isFinite(payload.elapsed)
|
|
334
|
+
|| payload.elapsed < 0
|
|
335
|
+
|| (payload.phase === 'started' && payload.internal_activity !== 0)
|
|
336
|
+
|| (payload.phase === 'working'
|
|
337
|
+
&& !(payload.internal_activity >= 1 && payload.internal_activity <= 1_048_576))) {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
const delegate = this.ports.runtime.inFlightDelegate(payload.delegate_id);
|
|
341
|
+
if (delegate?.executor !== payload.channel || delegate.op !== payload.op)
|
|
342
|
+
return;
|
|
343
|
+
const displayName = this.executorDisplayName(payload.channel);
|
|
344
|
+
const coding = payload.channel === this.ports.coding?.channel;
|
|
345
|
+
let summary = payload.summary;
|
|
346
|
+
if (!validProgressSummary(summary, payload.phase))
|
|
347
|
+
summary = null;
|
|
348
|
+
if (summary !== null) {
|
|
349
|
+
// CP2: prepared once at the storage boundary, so the recovery frame the session renders never
|
|
350
|
+
// carries raw markdown either.
|
|
351
|
+
summary = coding ? codingProgressSummary(summary) : prepareForSpeech(summary, { limit: SPEECH_FINAL_LIMIT }).text || null;
|
|
352
|
+
}
|
|
353
|
+
const previousSummary = this.#lastProgressSummary.get(payload.delegate_id);
|
|
354
|
+
// Keep received facts current even when smart mode suppresses delivery.
|
|
355
|
+
if (coding && payload.phase === 'working' && summary !== null) {
|
|
356
|
+
this.#lastProgressSummary.set(payload.delegate_id, summary);
|
|
357
|
+
}
|
|
358
|
+
this.ports.session.registerDelegate(payload.delegate_id, {
|
|
359
|
+
summary: this.#delegateSummary(payload.delegate_id, displayName),
|
|
360
|
+
state: 'running',
|
|
361
|
+
channel: payload.channel,
|
|
362
|
+
progress_summary: summary,
|
|
363
|
+
internal_activity: payload.internal_activity,
|
|
364
|
+
elapsed: payload.elapsed,
|
|
365
|
+
});
|
|
366
|
+
this.publishExecutorState();
|
|
367
|
+
if (manifest.ops.find(op => op.name === delegate.op)?.sync_result === true
|
|
368
|
+
|| (manifest.roles.includes('coding') && delegate.op === 'steer'))
|
|
369
|
+
return;
|
|
370
|
+
// Preparation and actual execution are different lifecycle facts. Deduplicate by delegate,
|
|
371
|
+
// never by spoken text, and let normal owner/expiry fences suppress obsolete startup facts.
|
|
372
|
+
if (coding && payload.phase === 'started') {
|
|
373
|
+
if (this.#startedDelegates.has(payload.delegate_id))
|
|
374
|
+
return;
|
|
375
|
+
this.#startedDelegates.add(payload.delegate_id);
|
|
376
|
+
}
|
|
377
|
+
if (!coding && payload.phase === 'started'
|
|
378
|
+
&& this.ports.hasSemanticAcknowledgement(`background:${payload.delegate_id}`))
|
|
379
|
+
return;
|
|
380
|
+
// A monitor's periodic heartbeat is operational state, not a new user-facing event. Speaking it
|
|
381
|
+
// creates a fresh model turn that can accidentally replay an older acknowledgement.
|
|
382
|
+
if (isMonitorPolicy(manifest.policy) && payload.phase === 'working')
|
|
383
|
+
return;
|
|
384
|
+
if (payload.phase === 'working') {
|
|
385
|
+
if (this.ports.codingProgressNarration.viaProactive(coding, manifest.policy.progress_via_surrogate === true))
|
|
386
|
+
return;
|
|
387
|
+
if (coding && this.ports.codingProgressNarration.mode === 'continuous' && summary === null)
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
let content;
|
|
391
|
+
if (payload.phase === 'started') {
|
|
392
|
+
content = coding ? `交给 ${manifest.display_name} 执行。` : `${displayName} 已开始处理这个任务。`;
|
|
393
|
+
}
|
|
394
|
+
else if (summary !== null) {
|
|
395
|
+
// Same-summary skip: state registration already happened, only the host injection is
|
|
396
|
+
// suppressed. A summary-less event keeps the field template and is never deduped this way.
|
|
397
|
+
if (previousSummary === summary)
|
|
398
|
+
return;
|
|
399
|
+
this.#lastProgressSummary.set(payload.delegate_id, summary);
|
|
400
|
+
content = `${displayName} 正在执行:${summary}`;
|
|
401
|
+
}
|
|
402
|
+
else {
|
|
403
|
+
content = `${displayName} 仍在处理这个任务,目前已推进 ${payload.internal_activity} 个步骤。`;
|
|
404
|
+
}
|
|
405
|
+
const eventId = `progress:${payload.delegate_id}:${payload.phase}:${payload.internal_activity}`;
|
|
406
|
+
if (coding && payload.phase === 'working') {
|
|
407
|
+
// Coalesce queued updates per task; the latest fact retains existing owner/floor/expiry fences.
|
|
408
|
+
if (this.ports.codingProgressNarration.mode === 'continuous') {
|
|
409
|
+
this.ports.retireDelegateHostEvents(payload.delegate_id);
|
|
410
|
+
this.ports.coalesceCodingProgress();
|
|
411
|
+
}
|
|
412
|
+
this.ports.rememberCodingProgressHostEvent(eventId);
|
|
413
|
+
}
|
|
414
|
+
this.ports.rememberDelegateHostEvent(payload.delegate_id, eventId);
|
|
415
|
+
this.ports.queueHostItem(hostFactIntent({
|
|
416
|
+
kind: 'progress',
|
|
417
|
+
host_item_id: this.ports.idFactory(),
|
|
418
|
+
event_id: eventId,
|
|
419
|
+
source: this.#workSource(payload.delegate_id, event.seq),
|
|
420
|
+
content,
|
|
421
|
+
}), {
|
|
422
|
+
priority: manifest.policy.priority,
|
|
423
|
+
owner: { delegate_id: payload.delegate_id, channel: payload.channel },
|
|
424
|
+
expiresAt: this.ports.clock.now() + PROGRESS_HOST_ITEM_TTL_S,
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
#projectHandoff(event, manifest) {
|
|
428
|
+
// Only the delegate *this* handoff claimed. A duplicate, or one for an already-settled delegate,
|
|
429
|
+
// claims nothing and must not be projected against whatever the previous one claimed.
|
|
430
|
+
const claimed = this.ports.runtime.claimedHandoff(event.seq);
|
|
431
|
+
if (claimed?.executor !== event.payload.channel)
|
|
432
|
+
return;
|
|
433
|
+
const payload = event.payload;
|
|
434
|
+
const displayName = this.executorDisplayName(payload.channel);
|
|
435
|
+
this.ports.fenceSemanticAcknowledgement(payload.delegate_id);
|
|
436
|
+
this.ports.retireDelegateHostEvents(payload.delegate_id);
|
|
437
|
+
const directSuggestionHandoff = manifest.policy.suggest === true
|
|
438
|
+
&& payload.outcome === 'ok'
|
|
439
|
+
&& claimed.routing_class === 'user_awaited';
|
|
440
|
+
const suppressUnselectedSuggestion = manifest.policy.suggest === true
|
|
441
|
+
&& payload.outcome === 'ok'
|
|
442
|
+
&& !directSuggestionHandoff;
|
|
443
|
+
this.ports.session.registerDelegate(payload.delegate_id, {
|
|
444
|
+
summary: this.#delegateSummary(payload.delegate_id, displayName),
|
|
445
|
+
state: payload.content.code === 'model_finished' && payload.content.verified === false ? 'unknown' : payload.outcome === 'ok'
|
|
446
|
+
? 'completed'
|
|
447
|
+
: payload.outcome === 'refused'
|
|
448
|
+
? 'refused'
|
|
449
|
+
: payload.outcome === 'unknown' ? 'unknown' : 'failed',
|
|
450
|
+
channel: payload.channel,
|
|
451
|
+
});
|
|
452
|
+
// CP1: a settled delegate leaves no dedup residue behind.
|
|
453
|
+
this.#lastProgressSummary.delete(payload.delegate_id);
|
|
454
|
+
this.#startedDelegates.delete(payload.delegate_id);
|
|
455
|
+
this.publishExecutorState();
|
|
456
|
+
// Tracked tasks publish only after host verification, never from executor terminal prose.
|
|
457
|
+
if (this.ports.taskOwnsWork?.(payload.delegate_id))
|
|
458
|
+
return;
|
|
459
|
+
if (manifest.ops.find(op => op.name === claimed.op)?.sync_result === true
|
|
460
|
+
|| (manifest.roles.includes('coding') && claimed.op === 'steer'))
|
|
461
|
+
return;
|
|
462
|
+
if (isMonitorPolicy(manifest.policy)
|
|
463
|
+
&& monitorAlertDelivery(manifest.policy) === 'none'
|
|
464
|
+
&& payload.outcome === 'ok'
|
|
465
|
+
&& payload.content.hit === true)
|
|
466
|
+
return;
|
|
467
|
+
if (suppressUnselectedSuggestion)
|
|
468
|
+
return;
|
|
469
|
+
const successfulMonitorStop = isMonitorPolicy(manifest.policy)
|
|
470
|
+
&& payload.outcome === 'ok'
|
|
471
|
+
&& ((claimed.op === 'stop' && payload.content.stopped === true)
|
|
472
|
+
|| (claimed.op === 'start' && payload.content.state === 'stopped'));
|
|
473
|
+
if (successfulMonitorStop)
|
|
474
|
+
return;
|
|
475
|
+
const finalView = payload.channel === this.ports.coding?.channel
|
|
476
|
+
? finalSpeechView(payload.outcome, payload.content, this.ports.coding.display_name)
|
|
477
|
+
: genericFinalSpeechView(displayName, payload.outcome, payload.content);
|
|
478
|
+
const task = payload.channel === this.ports.coding?.channel ? claimed.request?.work_order : null;
|
|
479
|
+
// Fact-only narration has no dialogue history. Keep this result tied to its own task,
|
|
480
|
+
// without restoring unrelated history or treating requested work as proof of execution.
|
|
481
|
+
const taskContext = typeof task === 'string'
|
|
482
|
+
? `\n本次任务上下文(不是执行结果,不复述):${JSON.stringify([...task].slice(0, 1600).join(''))}`
|
|
483
|
+
: '';
|
|
484
|
+
const content = [...(finalView + taskContext)].slice(0, MAX_HOST_FACT_CHARS).join('');
|
|
485
|
+
const hit = payload.outcome === 'ok' && payload.content.hit === true;
|
|
486
|
+
const preemptiveMonitorHit = hit && isPreemptiveMonitorAlert(manifest.policy);
|
|
487
|
+
this.ports.queueHostItem(hostFactIntent({
|
|
488
|
+
kind: 'final',
|
|
489
|
+
host_item_id: this.ports.idFactory(),
|
|
490
|
+
event_id: `final:${payload.delegate_id}`,
|
|
491
|
+
source: this.#workSource(payload.delegate_id, event.seq),
|
|
492
|
+
content,
|
|
493
|
+
}), {
|
|
494
|
+
priority: hit
|
|
495
|
+
? Math.max(manifest.policy.priority, HIT_ALERT_MIN_PRIORITY)
|
|
496
|
+
: manifest.policy.priority,
|
|
497
|
+
preemptive: hit && (isMonitorPolicy(manifest.policy)
|
|
498
|
+
? isPreemptiveMonitorAlert(manifest.policy)
|
|
499
|
+
: manifest.policy.priority >= PREEMPT_MIN_PRIORITY),
|
|
500
|
+
preemptiveAlert: preemptiveMonitorHit,
|
|
501
|
+
preemptiveAlertDelegateId: preemptiveMonitorHit ? payload.delegate_id : null,
|
|
502
|
+
}, notificationResultText(payload.content, finalView), false, payload.refs);
|
|
503
|
+
}
|
|
504
|
+
#workSource(delegateId, eventSeq) {
|
|
505
|
+
const record = this.ports.session.delegateRecord(delegateId);
|
|
506
|
+
const delegate = this.ports.runtime.delegateFor(delegateId);
|
|
507
|
+
const channel = record?.channel ?? delegate?.executor;
|
|
508
|
+
if (channel === undefined)
|
|
509
|
+
return undefined;
|
|
510
|
+
const request = channel === this.ports.coding?.channel ? delegate?.request : undefined;
|
|
511
|
+
const label = (value) => value === undefined
|
|
512
|
+
? undefined : [...value.replace(/[\p{C}]/gu, '')].slice(0, 120).join('') || undefined;
|
|
513
|
+
const project = label(record?.project ?? (typeof request?.project === 'string' ? request.project : undefined));
|
|
514
|
+
const title = label(record?.title ?? (typeof request?.title === 'string' ? request.title : undefined));
|
|
515
|
+
return { work_id: delegateId, ...(eventSeq === undefined ? {} : { event_seq: eventSeq }), executor: this.ports.agentNameForChannel(channel) ?? channel,
|
|
516
|
+
...(project === undefined ? {} : { project }), ...(title === undefined ? {} : { title }) };
|
|
517
|
+
}
|
|
518
|
+
#delegateSummary(delegateId, displayName) {
|
|
519
|
+
for (const [currentId, record] of this.ports.session.snapshot().active_delegates) {
|
|
520
|
+
if (currentId === delegateId)
|
|
521
|
+
return record.summary;
|
|
522
|
+
}
|
|
523
|
+
return `${displayName} background task`;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
//# sourceMappingURL=provider-projection.js.map
|