nova-personal-agent-server 0.0.0-stage → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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,55 @@
|
|
|
1
|
+
/** Human decision time is unbounded here; approval controllers own their own expiry policy. */
|
|
2
|
+
export function createTurnDeadline(options) {
|
|
3
|
+
const controller = new AbortController();
|
|
4
|
+
let timer;
|
|
5
|
+
let unsubscribe;
|
|
6
|
+
let waiting;
|
|
7
|
+
let closed = false;
|
|
8
|
+
const close = () => {
|
|
9
|
+
if (closed)
|
|
10
|
+
return;
|
|
11
|
+
closed = true;
|
|
12
|
+
timer?.abort();
|
|
13
|
+
unsubscribe?.();
|
|
14
|
+
options.parent.removeEventListener('abort', onParentAbort);
|
|
15
|
+
};
|
|
16
|
+
const abort = (reason) => { close(); controller.abort(reason); };
|
|
17
|
+
const onParentAbort = () => abort(options.parent.reason);
|
|
18
|
+
const refresh = () => {
|
|
19
|
+
if (closed)
|
|
20
|
+
return;
|
|
21
|
+
const next = options.isWaiting();
|
|
22
|
+
if (waiting === next)
|
|
23
|
+
return;
|
|
24
|
+
waiting = next;
|
|
25
|
+
timer?.abort();
|
|
26
|
+
if (waiting)
|
|
27
|
+
return;
|
|
28
|
+
const current = new AbortController();
|
|
29
|
+
timer = current;
|
|
30
|
+
void options.clock.sleep(120, current.signal).then(() => {
|
|
31
|
+
if (closed || current.signal.aborted)
|
|
32
|
+
return;
|
|
33
|
+
if (options.isWaiting()) {
|
|
34
|
+
refresh();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
abort(new DOMException('Conversation turn timed out', 'TimeoutError'));
|
|
38
|
+
}, error => {
|
|
39
|
+
if (!closed && !current.signal.aborted)
|
|
40
|
+
abort(error);
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
if (options.parent.aborted)
|
|
44
|
+
onParentAbort();
|
|
45
|
+
else {
|
|
46
|
+
options.parent.addEventListener('abort', onParentAbort, { once: true });
|
|
47
|
+
unsubscribe = options.subscribe(refresh);
|
|
48
|
+
if (closed)
|
|
49
|
+
unsubscribe();
|
|
50
|
+
else
|
|
51
|
+
refresh();
|
|
52
|
+
}
|
|
53
|
+
return { signal: controller.signal, close };
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=turn-deadline.js.map
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { assertAcceptable } from '../understanding/candidates.js';
|
|
3
|
+
/** Background interpretation is disposable; only authorized records enter LifeService. */
|
|
4
|
+
export class PersonalUnderstanding {
|
|
5
|
+
options;
|
|
6
|
+
#rows = [];
|
|
7
|
+
#status = 'idle';
|
|
8
|
+
#error = null;
|
|
9
|
+
#run;
|
|
10
|
+
#abort = new AbortController();
|
|
11
|
+
#key = '';
|
|
12
|
+
#seen = new Set();
|
|
13
|
+
#accepted = new Set();
|
|
14
|
+
#dismissed = new Set();
|
|
15
|
+
#recorded = [];
|
|
16
|
+
constructor(options) {
|
|
17
|
+
this.options = options;
|
|
18
|
+
}
|
|
19
|
+
#scope() { return this.options.scope?.() ?? this.options.source()?.id ?? null; }
|
|
20
|
+
#current(source) { return JSON.stringify(source) === JSON.stringify(this.options.source()); }
|
|
21
|
+
async #resolve(row, signal, guard) {
|
|
22
|
+
guard();
|
|
23
|
+
if (this.options.resolveCandidate) {
|
|
24
|
+
const result = await this.options.resolveCandidate(row, signal, guard);
|
|
25
|
+
guard();
|
|
26
|
+
if (result)
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
if (row.candidate.operation === 'update')
|
|
30
|
+
throw Error('candidate_resolution_unavailable');
|
|
31
|
+
const text = row.candidate.text;
|
|
32
|
+
if (row.candidate.kind === 'profile')
|
|
33
|
+
throw Error('candidate_kind_mismatch');
|
|
34
|
+
return { input: { op: 'create', kind: row.candidate.kind, title: text.slice(0, 200), note: text.length > 200 ? text : '', ...(row.candidate.patch?.due !== undefined ? { due: row.candidate.patch.due } : {}) } };
|
|
35
|
+
}
|
|
36
|
+
snapshot() { const source = this.options.source(); return { available: !!this.options.pipeline, status: this.#status, error: this.#error, recorded: this.#recorded.filter(r => r.scope === this.#scope()).map(r => ({ id: r.id, object_id: r.object_id, version: r.version, text: r.text })), items: this.#rows.filter(r => r.status === 'proposed' && r.decision.capture !== 'none' && !this.#accepted.has(r.candidate.id) && !this.#dismissed.has(r.candidate.id) && !!source && this.#current(r.source)).map(r => ({ id: r.candidate.id, kind: r.candidate.kind, text: r.candidate.text, quote: r.candidate.span.quote, source_id: r.source.id, importance: r.decision.importance })) }; }
|
|
37
|
+
/** Called after durable host commits. Selection/replay invalidates but never starts extraction. */
|
|
38
|
+
observe(newMessage = false) { const source = this.options.source(), key = JSON.stringify(source); if (key !== this.#key) {
|
|
39
|
+
this.#abort.abort();
|
|
40
|
+
this.#abort = new AbortController();
|
|
41
|
+
this.#key = key;
|
|
42
|
+
this.#rows = [];
|
|
43
|
+
this.#run = undefined;
|
|
44
|
+
this.#status = 'idle';
|
|
45
|
+
this.#error = null;
|
|
46
|
+
} if (newMessage && source && this.options.pipeline && !this.#seen.has(key))
|
|
47
|
+
this.start(true); }
|
|
48
|
+
start(automatic = false) {
|
|
49
|
+
if (!this.options.pipeline)
|
|
50
|
+
throw Error('understanding_unavailable');
|
|
51
|
+
this.observe();
|
|
52
|
+
if (this.#run)
|
|
53
|
+
return;
|
|
54
|
+
const source = this.options.source();
|
|
55
|
+
if (!source)
|
|
56
|
+
throw Error('no_user_message');
|
|
57
|
+
const controller = this.#abort, scope = this.#scope();
|
|
58
|
+
this.#seen.add(JSON.stringify(source));
|
|
59
|
+
for (const key of [...this.#seen].slice(0, -256))
|
|
60
|
+
this.#seen.delete(key);
|
|
61
|
+
this.#status = 'working';
|
|
62
|
+
this.#error = null;
|
|
63
|
+
this.options.changed();
|
|
64
|
+
const run = (async () => {
|
|
65
|
+
const signal = AbortSignal.any([controller.signal, AbortSignal.timeout(60000)]);
|
|
66
|
+
let onAbort = () => { };
|
|
67
|
+
try {
|
|
68
|
+
const rows = await Promise.race([this.options.pipeline(source, signal), new Promise((_, reject) => { onAbort = () => reject(signal.reason instanceof Error ? signal.reason : Error('understanding_aborted')); signal.addEventListener('abort', onAbort, { once: true }); if (signal.aborted)
|
|
69
|
+
onAbort(); })]);
|
|
70
|
+
if (signal.aborted || !this.#current(source))
|
|
71
|
+
return;
|
|
72
|
+
this.#rows = rows;
|
|
73
|
+
if (automatic)
|
|
74
|
+
for (const row of rows) {
|
|
75
|
+
if (row.status !== 'proposed' || (row.candidate.kind !== 'todo' && row.candidate.operation !== 'update') || row.decision.capture !== 'explicit')
|
|
76
|
+
continue;
|
|
77
|
+
const guard = () => { signal.throwIfAborted(); const current = this.options.source(); if (!current)
|
|
78
|
+
throw Error('candidate_stale_source'); assertAcceptable(row, current); };
|
|
79
|
+
guard();
|
|
80
|
+
const resolved = await this.#resolve(row, signal, guard);
|
|
81
|
+
guard();
|
|
82
|
+
if (resolved.input !== null) {
|
|
83
|
+
const result = await this.options.life.mutate(resolved.input, 'candidate:' + row.candidate.id, guard, { type: 'explicit_candidate', row, ...(resolved.resolution ? { resolution: resolved.resolution } : {}) });
|
|
84
|
+
if (resolved.input.op === 'create') {
|
|
85
|
+
this.#recorded.push({ id: row.candidate.id, object_id: result.id, version: result.version, text: row.candidate.text, scope });
|
|
86
|
+
this.#recorded = this.#recorded.slice(-20);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
this.#accepted.add(row.candidate.id);
|
|
90
|
+
}
|
|
91
|
+
if (!signal.aborted && this.#current(source))
|
|
92
|
+
this.#status = 'ready';
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
if (!controller.signal.aborted && this.#current(source)) {
|
|
96
|
+
this.#error = 'understanding_failed';
|
|
97
|
+
this.#status = 'failed';
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
signal.removeEventListener('abort', onAbort);
|
|
102
|
+
if (this.#abort === controller) {
|
|
103
|
+
this.#run = undefined;
|
|
104
|
+
this.options.changed();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
})();
|
|
108
|
+
this.#run = run;
|
|
109
|
+
}
|
|
110
|
+
async action(raw) {
|
|
111
|
+
const p = z.object({ id: z.string(), action: z.enum(['accept', 'dismiss', 'undo']), text: z.string().trim().min(1).max(1000).optional(), expected_profile_version: z.number().int().optional() }).strict().parse(raw);
|
|
112
|
+
if (p.action === 'undo') {
|
|
113
|
+
const record = this.#recorded.find(r => r.id === p.id && r.scope === this.#scope());
|
|
114
|
+
if (!record)
|
|
115
|
+
throw Error('record_not_found');
|
|
116
|
+
await this.options.life.mutate({ op: 'undo_create', id: record.object_id, expected_version: record.version }, 'undo-candidate:' + p.id);
|
|
117
|
+
this.#recorded = this.#recorded.filter(r => r !== record);
|
|
118
|
+
this.options.changed();
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const row = this.#rows.find(r => r.candidate.id === p.id);
|
|
122
|
+
if (!row)
|
|
123
|
+
throw Error('candidate_not_found');
|
|
124
|
+
const source = this.options.source();
|
|
125
|
+
if (!source)
|
|
126
|
+
throw Error('candidate_stale_source');
|
|
127
|
+
assertAcceptable(row, source);
|
|
128
|
+
if (p.action === 'dismiss') {
|
|
129
|
+
this.#dismissed.add(p.id);
|
|
130
|
+
this.options.changed();
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (this.#accepted.has(p.id))
|
|
134
|
+
return;
|
|
135
|
+
const text = p.text ?? row.candidate.text, kind = row.candidate.kind;
|
|
136
|
+
const signal = this.#abort.signal, guard = () => { signal.throwIfAborted(); const current = this.options.source(); if (!current)
|
|
137
|
+
throw Error('candidate_stale_source'); assertAcceptable(row, current); };
|
|
138
|
+
if (kind === 'profile') {
|
|
139
|
+
const profile = this.options.life.snapshot().profile;
|
|
140
|
+
if (p.expected_profile_version !== profile.version)
|
|
141
|
+
throw Error('version_conflict');
|
|
142
|
+
await this.options.life.mutate({ op: 'profile', expected_version: profile.version, about: [profile.about, text].filter(Boolean).join('\n') }, 'candidate:' + p.id, guard, { type: 'accepted_candidate', row });
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
const resolved = await this.#resolve(row, signal, guard);
|
|
146
|
+
guard();
|
|
147
|
+
if (resolved.input !== null) {
|
|
148
|
+
const input = resolved.input;
|
|
149
|
+
if (p.text && input.op === 'update' && text !== row.candidate.text)
|
|
150
|
+
throw Error('candidate_update_text_edit_unsupported');
|
|
151
|
+
await this.options.life.mutate(input.op === 'create' ? { ...input, title: text.slice(0, 200), note: text.length > 200 ? text : '' } : input, 'candidate:' + p.id, guard, { type: 'accepted_candidate', row, ...(resolved.resolution ? { resolution: resolved.resolution } : {}) });
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
this.#accepted.add(p.id);
|
|
155
|
+
this.options.changed();
|
|
156
|
+
}
|
|
157
|
+
async close() { this.#abort.abort(); await this.#run; }
|
|
158
|
+
reopen() { this.#abort = new AbortController(); this.#rows = []; this.#recorded = []; this.#status = 'idle'; this.#error = null; this.#key = ''; this.#seen.clear(); this.#accepted.clear(); this.#dismissed.clear(); }
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=understanding.js.map
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { BoundedJsonStore } from '../storage/bounded-json.js';
|
|
4
|
+
import { versionSchema } from './contracts.js';
|
|
5
|
+
import { digestEligible, selectContextCandidates } from './context-candidates.js';
|
|
6
|
+
const refSchema = z.object({ entry_id: z.string().min(1), version: versionSchema }).strict();
|
|
7
|
+
const line = (max) => z.string().trim().min(1).max(max).nullable().default(null);
|
|
8
|
+
/** A todo card says what, why now, and one concrete next step; a goal card names a state to reach, how to tell it is reached, and a first step; ideas leave why/next null. */
|
|
9
|
+
export const contextCardSchema = z.object({ candidate_id: z.string().min(1).max(128), tab: z.enum(['todos', 'ideas', 'goals']), title: z.string().trim().min(1).max(80), body: z.string().trim().min(1).max(120), why: line(80), next: line(80), refs: z.array(refSchema).min(1).max(8) }).strict();
|
|
10
|
+
export const recapSchema = z.object({ text: z.string().trim().min(1).max(160), refs: z.array(refSchema).min(1).max(8) }).strict();
|
|
11
|
+
export const contextCardsSchema = z.object({ recap: recapSchema.nullable().default(null), cards: z.array(contextCardSchema).max(9) }).strict();
|
|
12
|
+
const keyOf = (value) => createHash('sha256').update(JSON.stringify(value)).digest('hex');
|
|
13
|
+
const generationRevision = 'project-digest-v4';
|
|
14
|
+
const stateSchema = contextCardsSchema.extend({ recap_basis: z.array(z.string().max(128)).max(20).default([]), card_sources: z.record(z.string().max(128), z.object({ root: z.string().max(512), entries: z.array(z.string().max(512)).max(64) }).strict()).default({}), version: z.literal(2), key: z.string(), automatic_call_times: z.array(z.number().int().nonnegative()).max(6).default([]), retry_key: z.string().default(''), retry_not_before: z.number().int().nonnegative().default(0), dismissed: z.array(z.string()).max(1000), legacyDismissed: z.array(z.object({ tab: z.string(), refs: z.array(refSchema) }).strict()).max(1000) });
|
|
15
|
+
const diskSchema = z.preprocess(value => {
|
|
16
|
+
// An earlier local build recorded only cited refs under card_basis; that is not complete provenance, so it is dropped rather than trusted.
|
|
17
|
+
if (value && typeof value === 'object' && 'card_basis' in value) {
|
|
18
|
+
const rest = { ...value };
|
|
19
|
+
delete rest.card_basis;
|
|
20
|
+
value = rest;
|
|
21
|
+
}
|
|
22
|
+
if (!value || typeof value !== 'object' || 'version' in value)
|
|
23
|
+
return value;
|
|
24
|
+
const old = value;
|
|
25
|
+
const legacy = z.object({ cards: z.array(z.object({ tab: z.string(), title: z.string(), body: z.string(), refs: z.array(refSchema) }).passthrough()), dismissed: z.array(z.string()), key: z.string() }).safeParse(old);
|
|
26
|
+
if (!legacy.success)
|
|
27
|
+
return emptyState();
|
|
28
|
+
return { version: 2, recap: null, recap_basis: [], cards: [], key: '', dismissed: [], legacyDismissed: legacy.data.cards.filter(card => legacy.data.dismissed.includes(keyOf(card))).map(card => ({ tab: card.tab, refs: card.refs })) };
|
|
29
|
+
}, stateSchema);
|
|
30
|
+
const emptyState = () => ({ version: 2, recap: null, recap_basis: [], card_sources: {}, cards: [], key: '', automatic_call_times: [], retry_key: '', retry_not_before: 0, dismissed: [], legacyDismissed: [] });
|
|
31
|
+
const sameRef = (a, b) => a.entry_id === b.entry_id && a.version === b.version;
|
|
32
|
+
const leaksRawText = (text) => /(?:^|[^\w.])\/[\w.-]+\/[\w.-]|\b[A-Za-z]:[\\/]|\\\\[\w.$-]+\\|~[\\/]|\b(?:source|file):[\w-]+|\b(?:src|config|docs|runtime|clients)\/[\w./-]+|\b[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}\b|\b(?:api[_-]?key|access[_-]?token|secret|password)\s*[:=:]|\b[a-f\d]{40,}\b/iu.test(text);
|
|
33
|
+
const leaksRawField = (card) => leaksRawText([card.title, card.body, card.why ?? '', card.next ?? ''].join(' '));
|
|
34
|
+
/** Disposable, source-grounded suggestions. Saved Life records live elsewhere. */
|
|
35
|
+
export class WorkbenchContext {
|
|
36
|
+
generate;
|
|
37
|
+
changed;
|
|
38
|
+
#store;
|
|
39
|
+
#state = emptyState();
|
|
40
|
+
#inputs = [];
|
|
41
|
+
#candidates = [];
|
|
42
|
+
#abort = new AbortController();
|
|
43
|
+
#run;
|
|
44
|
+
#timer;
|
|
45
|
+
#status = 'idle';
|
|
46
|
+
#opened = false;
|
|
47
|
+
#tail = Promise.resolve();
|
|
48
|
+
#firstChangeAt = null;
|
|
49
|
+
#lastChangeAt = 0;
|
|
50
|
+
#pendingKey = '';
|
|
51
|
+
#manualPending = false;
|
|
52
|
+
#digests;
|
|
53
|
+
#digestsPending = 0;
|
|
54
|
+
constructor(path, generate, changed) {
|
|
55
|
+
this.generate = generate;
|
|
56
|
+
this.changed = changed;
|
|
57
|
+
this.#store = new BoundedJsonStore(path, diskSchema);
|
|
58
|
+
}
|
|
59
|
+
async open() { try {
|
|
60
|
+
this.#state = await this.#store.read(emptyState());
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (!(error instanceof z.ZodError))
|
|
64
|
+
throw error;
|
|
65
|
+
this.#state = emptyState();
|
|
66
|
+
} this.#opened = true; this.#abort = new AbortController(); this.#firstChangeAt = null; this.#pendingKey = ''; this.#manualPending = false; }
|
|
67
|
+
async close() { this.#opened = false; clearTimeout(this.#timer); this.#timer = undefined; this.#manualPending = false; this.#abort.abort(); await this.#run; await this.#tail; }
|
|
68
|
+
async clear() { const reopen = this.#opened; await this.close(); this.#inputs = []; this.#candidates = []; this.#digests = undefined; this.#digestsPending = 0; await this.#write(next => Object.assign(next, emptyState())); this.#abort = new AbortController(); this.#opened = reopen; this.#status = 'idle'; }
|
|
69
|
+
#candidate(card) { return this.#candidates.find(candidate => candidate.candidate_id === card.candidate_id && candidate.tab === card.tab && card.refs.every(ref => candidate.refs.some(allowed => sameRef(ref, allowed)))); }
|
|
70
|
+
/**
|
|
71
|
+
* A project card outlives a digest rewrite until the next generation replaces it: during a first scan digests are rewritten far more often than cards are regenerated.
|
|
72
|
+
* Every entry the card was derived from, cited or read uncited by its digest, must still be present, and for a project card still pass the digest rule, so withdrawn material never resurfaces; the card then cites the successor's current refs.
|
|
73
|
+
* Document cards keep an exact match.
|
|
74
|
+
*/
|
|
75
|
+
#shownRefs(card) {
|
|
76
|
+
const basis = this.#state.card_sources[card.candidate_id];
|
|
77
|
+
const project = basis?.root.startsWith('project:');
|
|
78
|
+
if (basis && !basis.entries.every(id => this.#inputs.some(input => input.id === id && (!project || digestEligible(input)))))
|
|
79
|
+
return null;
|
|
80
|
+
if (this.#candidate(card))
|
|
81
|
+
return card.refs;
|
|
82
|
+
if (!basis || !project)
|
|
83
|
+
return null;
|
|
84
|
+
return this.#candidates.find(candidate => candidate.root === basis.root && candidate.tab === card.tab)?.refs ?? null;
|
|
85
|
+
}
|
|
86
|
+
#recapGrounded(recap, candidates = this.#candidates) { return recap.refs.every(ref => candidates.some(c => c.tab === 'todos' && c.refs.some(allowed => sameRef(ref, allowed)))); }
|
|
87
|
+
/** Todo candidates a recap draws on; any of them changing or leaving retires the recap, even if its cited refs survive. */
|
|
88
|
+
#recapBasis(recap, candidates) { return candidates.filter(c => c.tab === 'todos' && c.refs.some(allowed => recap.refs.some(ref => sameRef(ref, allowed)))).map(c => c.candidate_id); }
|
|
89
|
+
#recapCurrent() { const basis = this.#state.recap_basis; return Boolean(this.#state.recap) && basis.length > 0 && basis.every(id => this.#candidates.some(c => c.tab === 'todos' && c.candidate_id === id)) && this.#recapGrounded(this.#state.recap); }
|
|
90
|
+
#emptyReason(tab, cards) { if (cards)
|
|
91
|
+
return null; if (!this.#candidates.some(c => c.tab === tab))
|
|
92
|
+
return tab !== 'ideas' && this.#digestsPending ? 'digests_pending' : 'no_eligible_sources'; return this.#status === 'ready' ? 'model_abstained' : this.#status === 'failed' ? 'generation_failed' : null; }
|
|
93
|
+
#key() { return keyOf([generationRevision, this.#candidates.map(candidate => [candidate.candidate_id, candidate.version])]); }
|
|
94
|
+
/** Active own projects, one line each, straight from their digests; no model call. */
|
|
95
|
+
#projects() { return (this.#digests ?? []).filter(d => d.role === 'own').slice(0, 4).map(d => ({ name: d.name, line: d.focus ?? d.summary })).filter(p => !leaksRawText(p.name + ' ' + p.line)); }
|
|
96
|
+
#sources(refs) {
|
|
97
|
+
const sources = refs.flatMap(ref => {
|
|
98
|
+
const input = this.#inputs.find(input => input.id === ref.entry_id && input.version === ref.version);
|
|
99
|
+
if (!input)
|
|
100
|
+
return [];
|
|
101
|
+
if (input.kind === 'memory')
|
|
102
|
+
return input.sources ?? [];
|
|
103
|
+
// Files are known from the host input type. Never invent a remote locator for local material.
|
|
104
|
+
return [{ evidence_id: input.id, type: 'file', label: input.rel_path.split(/[\\/]/u).at(-1), observed_at: new Date(input.mtime_ms).toISOString() }];
|
|
105
|
+
});
|
|
106
|
+
return structuredClone([...new Map(sources.map(source => [JSON.stringify(source), source])).values()]);
|
|
107
|
+
}
|
|
108
|
+
snapshot() {
|
|
109
|
+
const recap = this.#recapCurrent() ? this.#state.recap.text : null, cards = this.#state.cards.flatMap(card => { const refs = this.#shownRefs(card); return refs && !this.#state.dismissed.includes(card.candidate_id) ? [{ card, refs }] : []; }).map(({ card, refs }) => ({ ...structuredClone(card), id: card.candidate_id, sources: this.#sources(refs), refs: refs.map(ref => ({ ...ref, label: this.#inputs.find(input => input.id === ref.entry_id)?.content.slice(0, 700) ?? '来源内容不可用' })) }));
|
|
110
|
+
const empty_reasons = { todos: this.#emptyReason('todos', cards.filter(card => card.tab === 'todos').length), ideas: this.#emptyReason('ideas', cards.filter(card => card.tab === 'ideas').length), goals: this.#emptyReason('goals', cards.filter(card => card.tab === 'goals').length) };
|
|
111
|
+
return { status: this.#status, candidate_count: this.#candidates.length, recap: { text: recap, projects: this.#projects() }, empty_reason: this.#candidates.length === 0 ? this.#digestsPending ? 'digests_pending' : 'no_eligible_sources' : cards.length === 0 && this.#status === 'ready' ? 'model_abstained' : cards.length === 0 && this.#status === 'failed' ? 'generation_failed' : null, empty_reasons, cards };
|
|
112
|
+
}
|
|
113
|
+
#write(fn) { const run = this.#tail.then(async () => { const next = structuredClone(this.#state); fn(next); await this.#store.write(next); this.#state = next; this.changed(); }); this.#tail = run.catch(() => undefined); return run; }
|
|
114
|
+
dismiss(id) { if (!this.#state.cards.some(card => card.candidate_id === id))
|
|
115
|
+
throw Error('card_not_found'); return this.#write(next => { next.dismissed = [...new Set([...next.dismissed, id])].slice(-1000); }); }
|
|
116
|
+
update(entries, digests) {
|
|
117
|
+
this.#digests = digests?.items;
|
|
118
|
+
this.#digestsPending = digests?.pending ?? 0;
|
|
119
|
+
this.#inputs = entries.flatMap(entry => {
|
|
120
|
+
if ('kind' in entry && entry.kind === 'file')
|
|
121
|
+
return [entry];
|
|
122
|
+
if ('kind' in entry && entry.kind === 'memory')
|
|
123
|
+
return entry.version === null ? [] : [entry];
|
|
124
|
+
if ('origin' in entry && entry.version !== null)
|
|
125
|
+
return [{ kind: 'memory', id: entry.id, version: entry.version, content: entry.content, origin: entry.origin ?? 'inferred', sources: entry.sources }];
|
|
126
|
+
return [];
|
|
127
|
+
}).filter(entry => entry.content.trim());
|
|
128
|
+
this.#candidates = selectContextCandidates(this.#inputs, this.#digests);
|
|
129
|
+
if (this.#state.legacyDismissed.length) {
|
|
130
|
+
const mapped = [], unmatched = [];
|
|
131
|
+
for (const old of this.#state.legacyDismissed) {
|
|
132
|
+
const matches = this.#candidates.filter(candidate => candidate.tab === old.tab && old.refs.length === candidate.refs.length && old.refs.every(ref => candidate.refs.some(allowed => sameRef(ref, allowed))));
|
|
133
|
+
if (matches.length === 1)
|
|
134
|
+
mapped.push(matches[0].candidate_id);
|
|
135
|
+
else
|
|
136
|
+
unmatched.push(old);
|
|
137
|
+
}
|
|
138
|
+
if (mapped.length)
|
|
139
|
+
void this.#write(next => { next.dismissed = [...new Set([...next.dismissed, ...mapped])].slice(-1000); next.legacyDismissed = unmatched; }).catch(() => undefined);
|
|
140
|
+
}
|
|
141
|
+
this.changed();
|
|
142
|
+
if (!this.#opened || !this.generate)
|
|
143
|
+
return;
|
|
144
|
+
const key = this.#key();
|
|
145
|
+
if (!this.#candidates.length || key === this.#state.key) {
|
|
146
|
+
clearTimeout(this.#timer);
|
|
147
|
+
this.#timer = undefined;
|
|
148
|
+
this.#firstChangeAt = null;
|
|
149
|
+
this.#pendingKey = '';
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (key !== this.#pendingKey) {
|
|
153
|
+
const now = Date.now();
|
|
154
|
+
if (this.#firstChangeAt === null)
|
|
155
|
+
this.#firstChangeAt = now;
|
|
156
|
+
this.#lastChangeAt = now;
|
|
157
|
+
this.#pendingKey = key;
|
|
158
|
+
}
|
|
159
|
+
this.#schedule();
|
|
160
|
+
}
|
|
161
|
+
#schedule() {
|
|
162
|
+
clearTimeout(this.#timer);
|
|
163
|
+
this.#timer = undefined;
|
|
164
|
+
if (!this.#opened || !this.generate || this.#run || !this.#candidates.length || this.#key() === this.#state.key || this.#firstChangeAt === null)
|
|
165
|
+
return;
|
|
166
|
+
const now = Date.now(), recent = this.#state.automatic_call_times.filter(at => at > now - 3_600_000), first = this.#state.automatic_call_times.length === 0 && this.#state.key === '';
|
|
167
|
+
const due = Math.min(this.#firstChangeAt + (first ? 10_000 : 120_000), this.#lastChangeAt + (first ? 3_000 : 30_000));
|
|
168
|
+
const eligible = Math.max(due, (recent.at(-1) ?? -Infinity) + 120_000, recent.length >= 6 ? recent[0] + 3_600_000 : -Infinity, this.#state.retry_key === this.#key() ? this.#state.retry_not_before : 0);
|
|
169
|
+
this.#timer = setTimeout(() => { this.#timer = undefined; if (this.#key() !== this.#state.key)
|
|
170
|
+
void this.#generate(true); }, Math.max(0, eligible - now));
|
|
171
|
+
this.#timer.unref();
|
|
172
|
+
}
|
|
173
|
+
async refresh() { if (this.#run) {
|
|
174
|
+
this.#manualPending = true;
|
|
175
|
+
return this.#run;
|
|
176
|
+
} await this.#generate(false); }
|
|
177
|
+
async #generate(automatic) {
|
|
178
|
+
if (!this.#opened || !this.generate || this.#run || !this.#candidates.length)
|
|
179
|
+
return;
|
|
180
|
+
clearTimeout(this.#timer);
|
|
181
|
+
this.#timer = undefined;
|
|
182
|
+
const candidates = structuredClone(this.#candidates), key = this.#key();
|
|
183
|
+
if (key === this.#state.key) {
|
|
184
|
+
this.#status = 'ready';
|
|
185
|
+
this.changed();
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
this.#firstChangeAt = null;
|
|
189
|
+
this.#pendingKey = '';
|
|
190
|
+
this.#status = 'working';
|
|
191
|
+
this.changed();
|
|
192
|
+
const signal = AbortSignal.any([this.#abort.signal, AbortSignal.timeout(120000)]);
|
|
193
|
+
let failedAt = 0;
|
|
194
|
+
const run = (async () => {
|
|
195
|
+
try {
|
|
196
|
+
if (automatic)
|
|
197
|
+
await this.#write(next => { next.automatic_call_times = [...next.automatic_call_times.filter(at => at > Date.now() - 3_600_000), Date.now()].slice(-6); });
|
|
198
|
+
const result = contextCardsSchema.parse(await this.generate(candidates, signal));
|
|
199
|
+
signal.throwIfAborted();
|
|
200
|
+
const seen = new Set();
|
|
201
|
+
const cards = result.cards.filter(card => { if (seen.has(card.candidate_id) || leaksRawField(card) || !this.#candidate(card) || !card.refs.every(ref => candidates.some(candidate => candidate.candidate_id === card.candidate_id && candidate.refs.some(allowed => sameRef(ref, allowed)))))
|
|
202
|
+
return false; seen.add(card.candidate_id); return true; });
|
|
203
|
+
const basis = result.recap ? this.#recapBasis(result.recap, candidates) : [];
|
|
204
|
+
const recap = result.recap && basis.length && !leaksRawText(result.recap.text) && this.#recapGrounded(result.recap, candidates) ? result.recap : null;
|
|
205
|
+
const cardBasis = Object.fromEntries(cards.map(card => { const candidate = candidates.find(c => c.candidate_id === card.candidate_id); return [card.candidate_id, { root: candidate.root, entries: [...(candidate.sources ?? new Set(candidate.refs.map(ref => ref.entry_id)))] }]; }));
|
|
206
|
+
await this.#write(next => { next.recap = recap; next.recap_basis = recap ? basis : []; next.card_sources = cardBasis; next.cards = cards; next.key = key; next.retry_key = ''; next.retry_not_before = 0; });
|
|
207
|
+
this.#status = 'ready';
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
failedAt = Date.now();
|
|
211
|
+
if (this.#opened && !signal.aborted)
|
|
212
|
+
await this.#write(next => { next.retry_key = key; next.retry_not_before = failedAt + 300000; }).catch(() => undefined);
|
|
213
|
+
this.#status = 'failed';
|
|
214
|
+
console.error('[workbench-context] generation_failed', error instanceof z.ZodError ? JSON.stringify(error.issues.map(i => ({ code: i.code, path: i.path }))) : error instanceof Error ? error.name : 'unknown');
|
|
215
|
+
}
|
|
216
|
+
finally {
|
|
217
|
+
this.#run = undefined;
|
|
218
|
+
this.changed();
|
|
219
|
+
if (this.#opened) {
|
|
220
|
+
if (this.#manualPending) {
|
|
221
|
+
this.#manualPending = false;
|
|
222
|
+
void this.refresh();
|
|
223
|
+
}
|
|
224
|
+
else if (key !== this.#key())
|
|
225
|
+
this.update(this.#inputs, this.#digests && { items: this.#digests, pending: this.#digestsPending });
|
|
226
|
+
else if (this.#status === 'failed') {
|
|
227
|
+
this.#firstChangeAt = failedAt;
|
|
228
|
+
this.#lastChangeAt = failedAt;
|
|
229
|
+
this.#pendingKey = key;
|
|
230
|
+
this.#schedule();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
})();
|
|
235
|
+
this.#run = run;
|
|
236
|
+
await run;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
//# sourceMappingURL=workbench-context.js.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const CAPABILITIES = new WeakMap();
|
|
2
|
+
/** Register the exact frozen operation object after the controller accepts a decision before its TTL. */
|
|
3
|
+
export function issueConfirmedProjectCapability(capability, input) {
|
|
4
|
+
CAPABILITIES.set(capability, {
|
|
5
|
+
proposal_id: input.proposalId,
|
|
6
|
+
origin_ref: input.originRef,
|
|
7
|
+
phase: 'ready',
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Lock one exact capability for the one private confirmed-project admission shape.
|
|
12
|
+
*
|
|
13
|
+
* The proposal TTL gates capability issuance, not completion of an in-flight commit. Provider
|
|
14
|
+
* replacement, service close, terminal rejection and replay still revoke the identity explicitly.
|
|
15
|
+
*/
|
|
16
|
+
export function beginConfirmedProjectAdmission(capability, request, codingExecutor) {
|
|
17
|
+
const state = CAPABILITIES.get(capability);
|
|
18
|
+
if (state?.phase !== 'ready'
|
|
19
|
+
|| codingExecutor === null
|
|
20
|
+
|| request.executor !== codingExecutor
|
|
21
|
+
|| request.op !== 'run'
|
|
22
|
+
|| request.origin_ref !== state.origin_ref
|
|
23
|
+
|| Object.keys(request.request).length !== 1
|
|
24
|
+
|| typeof request.request.work_order !== 'string')
|
|
25
|
+
return false;
|
|
26
|
+
state.phase = 'admitting';
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
/** Admission rejection restores the capability; success consumes it before worker dispatch. */
|
|
30
|
+
export function finishConfirmedProjectAdmission(capability, accepted) {
|
|
31
|
+
const state = CAPABILITIES.get(capability);
|
|
32
|
+
if (state?.phase !== 'admitting')
|
|
33
|
+
return false;
|
|
34
|
+
state.phase = accepted ? 'admitted' : 'ready';
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
export function confirmedProjectCapabilityWasAdmitted(capability) {
|
|
38
|
+
return CAPABILITIES.get(capability)?.phase === 'admitted';
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Record the result returned by the host's narrow runtime-dispatch port.
|
|
42
|
+
*
|
|
43
|
+
* The real CausalRuntime has already moved the capability to admitted. This idempotent fallback lets
|
|
44
|
+
* isolated adapter tests provide the same trusted port without constructing a serving runtime.
|
|
45
|
+
*/
|
|
46
|
+
export function recordConfirmedProjectAdmission(capability) {
|
|
47
|
+
const state = CAPABILITIES.get(capability);
|
|
48
|
+
if (state?.phase === 'admitted')
|
|
49
|
+
return true;
|
|
50
|
+
if (state?.phase !== 'ready')
|
|
51
|
+
return false;
|
|
52
|
+
state.phase = 'admitted';
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
export function revokeConfirmedProjectCapability(capability) {
|
|
56
|
+
const state = CAPABILITIES.get(capability);
|
|
57
|
+
if (state !== undefined)
|
|
58
|
+
state.phase = 'revoked';
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=confirmed-project-capability.js.map
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-minted path capabilities.
|
|
3
|
+
*
|
|
4
|
+
* A `HostWorkspace` or `HostStateHome` can only be created here, from a canonical absolute native
|
|
5
|
+
* path that exists and passed the caller's allowlist. Executors receive the brand, never the raw
|
|
6
|
+
* string, so a workspace or per-workspace state home that reaches a child process is one the host
|
|
7
|
+
* validated. The values live in WeakMaps keyed by the frozen brand object; a forged object has no
|
|
8
|
+
* entry and every accessor throws.
|
|
9
|
+
*/
|
|
10
|
+
import { lstatSync, realpathSync, statSync } from 'node:fs';
|
|
11
|
+
import { isAbsolute } from 'node:path';
|
|
12
|
+
import { isWellFormed } from '../text/python-text.js';
|
|
13
|
+
const hostWorkspaceBrand = Symbol('HostWorkspace');
|
|
14
|
+
const hostStateHomeBrand = Symbol('HostStateHome');
|
|
15
|
+
const workspaceValues = new WeakMap();
|
|
16
|
+
const homeValues = new WeakMap();
|
|
17
|
+
export class HostPathError extends Error {
|
|
18
|
+
code;
|
|
19
|
+
constructor(code) {
|
|
20
|
+
super(code);
|
|
21
|
+
this.name = 'HostPathError';
|
|
22
|
+
this.code = code;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export function hostWorkspaceFromConfig(configured, allowlistedCanonicalWorkspaces) {
|
|
26
|
+
const canonical = requireCanonicalDirectory(configured, 'workspace_invalid');
|
|
27
|
+
if (!allowlistedCanonicalWorkspaces.some(candidate => safeCanonicalPath(candidate) === canonical)) {
|
|
28
|
+
throw new HostPathError('workspace_invalid');
|
|
29
|
+
}
|
|
30
|
+
return brandWorkspace(canonical);
|
|
31
|
+
}
|
|
32
|
+
export function hostEphemeralHomeFromConfig(configured, allowlistedCanonicalHomes) {
|
|
33
|
+
const canonical = requireCanonicalDirectory(configured, 'workspace_invalid');
|
|
34
|
+
if (!allowlistedCanonicalHomes.some(candidate => safeCanonicalPath(candidate) === canonical)) {
|
|
35
|
+
throw new HostPathError('workspace_invalid');
|
|
36
|
+
}
|
|
37
|
+
return brandHome(canonical, true);
|
|
38
|
+
}
|
|
39
|
+
export function hostPersistentHomeFromConfig(configured, allowlistedCanonicalHomes) {
|
|
40
|
+
const canonical = requireCanonicalDirectory(configured, 'workspace_invalid');
|
|
41
|
+
if (!allowlistedCanonicalHomes.some(candidate => safeCanonicalPath(candidate) === canonical)) {
|
|
42
|
+
throw new HostPathError('workspace_invalid');
|
|
43
|
+
}
|
|
44
|
+
return brandHome(canonical, false);
|
|
45
|
+
}
|
|
46
|
+
/** Test-only constructors. They still enforce canonical absolute native paths. */
|
|
47
|
+
export function hostWorkspaceForTest(configured) {
|
|
48
|
+
return brandWorkspace(requireCanonicalDirectory(configured, 'workspace_invalid'));
|
|
49
|
+
}
|
|
50
|
+
export function hostHomeForTest(configured, options) {
|
|
51
|
+
return brandHome(requireCanonicalDirectory(configured, 'workspace_invalid'), options.ephemeral);
|
|
52
|
+
}
|
|
53
|
+
export function hostWorkspacePath(value) {
|
|
54
|
+
const path = workspaceValues.get(value);
|
|
55
|
+
if (path === undefined)
|
|
56
|
+
throw new HostPathError('workspace_invalid');
|
|
57
|
+
return path;
|
|
58
|
+
}
|
|
59
|
+
export function hostHomeValue(value) {
|
|
60
|
+
const home = homeValues.get(value);
|
|
61
|
+
if (home === undefined)
|
|
62
|
+
throw new HostPathError('workspace_invalid');
|
|
63
|
+
return home;
|
|
64
|
+
}
|
|
65
|
+
/** Internal credential-cleanup capability refresh after creating an approved ephemeral home. */
|
|
66
|
+
export function refreshEphemeralHomeIdentity(value) {
|
|
67
|
+
const home = homeValues.get(value);
|
|
68
|
+
if (!home?.ephemeral)
|
|
69
|
+
throw new HostPathError('workspace_invalid');
|
|
70
|
+
home.identity = readEphemeralHomeIdentity(home.path);
|
|
71
|
+
home.cleanupPath = null;
|
|
72
|
+
}
|
|
73
|
+
export function requireCanonicalDirectory(configured, code) {
|
|
74
|
+
const canonical = requireCanonicalPath(configured, code);
|
|
75
|
+
try {
|
|
76
|
+
if (!statSync(canonical).isDirectory())
|
|
77
|
+
throw new Error('not directory');
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
throw new HostPathError(code);
|
|
81
|
+
}
|
|
82
|
+
return canonical;
|
|
83
|
+
}
|
|
84
|
+
export function requireCanonicalPath(configured, code) {
|
|
85
|
+
if (typeof configured !== 'string' || !isWellFormed(configured) || !isAbsolute(configured)) {
|
|
86
|
+
throw new HostPathError(code);
|
|
87
|
+
}
|
|
88
|
+
let canonical;
|
|
89
|
+
try {
|
|
90
|
+
canonical = realpathSync(configured);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
throw new HostPathError(code);
|
|
94
|
+
}
|
|
95
|
+
if (canonical !== configured)
|
|
96
|
+
throw new HostPathError(code);
|
|
97
|
+
return canonical;
|
|
98
|
+
}
|
|
99
|
+
export function safeCanonicalPath(candidate) {
|
|
100
|
+
try {
|
|
101
|
+
return requireCanonicalPath(candidate, 'workspace_invalid');
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function brandWorkspace(path) {
|
|
108
|
+
const value = Object.freeze({ [hostWorkspaceBrand]: true });
|
|
109
|
+
workspaceValues.set(value, path);
|
|
110
|
+
return value;
|
|
111
|
+
}
|
|
112
|
+
function brandHome(path, ephemeral) {
|
|
113
|
+
const value = Object.freeze({ [hostStateHomeBrand]: true });
|
|
114
|
+
homeValues.set(value, {
|
|
115
|
+
path,
|
|
116
|
+
ephemeral,
|
|
117
|
+
identity: ephemeral ? readEphemeralHomeIdentity(path) : null,
|
|
118
|
+
cleanupPath: null,
|
|
119
|
+
});
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
function readEphemeralHomeIdentity(path) {
|
|
123
|
+
try {
|
|
124
|
+
const info = lstatSync(path, { bigint: true });
|
|
125
|
+
if (info.isSymbolicLink() || !info.isDirectory())
|
|
126
|
+
throw new Error('invalid home');
|
|
127
|
+
return Object.freeze({ device: info.dev, inode: info.ino, uid: Number(info.uid) });
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
throw new HostPathError('workspace_invalid');
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=host-paths.js.map
|