@ouro.bot/cli 0.1.0-alpha.151 → 0.1.0-alpha.1510
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +158 -42
- package/RepairGuide.ouro/agent.json +5 -0
- package/RepairGuide.ouro/psyche/IDENTITY.md +19 -0
- package/RepairGuide.ouro/psyche/SOUL.md +55 -0
- package/RepairGuide.ouro/skills/diagnose-broken-remote.md +63 -0
- package/RepairGuide.ouro/skills/diagnose-stacked-typed-issues.md +35 -0
- package/RepairGuide.ouro/skills/diagnose-sync-blocked.md +54 -0
- package/RepairGuide.ouro/skills/diagnose-vault-expired.md +60 -0
- package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/agent.json +4 -2
- package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/SOUL.md +2 -2
- package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-serpent.md +1 -1
- package/assets/bluebubbles-host +264 -0
- package/assets/sanctuary-host-launcher.sh +16 -0
- package/changelog.json +8843 -41
- package/deploy/unraid/Dockerfile +85 -0
- package/deploy/unraid/INSTALL.md +64 -0
- package/deploy/unraid/README.txt +3034 -0
- package/deploy/unraid/audit-container-spec.sh +4 -0
- package/deploy/unraid/container-runtime.json +1 -0
- package/deploy/unraid/credit-gateway.md +95 -0
- package/deploy/unraid/docker-man-template-transaction.mjs +733 -0
- package/deploy/unraid/docker-man-template-xml.cjs +105 -0
- package/deploy/unraid/github_known_hosts +3 -0
- package/deploy/unraid/install.sh +274 -0
- package/deploy/unraid/migrate-sanctuary-bundle.mjs +63 -0
- package/deploy/unraid/ouro-events/bootstrap-spool.sh +92 -0
- package/deploy/unraid/ouro-events/emit-event.mjs +310 -0
- package/deploy/unraid/ouro-events/emit-usenet-event.sh +54 -0
- package/deploy/unraid/ouro-events/install-usenet-guard.sh +435 -0
- package/deploy/unraid/ouro-events/usenet-health.sh +176 -0
- package/deploy/unraid/ouro-host-lock.mjs +207 -0
- package/deploy/unraid/ouro-sync-ssh +98 -0
- package/deploy/unraid/ouro-sync.sudoers +3 -0
- package/deploy/unraid/sanctuary-acceptance-adapter.sh +43 -0
- package/deploy/unraid/sanctuary-acceptance-contract.json +198 -0
- package/deploy/unraid/sanctuary-acceptance-harness.sh +23 -0
- package/deploy/unraid/sanctuary-authority-installation.json +36 -0
- package/deploy/unraid/sanctuary-authority-service.sh +30 -0
- package/deploy/unraid/sanctuary-butler-upgrade.mjs +1604 -0
- package/deploy/unraid/sanctuary-deployment-target.mjs +710 -0
- package/deploy/unraid/sanctuary-replay-gate.mjs +2781 -0
- package/deploy/unraid/sanctuary-safe-rename.py +24 -0
- package/deploy/unraid/sanctuary-sync-cutover.sh +1039 -0
- package/deploy/unraid/sanctuary-unit16-host-broker.mjs +2088 -0
- package/deploy/unraid/sanctuary-unit16-run.sh +570 -0
- package/deploy/unraid/sanctuary-unit18-target-audit.sh +27 -0
- package/deploy/unraid/sanctuary.ouro/agent.json +73 -0
- package/deploy/unraid/sanctuary.ouro/arc/README.md +3 -0
- package/deploy/unraid/sanctuary.ouro/awaiting/house-care-sweep.md +17 -0
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +5 -0
- package/deploy/unraid/sanctuary.ouro/habits/sanctuary-health.md +8 -0
- package/deploy/unraid/sanctuary.ouro/mcp/media-mcp.mjs +2533 -0
- package/deploy/unraid/sanctuary.ouro/product/PRODUCT.md +13 -0
- package/deploy/unraid/sanctuary.ouro/provider-readiness.json +11 -0
- package/deploy/unraid/sanctuary.ouro/psyche/ASPIRATIONS.md +5 -0
- package/deploy/unraid/sanctuary.ouro/psyche/IDENTITY.md +7 -0
- package/deploy/unraid/sanctuary.ouro/psyche/LORE.md +7 -0
- package/deploy/unraid/sanctuary.ouro/psyche/SOUL.md +15 -0
- package/deploy/unraid/sanctuary.ouro/psyche/TACIT.md +3 -0
- package/deploy/unraid/sanctuary.ouro/state/policy/steward.json +7 -0
- package/deploy/unraid/sanctuary.ouro/tool-profiles.json +274 -0
- package/deploy/unraid/sanctuary.xml +30 -0
- package/desk.lock.json +8 -0
- package/dist/a2a/approval-relay-forward.js +117 -0
- package/dist/a2a/approval-relay.js +95 -0
- package/dist/a2a/approval-request-wire.js +123 -0
- package/dist/a2a/card.js +57 -0
- package/dist/a2a/client.js +331 -0
- package/dist/a2a/config.js +50 -0
- package/dist/a2a/delegated-command-grants.js +93 -0
- package/dist/a2a/delegated-command.js +200 -0
- package/dist/a2a/delegation-stores.js +56 -0
- package/dist/a2a/did-resolution.js +205 -0
- package/dist/a2a/escalation-grants.js +84 -0
- package/dist/a2a/escalation-wiring.js +60 -0
- package/dist/a2a/identity.js +258 -0
- package/dist/a2a/inbound-share.js +131 -0
- package/dist/a2a/mission-result-wire.js +265 -0
- package/dist/a2a/onboarding.js +133 -0
- package/dist/a2a/operator-trust.js +399 -0
- package/dist/a2a/outbox-client.js +59 -0
- package/dist/a2a/outbox-store.js +245 -0
- package/dist/a2a/outbox-wire.js +106 -0
- package/dist/a2a/pin-store.js +167 -0
- package/dist/a2a/refusals.js +55 -0
- package/dist/a2a/relay-client.js +106 -0
- package/dist/a2a/relay-config-vault.js +64 -0
- package/dist/a2a/relay-contacts.js +120 -0
- package/dist/a2a/relay-inbox.js +360 -0
- package/dist/a2a/relay-retirements.js +89 -0
- package/dist/a2a/replay-grant-holders.js +33 -0
- package/dist/a2a/replay-harness.js +188 -0
- package/dist/a2a/resolution-proof.js +53 -0
- package/dist/a2a/sealed-chat.js +142 -0
- package/dist/a2a/seen-ledger.js +216 -0
- package/dist/a2a/server.js +1088 -0
- package/dist/a2a/task-store.js +69 -0
- package/dist/a2a/transport.js +100 -0
- package/dist/a2a/trust-commands.js +203 -0
- package/dist/a2a/trusted-files.js +185 -0
- package/dist/a2a/types.js +3 -0
- package/dist/actions/generated/mailbox/actions.json +41 -0
- package/dist/actions/generated/mailbox/commands.json +15 -0
- package/dist/actions/generated/mailbox/mcp.json +46 -0
- package/dist/actions/generated/mailbox-tools/tools.json +35 -0
- package/dist/arc/attention-types.js +8 -0
- package/dist/arc/cares.js +360 -0
- package/dist/arc/episodes.js +118 -0
- package/dist/arc/evolution.js +490 -0
- package/dist/arc/flight-recorder.js +1030 -0
- package/dist/arc/intentions.js +134 -0
- package/dist/arc/json-store.js +117 -0
- package/dist/arc/obligations.js +386 -0
- package/dist/arc/packets.js +336 -0
- package/dist/arc/presence.js +185 -0
- package/dist/arc/task-lifecycle.js +57 -0
- package/dist/commerce/store.js +755 -0
- package/dist/commerce/types.js +3 -0
- package/dist/eval/assertions/index.js +378 -0
- package/dist/eval/budget.js +135 -0
- package/dist/eval/domain/case.js +115 -0
- package/dist/eval/domain/stats.js +19 -0
- package/dist/eval/guest-entry.js +18 -0
- package/dist/eval/h-guest-entry.js +19 -0
- package/dist/eval/interview-entry.js +172 -0
- package/dist/eval/interview-grade-entry.js +36 -0
- package/dist/eval/interview-guest-entry.js +19 -0
- package/dist/eval/interviews/allocation.js +90 -0
- package/dist/eval/interviews/final.js +133 -0
- package/dist/eval/interviews/grader.js +209 -0
- package/dist/eval/interviews/guest/arms.js +173 -0
- package/dist/eval/interviews/guest/ax/ax-command.js +792 -0
- package/dist/eval/interviews/guest/ax/effects.js +51 -0
- package/dist/eval/interviews/guest/ax/exit-codes.js +51 -0
- package/dist/eval/interviews/guest/ax/help.js +181 -0
- package/dist/eval/interviews/guest/ax/mcp.js +246 -0
- package/dist/eval/interviews/guest/ax/outcome.js +211 -0
- package/dist/eval/interviews/guest/ax/output.js +53 -0
- package/dist/eval/interviews/guest/ax/precise-copy.js +200 -0
- package/dist/eval/interviews/guest/ax/problem.js +95 -0
- package/dist/eval/interviews/guest/ax/voice.js +83 -0
- package/dist/eval/interviews/guest/ax/wait.js +158 -0
- package/dist/eval/interviews/guest/books-core.js +54 -0
- package/dist/eval/interviews/guest/cli-shell.js +267 -0
- package/dist/eval/interviews/guest/h/codex.js +201 -0
- package/dist/eval/interviews/guest/h/fidelity.js +59 -0
- package/dist/eval/interviews/guest/h/openhands.js +176 -0
- package/dist/eval/interviews/guest/h/run.js +99 -0
- package/dist/eval/interviews/guest/h/wire.js +403 -0
- package/dist/eval/interviews/guest/loop.js +87 -0
- package/dist/eval/interviews/guest/operations.js +108 -0
- package/dist/eval/interviews/guest/run.js +81 -0
- package/dist/eval/interviews/guest/u/arms.js +266 -0
- package/dist/eval/interviews/h/kit.js +119 -0
- package/dist/eval/interviews/latch.js +143 -0
- package/dist/eval/interviews/protocol.js +120 -0
- package/dist/eval/interviews/rewrite.js +57 -0
- package/dist/eval/interviews/runner.js +347 -0
- package/dist/eval/interviews/u/kit.js +83 -0
- package/dist/eval/readback/hedges.js +39 -0
- package/dist/eval/remote-entry.js +32 -0
- package/dist/eval/report.js +85 -0
- package/dist/eval/run-command.js +161 -0
- package/dist/eval/run-entry.js +89 -0
- package/dist/eval/sandbox/agent-profile.js +74 -0
- package/dist/eval/sandbox/declared-gaps.js +17 -0
- package/dist/eval/sandbox/docker.js +353 -0
- package/dist/eval/sandbox/guest.js +55 -0
- package/dist/eval/sandbox/host-lock.js +62 -0
- package/dist/eval/sandbox/images.js +39 -0
- package/dist/eval/sandbox/oracle.js +32 -0
- package/dist/eval/sandbox/projection.js +127 -0
- package/dist/eval/sandbox/readback.js +137 -0
- package/dist/eval/sandbox/remote.js +102 -0
- package/dist/eval/sandbox/slugger-projection.js +377 -0
- package/dist/eval/self-test.js +84 -0
- package/dist/eval/targets/index.js +127 -0
- package/dist/eval/transport/provider-proxy.js +262 -0
- package/dist/eval/transport/synthetic-sanctuary.js +111 -0
- package/dist/eval/transport/telegram-turn.js +241 -0
- package/dist/eval/watch/cli.js +55 -0
- package/dist/eval/watch/guarded-fs.js +254 -0
- package/dist/eval/watch/log-reader.js +99 -0
- package/dist/eval/watch/rows.js +143 -0
- package/dist/eval/watch/run-watch.js +160 -0
- package/dist/eval/watch-entry.js +26 -0
- package/dist/gateway/keys.js +117 -0
- package/dist/gateway/server.js +429 -0
- package/dist/heart/active-work.js +421 -45
- package/dist/heart/agent-entry.js +255 -4
- package/dist/heart/approval-files.js +94 -0
- package/dist/heart/approval-store.js +1000 -0
- package/dist/heart/atomic-file.js +115 -0
- package/dist/heart/attachments/downloaded-store.js +89 -0
- package/dist/heart/attachments/image-normalize.js +201 -0
- package/dist/heart/attachments/materialize.js +97 -0
- package/dist/heart/attachments/originals.js +102 -0
- package/dist/heart/attachments/render.js +29 -0
- package/dist/heart/attachments/sources/bluebubbles.js +155 -0
- package/dist/heart/attachments/sources/cli-local-file.js +78 -0
- package/dist/heart/attachments/sources/downloaded.js +76 -0
- package/dist/heart/attachments/sources/index.js +19 -0
- package/dist/heart/attachments/store.js +132 -0
- package/dist/heart/attachments/transcribe-audio.js +231 -0
- package/dist/heart/attachments/types.js +93 -0
- package/dist/heart/attachments/understand.js +195 -0
- package/dist/heart/auth/auth-flow.js +590 -0
- package/dist/heart/auth/github-device-login.js +104 -0
- package/dist/heart/autonomy-budget.js +478 -0
- package/dist/heart/awaiting/a2a-await-delivery.js +109 -0
- package/dist/heart/awaiting/await-alert.js +152 -0
- package/dist/heart/awaiting/await-expiry.js +143 -0
- package/dist/heart/awaiting/await-loader.js +91 -0
- package/dist/heart/awaiting/await-parser.js +152 -0
- package/dist/heart/awaiting/await-runtime-state.js +130 -0
- package/dist/heart/awaiting/await-scheduler.js +462 -0
- package/dist/heart/background-operations.js +281 -0
- package/dist/heart/bluebubbles-host-account.js +78 -0
- package/dist/heart/bridges/manager.js +137 -17
- package/dist/heart/bridges/store.js +14 -2
- package/dist/heart/bundle-state.js +168 -0
- package/dist/heart/chat-interaction.js +69 -0
- package/dist/heart/commitments.js +44 -14
- package/dist/heart/config-registry.js +340 -0
- package/dist/heart/config.js +191 -140
- package/dist/heart/context-loss-gauntlet.js +387 -0
- package/dist/heart/context-loss-sentinel.js +1200 -0
- package/dist/heart/core.js +2781 -697
- package/dist/heart/cross-chat-delivery.js +29 -22
- package/dist/heart/daemon/agent-config-check.js +494 -0
- package/dist/heart/daemon/agent-discovery.js +304 -3
- package/dist/heart/daemon/agent-home.js +409 -0
- package/dist/heart/daemon/agent-service.js +210 -28
- package/dist/heart/daemon/agentic-repair.js +548 -0
- package/dist/heart/daemon/await-private-wake.js +59 -0
- package/dist/heart/daemon/bluebubbles-cli-integration.js +71 -0
- package/dist/heart/daemon/bluebubbles-health-diagnostics.js +122 -0
- package/dist/heart/daemon/bluebubbles-host-protocol.js +433 -0
- package/dist/heart/daemon/bluebubbles-host.js +273 -0
- package/dist/heart/daemon/boot-sync-probe.js +223 -0
- package/dist/heart/daemon/cadence.js +110 -0
- package/dist/heart/daemon/cli-arg-redaction.js +26 -0
- package/dist/heart/daemon/cli-commands/a2a.js +26 -0
- package/dist/heart/daemon/cli-commands/cards.js +68 -0
- package/dist/heart/daemon/cli-commands/coding-tools.js +13 -0
- package/dist/heart/daemon/cli-commands/desk.js +43 -0
- package/dist/heart/daemon/cli-commands/dns.js +13 -0
- package/dist/heart/daemon/cli-commands/entry-points.js +176 -0
- package/dist/heart/daemon/cli-commands/failure-code.js +11 -0
- package/dist/heart/daemon/cli-commands/friends.js +18 -0
- package/dist/heart/daemon/cli-commands/habits.js +15 -0
- package/dist/heart/daemon/cli-commands/lifecycle.js +42 -0
- package/dist/heart/daemon/cli-commands/mail.js +11 -0
- package/dist/heart/daemon/cli-commands/mind.js +25 -0
- package/dist/heart/daemon/cli-commands/presence.js +28 -0
- package/dist/heart/daemon/cli-commands/providers.js +20 -0
- package/dist/heart/daemon/cli-commands/rsvp.js +20 -0
- package/dist/heart/daemon/cli-commands/shepherd.js +17 -0
- package/dist/heart/daemon/cli-commands/vault.js +23 -0
- package/dist/heart/daemon/cli-defaults.js +997 -0
- package/dist/heart/daemon/cli-desk.js +346 -0
- package/dist/heart/daemon/cli-exec.js +9672 -0
- package/dist/heart/daemon/cli-gate.js +198 -0
- package/dist/heart/daemon/cli-help.js +800 -0
- package/dist/heart/daemon/cli-manifest.js +115 -0
- package/dist/heart/daemon/cli-parse.js +3623 -0
- package/dist/heart/daemon/cli-render-doctor.js +57 -0
- package/dist/heart/daemon/cli-render.js +816 -0
- package/dist/heart/daemon/cli-types.js +8 -0
- package/dist/heart/daemon/compile-cache.js +69 -0
- package/dist/heart/daemon/connect-bay.js +323 -0
- package/dist/heart/daemon/container-credential-bootstrap.js +273 -0
- package/dist/heart/daemon/container-healthcheck.js +123 -0
- package/dist/heart/daemon/container-runtime.js +97 -0
- package/dist/heart/daemon/container-spec-auditor-main.js +187 -0
- package/dist/heart/daemon/container-spec-auditor.js +261 -0
- package/dist/heart/daemon/daemon-bootstrap-startup.js +115 -0
- package/dist/heart/daemon/daemon-cli.js +29 -3145
- package/dist/heart/daemon/daemon-entry.js +1082 -55
- package/dist/heart/daemon/daemon-health.js +186 -0
- package/dist/heart/daemon/daemon-rollup.js +57 -0
- package/dist/heart/daemon/daemon-runtime-sync.js +147 -13
- package/dist/heart/daemon/daemon-tombstone.js +134 -4
- package/dist/heart/daemon/daemon.js +1975 -131
- package/dist/heart/daemon/desk-admin.js +420 -0
- package/dist/heart/daemon/dns-workflow.js +394 -0
- package/dist/heart/daemon/doctor-types.js +8 -0
- package/dist/heart/daemon/doctor.js +1890 -0
- package/dist/heart/daemon/freshness.js +345 -0
- package/dist/heart/daemon/habit-private-wake.js +61 -0
- package/dist/heart/daemon/health-monitor.js +209 -12
- package/dist/heart/daemon/home-filesystem.js +93 -0
- package/dist/heart/daemon/hook-post-tool-use.js +149 -0
- package/dist/heart/daemon/hooks/agent-config-v2.js +33 -0
- package/dist/heart/daemon/hooks/bundle-meta.js +135 -1
- package/dist/heart/daemon/http-health-probe.js +80 -0
- package/dist/heart/daemon/human-command-screens.js +234 -0
- package/dist/heart/daemon/human-readiness.js +114 -0
- package/dist/heart/daemon/inner-status.js +7 -18
- package/dist/heart/daemon/interactive-repair.js +394 -0
- package/dist/heart/daemon/launchd.js +40 -8
- package/dist/heart/daemon/linux-service.js +382 -0
- package/dist/heart/daemon/log-tailer.js +79 -10
- package/dist/heart/daemon/logs-prune.js +132 -0
- package/dist/heart/daemon/mailroom-copy-proof.js +158 -0
- package/dist/heart/daemon/mcp-canary.js +525 -0
- package/dist/heart/daemon/message-router.js +65 -5
- package/dist/heart/daemon/migrate-to-desk.js +848 -0
- package/dist/heart/daemon/os-cron-deps.js +5 -0
- package/dist/heart/daemon/os-cron.js +45 -15
- package/dist/heart/daemon/ouro-bot-entry.js +8 -3
- package/dist/heart/daemon/ouro-cli-main.js +50 -0
- package/dist/heart/daemon/ouro-entry.js +43 -20
- package/dist/heart/daemon/plugin-cli.js +432 -0
- package/dist/heart/daemon/portable-git-install.js +265 -0
- package/dist/heart/daemon/portable-git.js +179 -0
- package/dist/heart/daemon/presence-daemon.js +265 -0
- package/dist/heart/daemon/presence-roster.js +260 -0
- package/dist/heart/daemon/presence.js +469 -0
- package/dist/heart/daemon/process-manager.js +790 -71
- package/dist/heart/daemon/process-tree.js +109 -0
- package/dist/heart/daemon/provider-discovery.js +171 -0
- package/dist/heart/daemon/provider-ping-progress.js +83 -0
- package/dist/heart/daemon/prunable-bundle.js +144 -0
- package/dist/heart/daemon/pulse.js +511 -0
- package/dist/heart/daemon/readiness-repair.js +365 -0
- package/dist/heart/daemon/run-hooks.js +2 -0
- package/dist/heart/daemon/runtime-logging.js +54 -14
- package/dist/heart/daemon/runtime-metadata.js +2 -30
- package/dist/heart/daemon/runtime-mode.js +13 -2
- package/dist/heart/daemon/runtime-replacement-handoff.js +207 -0
- package/dist/heart/daemon/safe-mode.js +161 -0
- package/dist/heart/daemon/sanctuary-acceptance-adapter.js +2659 -0
- package/dist/heart/daemon/sanctuary-acceptance-harness.js +1832 -0
- package/dist/heart/daemon/sanctuary-acceptance-marker.js +267 -0
- package/dist/heart/daemon/sanctuary-acceptance-scenarios.js +956 -0
- package/dist/heart/daemon/sanctuary-authority-codec.js +86 -0
- package/dist/heart/daemon/sanctuary-authority-epoch.js +291 -0
- package/dist/heart/daemon/sanctuary-authority-installation.js +161 -0
- package/dist/heart/daemon/sanctuary-authority-ledger.js +241 -0
- package/dist/heart/daemon/sanctuary-authority-root-lifecycle.js +1370 -0
- package/dist/heart/daemon/sanctuary-authority-vault-migration.js +79 -0
- package/dist/heart/daemon/sanctuary-bundle-migration.js +974 -0
- package/dist/heart/daemon/sanctuary-host-authority.js +1008 -0
- package/dist/heart/daemon/sanctuary-host-detached-supervisor.js +493 -0
- package/dist/heart/daemon/sanctuary-host-executor.js +670 -0
- package/dist/heart/daemon/sanctuary-host-linux-kernel.js +334 -0
- package/dist/heart/daemon/sanctuary-host-supervisor-entry.js +210 -0
- package/dist/heart/daemon/sanctuary-host-supervisor.js +95 -0
- package/dist/heart/daemon/sanctuary-package-management.js +113 -0
- package/dist/heart/daemon/sanctuary-scheduler-liveness.js +227 -0
- package/dist/heart/daemon/sanctuary-scheduler-origin.js +132 -0
- package/dist/heart/daemon/sanctuary-telegram-authority-entry.js +481 -0
- package/dist/heart/daemon/sanctuary-telegram-authority-gateway.js +614 -0
- package/dist/heart/daemon/sanctuary-telegram-authority-service.js +763 -0
- package/dist/heart/daemon/sanctuary-telegram-test-driver-entry.js +97 -0
- package/dist/heart/daemon/sanctuary-telegram-test-driver.js +294 -0
- package/dist/heart/daemon/sense-manager.js +1071 -60
- package/dist/heart/daemon/skill-management-installer.js +1 -1
- package/dist/heart/daemon/socket-client.js +180 -12
- package/dist/heart/daemon/stale-bundle-prune.js +113 -0
- package/dist/heart/daemon/startup-tui.js +339 -0
- package/dist/heart/daemon/state-retention.js +234 -0
- package/dist/heart/daemon/supercronic-supervisor.js +282 -0
- package/dist/heart/daemon/task-scheduler.js +115 -15
- package/dist/heart/daemon/terminal-ui.js +503 -0
- package/dist/heart/daemon/thoughts.js +133 -49
- package/dist/heart/daemon/up-progress.js +366 -0
- package/dist/heart/daemon/vault-items.js +56 -0
- package/dist/heart/daemon/vault-outage.js +74 -0
- package/dist/heart/delegated-work-report.js +115 -0
- package/dist/heart/delegation.js +0 -3
- package/dist/heart/external-events/router.js +1556 -0
- package/dist/heart/failure-reports.js +398 -0
- package/dist/heart/file-lock.js +109 -0
- package/dist/heart/frontend-approval-runtime.js +506 -0
- package/dist/heart/frontend-journal.js +215 -0
- package/dist/heart/frontend-session-service.js +330 -0
- package/dist/heart/frontend-socket-client.js +173 -0
- package/dist/heart/frontend-socket.js +434 -0
- package/dist/heart/frontend-turn-errors.js +20 -0
- package/dist/heart/git-binary.js +115 -0
- package/dist/heart/habits/habit-cancel.js +810 -0
- package/dist/heart/habits/habit-lifecycle.js +1324 -0
- package/dist/heart/{daemon → habits}/habit-migration.js +41 -28
- package/dist/heart/habits/habit-parser.js +278 -0
- package/dist/heart/habits/habit-runtime-state.js +93 -0
- package/dist/heart/habits/habit-scheduler.js +667 -0
- package/dist/heart/habits/habit-session-summary.js +318 -0
- package/dist/heart/habits/habit-session.js +643 -0
- package/dist/heart/{daemon → hatch}/hatch-flow.js +60 -36
- package/dist/heart/{daemon → hatch}/hatch-specialist.js +6 -8
- package/dist/heart/{daemon → hatch}/specialist-prompt.js +10 -6
- package/dist/heart/hatch/specialist-tools.js +395 -0
- package/dist/heart/identity.js +389 -60
- package/dist/heart/kept-notes.js +289 -0
- package/dist/heart/letters/doors-tools.js +31 -0
- package/dist/heart/letters/doors.js +226 -0
- package/dist/heart/machine-identity.js +175 -0
- package/dist/heart/mail-import-discovery.js +356 -0
- package/dist/heart/mcp/mcp-server.js +893 -0
- package/dist/heart/migrate-config.js +100 -0
- package/dist/heart/model-capabilities.js +98 -16
- package/dist/heart/model-limits.js +49 -0
- package/dist/heart/optional-packages.js +77 -0
- package/dist/heart/orientation-frame.js +393 -0
- package/dist/heart/platform.js +81 -0
- package/dist/heart/primitives.js +1 -1
- package/dist/heart/private-runtime/decision-renderer.js +158 -0
- package/dist/heart/private-runtime/index.js +18 -0
- package/dist/heart/private-runtime/ledger.js +212 -0
- package/dist/heart/private-runtime/policy.js +303 -0
- package/dist/heart/private-runtime/types.js +2 -0
- package/dist/heart/progress-story.js +1 -1
- package/dist/heart/provider-attempt.js +137 -0
- package/dist/heart/provider-binding-resolver.js +273 -0
- package/dist/heart/provider-credentials.js +449 -0
- package/dist/heart/provider-failover.js +260 -37
- package/dist/heart/provider-fallback.js +228 -0
- package/dist/heart/provider-models.js +96 -0
- package/dist/heart/provider-ping-child.js +125 -0
- package/dist/heart/provider-ping-entry.js +8 -0
- package/dist/heart/provider-ping.js +217 -78
- package/dist/heart/provider-readiness-cache.js +119 -0
- package/dist/heart/provider-visibility.js +188 -0
- package/dist/heart/providers/account-pool.js +717 -0
- package/dist/heart/providers/anthropic-token.js +15 -47
- package/dist/heart/providers/anthropic.js +275 -80
- package/dist/heart/providers/azure.js +19 -31
- package/dist/heart/providers/error-classification.js +129 -0
- package/dist/heart/providers/github-copilot.js +131 -36
- package/dist/heart/providers/minimax-vlm.js +189 -0
- package/dist/heart/providers/minimax.js +19 -27
- package/dist/heart/providers/openai-codex-token.js +349 -0
- package/dist/heart/providers/openai-codex.js +46 -57
- package/dist/heart/providers/openai-compatible.js +177 -0
- package/dist/heart/quota/fleet-readings.js +222 -0
- package/dist/heart/quota/tranche.js +59 -0
- package/dist/heart/reach-channel.js +85 -0
- package/dist/heart/reply-style.js +52 -0
- package/dist/heart/run-ledger.js +247 -0
- package/dist/heart/runtime-capability-check.js +170 -0
- package/dist/heart/runtime-credentials.js +647 -0
- package/dist/heart/runtime-cwd.js +87 -0
- package/dist/heart/sense-truth.js +26 -4
- package/dist/heart/sent-message-ledger.js +98 -0
- package/dist/heart/session-activity.js +89 -23
- package/dist/heart/session-events.js +1602 -0
- package/dist/heart/session-playback-cli-main.js +10 -0
- package/dist/heart/session-playback-cli.js +36 -0
- package/dist/heart/session-playback.js +231 -0
- package/dist/heart/session-redaction-repair-cli-main.js +34 -0
- package/dist/heart/session-redaction-repair.js +552 -0
- package/dist/heart/session-stats-cli-main.js +10 -0
- package/dist/heart/session-stats.js +183 -0
- package/dist/heart/session-transcript.js +133 -0
- package/dist/heart/shelf-claims.js +136 -0
- package/dist/heart/shepherd/custody-types.js +2 -0
- package/dist/heart/shepherd/mandates.js +352 -0
- package/dist/heart/shepherd/operation-commands.js +19 -0
- package/dist/heart/shepherd/operations.js +139 -0
- package/dist/heart/shepherd/supervision-read.js +131 -0
- package/dist/heart/shepherd/supervision.js +114 -0
- package/dist/heart/shepherd/types.js +2 -0
- package/dist/heart/shepherd-config.js +113 -0
- package/dist/heart/source-grounding.js +313 -0
- package/dist/heart/sqlite.js +18 -0
- package/dist/heart/start-of-turn-packet.js +372 -0
- package/dist/heart/steward-policy.js +656 -0
- package/dist/heart/streaming.js +627 -193
- package/dist/heart/structured-output.js +196 -0
- package/dist/heart/sync-classification.js +176 -0
- package/dist/heart/sync-health.js +152 -0
- package/dist/heart/sync-lock.js +431 -0
- package/dist/heart/sync.js +1583 -0
- package/dist/heart/target-resolution.js +7 -7
- package/dist/heart/tempo.js +93 -0
- package/dist/heart/temporal-view.js +41 -0
- package/dist/heart/termination-guard.js +27 -0
- package/dist/heart/timeouts.js +101 -0
- package/dist/heart/tool-activity-callbacks.js +59 -0
- package/dist/heart/tool-approval.js +382 -0
- package/dist/heart/tool-description.js +155 -0
- package/dist/heart/tool-friction.js +55 -0
- package/dist/heart/tool-images.js +42 -0
- package/dist/heart/tool-loop.js +9 -3
- package/dist/heart/tool-output-budget.js +41 -0
- package/dist/heart/turn-context.js +503 -0
- package/dist/heart/turn-execution-lease.js +78 -0
- package/dist/heart/turn-summary.js +216 -0
- package/dist/heart/versioning/host-self-update.js +118 -0
- package/dist/heart/{daemon → versioning}/ouro-bot-global-installer.js +6 -5
- package/dist/heart/{daemon → versioning}/ouro-bot-wrapper.js +3 -2
- package/dist/heart/versioning/ouro-path-installer.js +432 -0
- package/dist/heart/versioning/ouro-recovery-launcher.js +98 -0
- package/dist/heart/versioning/ouro-version-manager.js +432 -0
- package/dist/heart/versioning/release-sources.js +185 -0
- package/dist/heart/versioning/self-update-defaults.js +443 -0
- package/dist/heart/versioning/self-update.js +270 -0
- package/dist/heart/{daemon → versioning}/staged-restart.js +40 -8
- package/dist/heart/{daemon → versioning}/update-checker.js +12 -35
- package/dist/heart/versioning/update-hooks.js +160 -0
- package/dist/heart/versioning/update-state.js +134 -0
- package/dist/heart/versioning/updater-launchd.js +204 -0
- package/dist/heart/versioning/version-intent.js +114 -0
- package/dist/heart/work-card.js +380 -0
- package/dist/mailroom/attention.js +167 -0
- package/dist/mailroom/autonomy.js +209 -0
- package/dist/mailroom/azure-sdk.js +27 -0
- package/dist/mailroom/blob-store.js +991 -0
- package/dist/mailroom/body-cache.js +61 -0
- package/dist/mailroom/cache-sync-cli.js +58 -0
- package/dist/mailroom/core.js +813 -0
- package/dist/mailroom/entry.js +169 -0
- package/dist/mailroom/file-store.js +568 -0
- package/dist/mailroom/hosted-cache-sync.js +384 -0
- package/dist/mailroom/mbox-import.js +393 -0
- package/dist/mailroom/migration.js +164 -0
- package/dist/mailroom/outbound.js +380 -0
- package/dist/mailroom/policy.js +263 -0
- package/dist/mailroom/reader.js +308 -0
- package/dist/mailroom/search-cache.js +513 -0
- package/dist/mailroom/search-relevance.js +319 -0
- package/dist/mailroom/smtp-ingress.js +176 -0
- package/dist/mailroom/source-state.js +176 -0
- package/dist/mailroom/sweep-orphans-cli.js +34 -0
- package/dist/mailroom/thread.js +109 -0
- package/dist/mailroom/travel-extract.js +89 -0
- package/dist/mind/bundle-manifest.js +25 -4
- package/dist/mind/context.js +335 -198
- package/dist/mind/desk-section.js +332 -0
- package/dist/mind/diary-integrity.js +60 -0
- package/dist/mind/diary.js +31 -53
- package/dist/mind/embedding-provider.js +60 -0
- package/dist/mind/file-state.js +179 -0
- package/dist/mind/friend-link-codes.js +209 -0
- package/dist/mind/friend-merge.js +336 -0
- package/dist/mind/house-names.js +43 -0
- package/dist/mind/note-search.js +198 -0
- package/dist/mind/obligation-steering.js +15 -9
- package/dist/mind/outbound-record.js +176 -0
- package/dist/mind/pending.js +294 -11
- package/dist/mind/prompt-budget.js +511 -0
- package/dist/mind/prompt-refresh.js +3 -2
- package/dist/mind/prompt.js +947 -368
- package/dist/mind/provenance-trust.js +26 -0
- package/dist/mind/record-paths.js +312 -0
- package/dist/mind/scrutiny.js +121 -0
- package/dist/mind/session-transaction.js +642 -0
- package/dist/mind/token-estimate.js +17 -0
- package/dist/mind/where-am-i.js +150 -0
- package/dist/nerves/cli-logging.js +7 -1
- package/dist/nerves/coverage/audit-rules.js +15 -6
- package/dist/nerves/coverage/audit.js +28 -2
- package/dist/nerves/coverage/cli-main.js +6 -1
- package/dist/nerves/coverage/cli.js +1 -1
- package/dist/nerves/coverage/contract.js +5 -5
- package/dist/nerves/coverage/file-completeness.js +153 -5
- package/dist/nerves/coverage/run-artifacts.js +55 -35
- package/dist/nerves/coverage/source-scanner.js +4 -4
- package/dist/nerves/event-buffer.js +111 -0
- package/dist/nerves/index.js +270 -31
- package/dist/nerves/observation.js +18 -0
- package/dist/nerves/redact.js +79 -0
- package/dist/nerves/review/cli-main.js +10 -0
- package/dist/nerves/review/cli.js +156 -0
- package/dist/nerves/review/core.js +159 -0
- package/dist/nerves/runtime.js +16 -1
- package/dist/repertoire/ado-client.js +15 -56
- package/dist/repertoire/ado-semantic.js +108 -40
- package/dist/repertoire/api-client.js +97 -0
- package/dist/repertoire/auth-required.js +22 -0
- package/dist/repertoire/bitwarden-native.js +458 -0
- package/dist/repertoire/bitwarden-store.js +1296 -0
- package/dist/repertoire/bundle-templates.js +71 -0
- package/dist/repertoire/bw-installer.js +268 -0
- package/dist/repertoire/coding/context-pack.js +80 -3
- package/dist/repertoire/coding/feedback.js +27 -26
- package/dist/repertoire/coding/index.js +63 -6
- package/dist/repertoire/coding/manager.js +31 -14
- package/dist/repertoire/coding/orca-client.js +194 -0
- package/dist/repertoire/coding/orca-manager.js +460 -0
- package/dist/repertoire/coding/router.js +124 -0
- package/dist/repertoire/coding/spawner.js +3 -2
- package/dist/repertoire/coding/tools.js +178 -34
- package/dist/repertoire/coding/workbench-client.js +272 -0
- package/dist/repertoire/coding/workbench-manager.js +404 -0
- package/dist/repertoire/commerce-errors.js +109 -0
- package/dist/repertoire/commerce-self-test.js +156 -0
- package/dist/repertoire/credential-access.js +183 -0
- package/dist/repertoire/desk/classifier.js +362 -0
- package/dist/repertoire/desk-mcp.js +140 -0
- package/dist/repertoire/duffel-client.js +185 -0
- package/dist/repertoire/github-client.js +14 -55
- package/dist/repertoire/graph-client.js +11 -52
- package/dist/repertoire/guardrails.js +1174 -70
- package/dist/repertoire/house-sweep.js +471 -0
- package/dist/repertoire/in-turn-tools-door.js +54 -0
- package/dist/repertoire/mcp-client.js +58 -5
- package/dist/repertoire/mcp-declared-tools.js +156 -0
- package/dist/repertoire/mcp-manager.js +457 -141
- package/dist/repertoire/mcp-tools.js +199 -0
- package/dist/repertoire/mcp-write-guard.js +85 -0
- package/dist/repertoire/plugin-mcp.js +175 -0
- package/dist/repertoire/plugins.js +253 -0
- package/dist/repertoire/relationship-authorization.js +322 -0
- package/dist/repertoire/sanctuary-container-policy.js +50 -0
- package/dist/repertoire/shell-sessions.js +136 -0
- package/dist/repertoire/skill-search.js +177 -0
- package/dist/repertoire/skill-summaries.js +129 -0
- package/dist/repertoire/skills.js +34 -4
- package/dist/repertoire/stripe-client.js +163 -0
- package/dist/repertoire/tool-arguments.js +180 -0
- package/dist/repertoire/tool-candidates.js +50 -0
- package/dist/repertoire/tool-catalog.js +228 -0
- package/dist/repertoire/tool-error-code.js +30 -0
- package/dist/repertoire/tool-limits.js +20 -0
- package/dist/repertoire/tool-results.js +29 -0
- package/dist/repertoire/tools-a2a.js +792 -0
- package/dist/repertoire/tools-app-sessions.js +219 -0
- package/dist/repertoire/tools-attachments.js +302 -0
- package/dist/repertoire/tools-awaiting.js +934 -0
- package/dist/repertoire/tools-base.js +85 -1420
- package/dist/repertoire/tools-bridge.js +153 -0
- package/dist/repertoire/tools-bundle.js +998 -0
- package/dist/repertoire/tools-chat.js +185 -0
- package/dist/repertoire/tools-commerce.js +272 -0
- package/dist/repertoire/tools-config.js +199 -0
- package/dist/repertoire/tools-continuity.js +648 -0
- package/dist/repertoire/tools-credential.js +410 -0
- package/dist/repertoire/tools-escalation.js +98 -0
- package/dist/repertoire/tools-evolution.js +560 -0
- package/dist/repertoire/tools-files.js +521 -0
- package/dist/repertoire/tools-flight.js +313 -0
- package/dist/repertoire/tools-flow.js +169 -0
- package/dist/repertoire/tools-friend-link.js +65 -0
- package/dist/repertoire/tools-github.js +11 -4
- package/dist/repertoire/tools-habits.js +111 -0
- package/dist/repertoire/tools-house-care.js +190 -0
- package/dist/repertoire/tools-mail.js +1928 -0
- package/dist/repertoire/tools-notes.js +567 -0
- package/dist/repertoire/tools-obligations.js +187 -0
- package/dist/repertoire/tools-orientation.js +36 -0
- package/dist/repertoire/tools-record.js +497 -0
- package/dist/repertoire/tools-rsvp.js +148 -0
- package/dist/repertoire/tools-runtime.js +260 -0
- package/dist/repertoire/tools-sanctuary-host.js +213 -0
- package/dist/repertoire/tools-session.js +1190 -0
- package/dist/repertoire/tools-shell.js +275 -0
- package/dist/repertoire/tools-shepherd-guidance.js +183 -0
- package/dist/repertoire/tools-shepherd.js +369 -0
- package/dist/repertoire/tools-steward-policy.js +157 -0
- package/dist/repertoire/tools-stripe.js +244 -0
- package/dist/repertoire/tools-surface.js +553 -0
- package/dist/repertoire/tools-teams.js +67 -17
- package/dist/repertoire/tools-telegram-contacts.js +41 -0
- package/dist/repertoire/tools-travel.js +142 -0
- package/dist/repertoire/tools-trip.js +1041 -0
- package/dist/repertoire/tools-unraid.js +627 -0
- package/dist/repertoire/tools-user-profile.js +166 -0
- package/dist/repertoire/tools-vault.js +46 -0
- package/dist/repertoire/tools-voice-local.js +210 -0
- package/dist/repertoire/tools-voice.js +153 -0
- package/dist/repertoire/tools-web.js +238 -0
- package/dist/repertoire/tools.js +608 -288
- package/dist/repertoire/travel-api-client.js +463 -0
- package/dist/repertoire/unraid-client.js +155 -0
- package/dist/repertoire/unraid-restart.js +342 -0
- package/dist/repertoire/user-profile.js +131 -0
- package/dist/repertoire/vault-setup.js +298 -0
- package/dist/repertoire/vault-unlock.js +816 -0
- package/dist/rsvp/aisleplanner-client.js +354 -0
- package/dist/rsvp/cli.js +936 -0
- package/dist/rsvp/config.js +327 -0
- package/dist/rsvp/cutover.js +453 -0
- package/dist/rsvp/diagnostics.js +232 -0
- package/dist/rsvp/diff-renderer.js +176 -0
- package/dist/rsvp/habit-policy.js +110 -0
- package/dist/rsvp/habit-stage.js +123 -0
- package/dist/rsvp/incident-bundle.js +97 -0
- package/dist/rsvp/migration.js +204 -0
- package/dist/rsvp/native-habit-runner.js +630 -0
- package/dist/rsvp/outbound-state.js +628 -0
- package/dist/rsvp/query.js +118 -0
- package/dist/rsvp/replay.js +233 -0
- package/dist/rsvp/snapshot.js +232 -0
- package/dist/rsvp/spend-ledger.js +175 -0
- package/dist/scripts/claude-code-stop-hook.js +4 -3
- package/dist/senses/a2a-entry.js +145 -0
- package/dist/senses/acp-server.js +386 -0
- package/dist/senses/app-sessions/client.js +128 -0
- package/dist/senses/app-sessions/digest-cards.js +187 -0
- package/dist/senses/app-sessions/digest-push.js +108 -0
- package/dist/senses/app-sessions/digest-sources.js +204 -0
- package/dist/senses/app-sessions/digest.js +284 -0
- package/dist/senses/app-sessions/run-command.js +51 -0
- package/dist/senses/app-sessions/sense.js +242 -0
- package/dist/senses/app-sessions/shepherd-cli.js +166 -0
- package/dist/senses/app-sessions/shepherd-rows.js +67 -0
- package/dist/senses/app-sessions/store.js +149 -0
- package/dist/senses/app-sessions/waiting-prompts.js +137 -0
- package/dist/senses/app-sessions/waiting-status.js +23 -0
- package/dist/senses/app-sessions-entry.js +87 -0
- package/dist/senses/attention-queue.js +95 -6
- package/dist/senses/await-turn-message.js +65 -0
- package/dist/senses/bluebubbles/active-turns.js +241 -0
- package/dist/senses/bluebubbles/attachment-cache.js +53 -0
- package/dist/senses/bluebubbles/attachment-download.js +143 -0
- package/dist/senses/{bluebubbles-client.js → bluebubbles/client.js} +391 -49
- package/dist/senses/bluebubbles/context-packet.js +207 -0
- package/dist/senses/bluebubbles/context-smoke.js +144 -0
- package/dist/senses/bluebubbles/entry.js +80 -0
- package/dist/senses/bluebubbles/host-account-verifier.js +113 -0
- package/dist/senses/{bluebubbles-inbound-log.js → bluebubbles/inbound-log.js} +21 -3
- package/dist/senses/bluebubbles/index.js +4663 -0
- package/dist/senses/bluebubbles/latest-turn.js +342 -0
- package/dist/senses/bluebubbles/media.js +255 -0
- package/dist/senses/{bluebubbles-model.js → bluebubbles/model.js} +152 -30
- package/dist/senses/{bluebubbles-mutation-log.js → bluebubbles/mutation-log.js} +24 -13
- package/dist/senses/bluebubbles/outbound-state.js +335 -0
- package/dist/senses/bluebubbles/processed-log.js +133 -0
- package/dist/senses/bluebubbles/reactions.js +18 -0
- package/dist/senses/bluebubbles/replay.js +284 -0
- package/dist/senses/{bluebubbles-runtime-state.js → bluebubbles/runtime-state.js} +47 -4
- package/dist/senses/bluebubbles/semantic-receipts.js +2014 -0
- package/dist/senses/bluebubbles/send-file.js +20 -0
- package/dist/senses/bluebubbles/send-health.js +126 -0
- package/dist/senses/{bluebubbles-session-cleanup.js → bluebubbles/session-cleanup.js} +1 -1
- package/dist/senses/bluebubbles/webhook-registration.js +257 -0
- package/dist/senses/bluebubbles-meta-guard.js +39 -0
- package/dist/senses/chat-file.js +75 -0
- package/dist/senses/cli/bracketed-paste.js +82 -0
- package/dist/senses/cli/image-paste.js +287 -0
- package/dist/senses/cli/image-ref-navigation.js +75 -0
- package/dist/senses/cli/ink-app.js +156 -0
- package/dist/senses/cli/inline-diff.js +64 -0
- package/dist/senses/cli/input-keys.js +209 -0
- package/dist/senses/cli/kill-ring.js +86 -0
- package/dist/senses/cli/message-list.js +51 -0
- package/dist/senses/cli/ouro-tui.js +633 -0
- package/dist/senses/cli/spinner-imperative.js +135 -0
- package/dist/senses/cli/spinner.js +101 -0
- package/dist/senses/cli/status-line.js +60 -0
- package/dist/senses/cli/streaming-markdown.js +526 -0
- package/dist/senses/cli/tool-display.js +85 -0
- package/dist/senses/cli/tool-render.js +85 -0
- package/dist/senses/cli/tui-store.js +252 -0
- package/dist/senses/cli/virtual-list.js +35 -0
- package/dist/senses/cli-entry.js +62 -9
- package/dist/senses/cli.js +627 -350
- package/dist/senses/commands.js +66 -3
- package/dist/senses/context-packet-ledger.js +367 -0
- package/dist/senses/context-packets.js +154 -0
- package/dist/senses/habit-lifecycle-guard.js +24 -0
- package/dist/senses/habit-turn-message.js +160 -0
- package/dist/senses/inbound-journal.js +186 -0
- package/dist/senses/ingress-evidence.js +2 -0
- package/dist/senses/mail-entry.js +69 -0
- package/dist/senses/mail.js +524 -0
- package/dist/senses/ordinary-owner-decision.js +98 -0
- package/dist/senses/pipeline.js +1216 -289
- package/dist/senses/private-runtime-worker.js +857 -0
- package/dist/senses/private-runtime.js +1692 -0
- package/dist/senses/proactive-content-guard.js +51 -0
- package/dist/senses/program-status.js +155 -0
- package/dist/senses/repeat-while.js +36 -0
- package/dist/senses/root-host-approval-port.js +345 -0
- package/dist/senses/root-host-approval-runtime.js +393 -0
- package/dist/senses/sanctuary-authority-resident.js +102 -0
- package/dist/senses/sanctuary-download-credit-presentation.js +31 -0
- package/dist/senses/sanctuary-full-visibility-contract.js +302 -0
- package/dist/senses/sanctuary-grounding.js +118 -0
- package/dist/senses/sanctuary-health-acceptance-probe-entry.js +21 -0
- package/dist/senses/sanctuary-health-acceptance-probe.js +802 -0
- package/dist/senses/sanctuary-health-runner.js +106 -0
- package/dist/senses/sanctuary-health.js +442 -0
- package/dist/senses/sanctuary-house.js +97 -0
- package/dist/senses/sanctuary-install-state-contract.js +169 -0
- package/dist/senses/sanctuary-interactive-control.js +410 -0
- package/dist/senses/sanctuary-media-catalog-contract.js +268 -0
- package/dist/senses/sanctuary-media-optimization.js +517 -0
- package/dist/senses/sanctuary-runtime.js +392 -0
- package/dist/senses/sanctuary-sab.js +85 -0
- package/dist/senses/sanctuary-storage-optimization-contract.js +32 -0
- package/dist/senses/sense-shutdown.js +72 -0
- package/dist/senses/shared-turn.js +741 -97
- package/dist/senses/shepherd/agent-presentation.js +88 -0
- package/dist/senses/shepherd/attention-page.js +166 -0
- package/dist/senses/shepherd/attention-sidebar.js +76 -0
- package/dist/senses/shepherd/attention.js +295 -0
- package/dist/senses/shepherd/checkin-config.js +76 -0
- package/dist/senses/shepherd/checkin-store.js +383 -0
- package/dist/senses/shepherd/client.js +196 -0
- package/dist/senses/shepherd/cmux.js +483 -0
- package/dist/senses/shepherd/composer.js +336 -0
- package/dist/senses/shepherd/conversation-hold.js +78 -0
- package/dist/senses/shepherd/feedback-reply.js +108 -0
- package/dist/senses/shepherd/feedback-source.js +20 -0
- package/dist/senses/shepherd/feedback-store.js +328 -0
- package/dist/senses/shepherd/feedback-submit.js +182 -0
- package/dist/senses/shepherd/feedback-worker.js +208 -0
- package/dist/senses/shepherd/guidance.js +273 -0
- package/dist/senses/shepherd/herdr.js +427 -0
- package/dist/senses/shepherd/host.js +14 -0
- package/dist/senses/shepherd/human-decision-guard.js +29 -0
- package/dist/senses/shepherd/judge-evaluation-command.js +185 -0
- package/dist/senses/shepherd/judge-evaluation-entry.js +20 -0
- package/dist/senses/shepherd/judge-evaluation.js +144 -0
- package/dist/senses/shepherd/judge.js +210 -0
- package/dist/senses/shepherd/notice-outbox.js +254 -0
- package/dist/senses/shepherd/observation-publisher.js +320 -0
- package/dist/senses/shepherd/operations-defaults.js +86 -0
- package/dist/senses/shepherd/operations.js +159 -0
- package/dist/senses/shepherd/owner-notice.js +496 -0
- package/dist/senses/shepherd/prompt-state.js +60 -0
- package/dist/senses/shepherd/recovery.js +543 -0
- package/dist/senses/shepherd/redact.js +66 -0
- package/dist/senses/shepherd/returns.js +79 -0
- package/dist/senses/shepherd/sense.js +862 -0
- package/dist/senses/shepherd/shepherd-judge-corpus-v1.json +170 -0
- package/dist/senses/shepherd/surface.js +125 -0
- package/dist/senses/shepherd/target-binding.js +13 -0
- package/dist/senses/shepherd/terminal-process.js +147 -0
- package/dist/senses/shepherd-entry.js +98 -0
- package/dist/senses/surface-tool.js +60 -34
- package/dist/senses/teams-attachments.js +68 -0
- package/dist/senses/teams-entry.js +80 -9
- package/dist/senses/teams-image.js +128 -0
- package/dist/senses/teams-inbound.js +76 -0
- package/dist/senses/teams-off-turn.js +199 -0
- package/dist/senses/teams-outbox.js +249 -0
- package/dist/senses/teams.js +1267 -378
- package/dist/senses/telegram-admission.js +700 -0
- package/dist/senses/telegram-approval-relay.js +293 -0
- package/dist/senses/telegram-approval-runtime.js +831 -0
- package/dist/senses/telegram-attachments.js +128 -0
- package/dist/senses/telegram-audit-ledger.js +220 -0
- package/dist/senses/telegram-authority-transport.js +233 -0
- package/dist/senses/telegram-chat-actions.js +57 -0
- package/dist/senses/telegram-client.js +1896 -0
- package/dist/senses/telegram-effect-adapter.js +892 -0
- package/dist/senses/telegram-entry.js +87 -0
- package/dist/senses/telegram-handoff.js +150 -0
- package/dist/senses/telegram-identity-key.js +143 -0
- package/dist/senses/telegram-markdown.js +331 -0
- package/dist/senses/telegram-owner-route.js +129 -0
- package/dist/senses/telegram.js +2789 -0
- package/dist/senses/terminal-handoff.js +44 -0
- package/dist/senses/trust-gate.js +104 -9
- package/dist/senses/turn-attempts.js +171 -0
- package/dist/senses/turn-watch.js +268 -0
- package/dist/senses/voice/audio-playback.js +237 -0
- package/dist/senses/voice/audio-routing.js +119 -0
- package/dist/senses/voice/call-auth.js +250 -0
- package/dist/senses/voice/elevenlabs.js +202 -0
- package/dist/senses/voice/floor-control.js +431 -0
- package/dist/senses/voice/floor-controller.js +115 -0
- package/dist/senses/voice/golden-path.js +116 -0
- package/dist/senses/voice/index.js +29 -0
- package/dist/senses/voice/local-audio-control.js +344 -0
- package/dist/senses/voice/local-audio-devices.js +516 -0
- package/dist/senses/voice/local-audio-disclosure.js +174 -0
- package/dist/senses/voice/local-audio-identity.js +103 -0
- package/dist/senses/voice/local-audio-join.js +325 -0
- package/dist/senses/voice/local-audio-mute.js +199 -0
- package/dist/senses/voice/local-audio-notify.js +124 -0
- package/dist/senses/voice/local-audio-prompts.js +116 -0
- package/dist/senses/voice/local-audio-transport.js +427 -0
- package/dist/senses/voice/local-audio.js +281 -0
- package/dist/senses/voice/local-media-stream.js +145 -0
- package/dist/senses/voice/meeting.js +113 -0
- package/dist/senses/voice/outbound.js +190 -0
- package/dist/senses/voice/phone.js +33 -0
- package/dist/senses/voice/playback.js +139 -0
- package/dist/senses/voice/process-guards.js +51 -0
- package/dist/senses/voice/realtime-eval.js +496 -0
- package/dist/senses/voice/realtime-tool-schema.js +195 -0
- package/dist/senses/voice/realtime-trace.js +531 -0
- package/dist/senses/voice/realtime-utterances.js +158 -0
- package/dist/senses/voice/transcript.js +70 -0
- package/dist/senses/voice/turn.js +219 -0
- package/dist/senses/voice/twilio-phone-runtime.js +836 -0
- package/dist/senses/voice/twilio-phone.js +5660 -0
- package/dist/senses/voice/types.js +2 -0
- package/dist/senses/voice/utterances.js +207 -0
- package/dist/senses/voice/whisper.js +153 -0
- package/dist/senses/voice-entry.js +84 -0
- package/dist/senses/voice-realtime-eval-command.js +99 -0
- package/dist/senses/voice-realtime-eval-entry.js +25 -0
- package/dist/senses/voice-twilio-entry.js +88 -0
- package/dist/trips/core.js +138 -0
- package/dist/trips/store.js +265 -0
- package/dist/util/frontmatter.js +69 -0
- package/node_modules/@ouro.bot/friends/LICENSE +201 -0
- package/node_modules/@ouro.bot/friends/README.md +687 -0
- package/node_modules/@ouro.bot/friends/actions/generated/mcp.json +1105 -0
- package/node_modules/@ouro.bot/friends/changelog.json +197 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/a2a-message.d.ts +39 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/a2a-message.js +54 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/adapter.d.ts +117 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/adapter.js +202 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/agent-card.d.ts +50 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/agent-card.js +32 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/did-key.d.ts +38 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/did-key.js +120 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/did-verifier.d.ts +195 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/did-verifier.js +342 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/did-web.d.ts +26 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/did-web.js +140 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/envelope-binding.d.ts +62 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/envelope-binding.js +83 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/index.d.ts +26 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/index.js +82 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/jcs.d.ts +5 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/jcs.js +84 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/reachability.d.ts +22 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/reachability.js +17 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/roster-verify.d.ts +15 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/roster-verify.js +61 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/seal.d.ts +47 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/seal.js +95 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/sealed-envelope.d.ts +58 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/sealed-envelope.js +113 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/sign.d.ts +42 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/sign.js +87 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/sodium.d.ts +5 -0
- package/node_modules/@ouro.bot/friends/dist/a2a-client/sodium.js +19 -0
- package/node_modules/@ouro.bot/friends/dist/account-roster.d.ts +52 -0
- package/node_modules/@ouro.bot/friends/dist/account-roster.js +108 -0
- package/node_modules/@ouro.bot/friends/dist/agent-peer.d.ts +26 -0
- package/node_modules/@ouro.bot/friends/dist/agent-peer.js +138 -0
- package/node_modules/@ouro.bot/friends/dist/audit.d.ts +42 -0
- package/node_modules/@ouro.bot/friends/dist/audit.js +86 -0
- package/node_modules/@ouro.bot/friends/dist/channel.d.ts +16 -0
- package/{dist/mind/friends → node_modules/@ouro.bot/friends/dist}/channel.js +83 -4
- package/node_modules/@ouro.bot/friends/dist/connect-authority.d.ts +43 -0
- package/node_modules/@ouro.bot/friends/dist/connect-authority.js +84 -0
- package/node_modules/@ouro.bot/friends/dist/connect.d.ts +56 -0
- package/node_modules/@ouro.bot/friends/dist/connect.js +163 -0
- package/node_modules/@ouro.bot/friends/dist/consent.d.ts +34 -0
- package/node_modules/@ouro.bot/friends/dist/consent.js +65 -0
- package/node_modules/@ouro.bot/friends/dist/coordination.d.ts +116 -0
- package/node_modules/@ouro.bot/friends/dist/coordination.js +329 -0
- package/node_modules/@ouro.bot/friends/dist/delegation-grant.d.ts +21 -0
- package/node_modules/@ouro.bot/friends/dist/delegation-grant.js +39 -0
- package/node_modules/@ouro.bot/friends/dist/file-bundle.d.ts +17 -0
- package/node_modules/@ouro.bot/friends/dist/file-bundle.js +27 -0
- package/node_modules/@ouro.bot/friends/dist/friend-lookup.d.ts +9 -0
- package/node_modules/@ouro.bot/friends/dist/friend-lookup.js +69 -0
- package/node_modules/@ouro.bot/friends/dist/grant-store-file.d.ts +19 -0
- package/node_modules/@ouro.bot/friends/dist/grant-store-file.js +157 -0
- package/node_modules/@ouro.bot/friends/dist/grant-store.d.ts +7 -0
- package/node_modules/@ouro.bot/friends/dist/grant-store.js +8 -0
- package/node_modules/@ouro.bot/friends/dist/grants.d.ts +43 -0
- package/node_modules/@ouro.bot/friends/dist/grants.js +100 -0
- package/node_modules/@ouro.bot/friends/dist/group-context.d.ts +21 -0
- package/{dist/mind/friends → node_modules/@ouro.bot/friends/dist}/group-context.js +5 -4
- package/node_modules/@ouro.bot/friends/dist/identity.d.ts +17 -0
- package/node_modules/@ouro.bot/friends/dist/identity.js +68 -0
- package/node_modules/@ouro.bot/friends/dist/index.d.ts +73 -0
- package/node_modules/@ouro.bot/friends/dist/index.js +164 -0
- package/node_modules/@ouro.bot/friends/dist/link-identity.d.ts +14 -0
- package/node_modules/@ouro.bot/friends/dist/link-identity.js +157 -0
- package/node_modules/@ouro.bot/friends/dist/mailbox/index.d.ts +105 -0
- package/node_modules/@ouro.bot/friends/dist/mailbox/index.js +205 -0
- package/node_modules/@ouro.bot/friends/dist/mcp/bin.d.ts +2 -0
- package/node_modules/@ouro.bot/friends/dist/mcp/bin.js +17 -0
- package/node_modules/@ouro.bot/friends/dist/mcp/dispatch.d.ts +40 -0
- package/node_modules/@ouro.bot/friends/dist/mcp/dispatch.js +744 -0
- package/node_modules/@ouro.bot/friends/dist/mcp/index.d.ts +6 -0
- package/node_modules/@ouro.bot/friends/dist/mcp/index.js +14 -0
- package/node_modules/@ouro.bot/friends/dist/mcp/run-main.d.ts +7 -0
- package/node_modules/@ouro.bot/friends/dist/mcp/run-main.js +59 -0
- package/node_modules/@ouro.bot/friends/dist/mcp/schemas.d.ts +10 -0
- package/node_modules/@ouro.bot/friends/dist/mcp/schemas.js +23 -0
- package/node_modules/@ouro.bot/friends/dist/mcp/server.d.ts +30 -0
- package/node_modules/@ouro.bot/friends/dist/mcp/server.js +195 -0
- package/node_modules/@ouro.bot/friends/dist/message.d.ts +93 -0
- package/node_modules/@ouro.bot/friends/dist/message.js +129 -0
- package/node_modules/@ouro.bot/friends/dist/mission-result.d.ts +89 -0
- package/node_modules/@ouro.bot/friends/dist/mission-result.js +207 -0
- package/node_modules/@ouro.bot/friends/dist/mission-share.d.ts +94 -0
- package/node_modules/@ouro.bot/friends/dist/mission-share.js +232 -0
- package/node_modules/@ouro.bot/friends/dist/mission-store-file.d.ts +18 -0
- package/node_modules/@ouro.bot/friends/dist/mission-store-file.js +169 -0
- package/node_modules/@ouro.bot/friends/dist/mission-store.d.ts +10 -0
- package/node_modules/@ouro.bot/friends/dist/mission-store.js +9 -0
- package/node_modules/@ouro.bot/friends/dist/missions.d.ts +31 -0
- package/node_modules/@ouro.bot/friends/dist/missions.js +99 -0
- package/node_modules/@ouro.bot/friends/dist/notes.d.ts +11 -0
- package/node_modules/@ouro.bot/friends/dist/notes.js +90 -0
- package/node_modules/@ouro.bot/friends/dist/observability.d.ts +27 -0
- package/node_modules/@ouro.bot/friends/dist/observability.js +31 -0
- package/node_modules/@ouro.bot/friends/dist/outcomes.d.ts +9 -0
- package/node_modules/@ouro.bot/friends/dist/outcomes.js +51 -0
- package/node_modules/@ouro.bot/friends/dist/resolver.d.ts +59 -0
- package/node_modules/@ouro.bot/friends/dist/resolver.js +276 -0
- package/node_modules/@ouro.bot/friends/dist/results.d.ts +10 -0
- package/node_modules/@ouro.bot/friends/dist/results.js +2 -0
- package/node_modules/@ouro.bot/friends/dist/room.d.ts +22 -0
- package/node_modules/@ouro.bot/friends/dist/room.js +40 -0
- package/node_modules/@ouro.bot/friends/dist/roster-store-file.d.ts +16 -0
- package/node_modules/@ouro.bot/friends/dist/roster-store-file.js +125 -0
- package/node_modules/@ouro.bot/friends/dist/roster-store-memory.d.ts +9 -0
- package/node_modules/@ouro.bot/friends/dist/roster-store-memory.js +20 -0
- package/node_modules/@ouro.bot/friends/dist/roster-store.d.ts +29 -0
- package/node_modules/@ouro.bot/friends/dist/roster-store.js +9 -0
- package/node_modules/@ouro.bot/friends/dist/roster-verifier.d.ts +23 -0
- package/node_modules/@ouro.bot/friends/dist/roster-verifier.js +47 -0
- package/node_modules/@ouro.bot/friends/dist/share.d.ts +113 -0
- package/node_modules/@ouro.bot/friends/dist/share.js +314 -0
- package/node_modules/@ouro.bot/friends/dist/standing.d.ts +83 -0
- package/node_modules/@ouro.bot/friends/dist/standing.js +111 -0
- package/node_modules/@ouro.bot/friends/dist/store-file.d.ts +82 -0
- package/node_modules/@ouro.bot/friends/dist/store-file.js +1089 -0
- package/node_modules/@ouro.bot/friends/dist/store.d.ts +43 -0
- package/node_modules/@ouro.bot/friends/dist/tokens.d.ts +10 -0
- package/{dist/mind/friends → node_modules/@ouro.bot/friends/dist}/tokens.js +7 -4
- package/node_modules/@ouro.bot/friends/dist/trust-explanation.d.ts +22 -0
- package/node_modules/@ouro.bot/friends/dist/trust-explanation.js +90 -0
- package/node_modules/@ouro.bot/friends/dist/trust-mutation.d.ts +16 -0
- package/node_modules/@ouro.bot/friends/dist/trust-mutation.js +67 -0
- package/node_modules/@ouro.bot/friends/dist/types.d.ts +333 -0
- package/node_modules/@ouro.bot/friends/dist/types.js +55 -0
- package/node_modules/@ouro.bot/friends/dist/util/cap-string.d.ts +7 -0
- package/node_modules/@ouro.bot/friends/dist/util/cap-string.js +35 -0
- package/node_modules/@ouro.bot/friends/dist/util/safe-id.d.ts +1 -0
- package/node_modules/@ouro.bot/friends/dist/util/safe-id.js +10 -0
- package/node_modules/@ouro.bot/friends/dist/verifier.d.ts +11 -0
- package/node_modules/@ouro.bot/friends/dist/verifier.js +29 -0
- package/node_modules/@ouro.bot/friends/dist/whoami.d.ts +7 -0
- package/node_modules/@ouro.bot/friends/dist/whoami.js +39 -0
- package/node_modules/@ouro.bot/friends/package.json +82 -0
- package/node_modules/libsodium/LICENSE +16 -0
- package/node_modules/libsodium/README.md +281 -0
- package/node_modules/libsodium/dist/modules/libsodium.js +1 -0
- package/node_modules/libsodium/dist/modules-esm/libsodium.mjs +1 -0
- package/node_modules/libsodium/package.json +54 -0
- package/node_modules/libsodium-wrappers/LICENSE +16 -0
- package/node_modules/libsodium-wrappers/README.md +281 -0
- package/node_modules/libsodium-wrappers/dist/modules/libsodium-wrappers.d.ts +2155 -0
- package/node_modules/libsodium-wrappers/dist/modules/libsodium-wrappers.js +1 -0
- package/node_modules/libsodium-wrappers/dist/modules-esm/libsodium-wrappers.d.mts +2743 -0
- package/node_modules/libsodium-wrappers/dist/modules-esm/libsodium-wrappers.mjs +1 -0
- package/node_modules/libsodium-wrappers/package.json +74 -0
- package/npm-shrinkwrap.json +8789 -0
- package/package.json +96 -12
- package/skills/agent-commerce.md +116 -0
- package/skills/browser-navigation.md +120 -0
- package/skills/commerce-setup-guide.md +116 -0
- package/skills/commerce-setup.md +87 -0
- package/skills/configure-dev-tools.md +32 -14
- package/skills/sense-setup.md +56 -0
- package/skills/travel-planning.md +141 -0
- package/vendor/desk/.claude-plugin/plugin.json +35 -0
- package/vendor/desk/.mcp.claude-codex.json +28 -0
- package/vendor/desk/.mcp.copilot.json +16 -0
- package/vendor/desk/.ouro-desk.json +6 -0
- package/vendor/desk/CHANGELOG.md +7004 -0
- package/vendor/desk/README.md +195 -0
- package/vendor/desk/activation/README.md +98 -0
- package/vendor/desk/activation/copilot-root.flattened-bundle.json +38 -0
- package/vendor/desk/activation/desk.activation.json +251 -0
- package/vendor/desk/activation/host-capability-evidence.md +46 -0
- package/vendor/desk/activation/support-matrix.json +84 -0
- package/vendor/desk/agency.json +20 -0
- package/vendor/desk/agents/observer.agent.md +26 -0
- package/vendor/desk/agents/observer.md +29 -0
- package/vendor/desk/agents/worker.agent.md +32 -0
- package/vendor/desk/agents/worker.md +40 -0
- package/vendor/desk/artifacts/tombstones/tombstone.schema.json +53 -0
- package/vendor/desk/artifacts/tombstones/tombstones.jsonl +1 -0
- package/vendor/desk/changelog.d/README.md +12 -0
- package/vendor/desk/docs/agent-files.md +104 -0
- package/vendor/desk/docs/agentic-engineering-v2-rfc.md +206 -0
- package/vendor/desk/docs/agentic-engineering-v3-rfc.md +109 -0
- package/vendor/desk/docs/browser-remote-desktops.md +69 -0
- package/vendor/desk/docs/dependency-activation-stories-and-criteria.md +500 -0
- package/vendor/desk/docs/evaluation-packet.md +363 -0
- package/vendor/desk/docs/factory-local-capture.md +651 -0
- package/vendor/desk/docs/factory-store-playbook.md +927 -0
- package/vendor/desk/docs/images/factory-site.png +0 -0
- package/vendor/desk/docs/issue-drains.md +79 -0
- package/vendor/desk/docs/lfs-inspection.md +55 -0
- package/vendor/desk/docs/preview-diagnostics.md +11 -0
- package/vendor/desk/docs/relays.md +88 -0
- package/vendor/desk/docs/schedules.md +69 -0
- package/vendor/desk/docs/search-recovery.md +22 -0
- package/vendor/desk/docs/session-labels.md +157 -0
- package/vendor/desk/docs/session-retention.md +125 -0
- package/vendor/desk/docs/sessions.md +17 -0
- package/vendor/desk/docs/stalled-nudges.md +54 -0
- package/vendor/desk/docs/webhooks.md +80 -0
- package/vendor/desk/docs/workspace-tidy.md +74 -0
- package/vendor/desk/hooks/boot-checks.cjs +7 -0
- package/vendor/desk/hooks/claude-session-start.cjs +123 -0
- package/vendor/desk/hooks/compatible-node.cjs +97 -0
- package/vendor/desk/hooks/copilot-boot-prompt.cjs +69 -0
- package/vendor/desk/hooks/copilot-durable-files.cjs +8 -0
- package/vendor/desk/hooks/copilot-hooks.json +61 -0
- package/vendor/desk/hooks/copilot-intake-context.cjs +5 -0
- package/vendor/desk/hooks/copilot-lane-model.cjs +8 -0
- package/vendor/desk/hooks/copilot-session-start.cjs +264 -0
- package/vendor/desk/hooks/copilot-skill-current.cjs +28 -0
- package/vendor/desk/hooks/factory-end.cjs +5 -0
- package/vendor/desk/hooks/factory-start.cjs +27 -0
- package/vendor/desk/hooks/hooks.json +40 -0
- package/vendor/desk/hooks/lib/boot-checks.cjs +643 -0
- package/vendor/desk/hooks/lib/child-agent.cjs +14 -0
- package/vendor/desk/hooks/lib/copilot-intake-context.cjs +73 -0
- package/vendor/desk/hooks/lib/current-release.cjs +162 -0
- package/vendor/desk/hooks/lib/delivery-stop.cjs +326 -0
- package/vendor/desk/hooks/lib/detach-worker.cjs +43 -0
- package/vendor/desk/hooks/lib/durable-files.cjs +102 -0
- package/vendor/desk/hooks/lib/factory-end.cjs +327 -0
- package/vendor/desk/hooks/lib/lane-model.cjs +82 -0
- package/vendor/desk/hooks/lib/node-required.cjs +56 -0
- package/vendor/desk/hooks/lib/orca-session-title.cjs +60 -0
- package/vendor/desk/hooks/lib/session-end.cjs +30 -0
- package/vendor/desk/hooks/lib/sync-end.cjs +89 -0
- package/vendor/desk/hooks/loop-start.cjs +105 -0
- package/vendor/desk/hooks/node-missing.sh +78 -0
- package/vendor/desk/hooks/orca-session-title.cjs +8 -0
- package/vendor/desk/hooks/session-end.cjs +8 -0
- package/vendor/desk/mcp/README.md +269 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/darwin-arm64-node-127/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/darwin-arm64-node-127/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/darwin-arm64-node-127/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/darwin-arm64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/darwin-arm64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/darwin-arm64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-127/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-127/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-127/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-147/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-147/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/linux-x64-node-147/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/support-matrix.json +72 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/win32-x64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/win32-x64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/win32-x64-node-137/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/win32-x64-node-147/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.manifest.json +881 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/win32-x64-node-147/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.sha256 +1 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/1.4.0-alpha.6/win32-x64-node-147/3b0cb8b1e7dd77a982b38375fe88a5278bd77974213e18be025d7dc8deea800f/runtime-deps.tgz +0 -0
- package/vendor/desk/mcp/artifacts/runtime-deps/README.md +25 -0
- package/vendor/desk/mcp/bootstrap.cjs +761 -0
- package/vendor/desk/mcp/docs/private-feedback.md +13 -0
- package/vendor/desk/mcp/idle-proxy.cjs +423 -0
- package/vendor/desk/mcp/index.js +813 -0
- package/vendor/desk/mcp/package-lock.json +3717 -0
- package/vendor/desk/mcp/package.json +44 -0
- package/vendor/desk/mcp/scripts/agency-desk-channel.js +7 -0
- package/vendor/desk/mcp/scripts/build-runtime-deps-pack.js +5 -0
- package/vendor/desk/mcp/scripts/crew.js +89 -0
- package/vendor/desk/mcp/scripts/drains-launcher.mjs +329 -0
- package/vendor/desk/mcp/scripts/drains.js +5 -0
- package/vendor/desk/mcp/scripts/factory.js +657 -0
- package/vendor/desk/mcp/scripts/file-desk-problem.js +9 -0
- package/vendor/desk/mcp/scripts/finish-commit.js +7 -0
- package/vendor/desk/mcp/scripts/lfs.js +37 -0
- package/vendor/desk/mcp/scripts/local-recovery.js +363 -0
- package/vendor/desk/mcp/scripts/migrations.js +11 -0
- package/vendor/desk/mcp/scripts/private-view.js +177 -0
- package/vendor/desk/mcp/scripts/resolve-desk-root.js +106 -0
- package/vendor/desk/mcp/scripts/session-boot.js +22 -0
- package/vendor/desk/mcp/scripts/session-retention.js +5 -0
- package/vendor/desk/mcp/scripts/session-sync.js +10 -0
- package/vendor/desk/mcp/scripts/sessions.js +5 -0
- package/vendor/desk/mcp/scripts/sync-push.js +13 -0
- package/vendor/desk/mcp/scripts/tidy-status.js +8 -0
- package/vendor/desk/mcp/scripts/verify-runtime-deps-pack.js +5 -0
- package/vendor/desk/mcp/src/actions/desk-read.actions.mts +73 -0
- package/vendor/desk/mcp/src/actions/desk-session.actions.mts +42 -0
- package/vendor/desk/mcp/src/actions/desk-web.actions.mts +52 -0
- package/vendor/desk/mcp/src/actions/desk.actions.mts +5 -0
- package/vendor/desk/mcp/src/actions/generated/desk/OuroActions.swift +649 -0
- package/vendor/desk/mcp/src/actions/generated/desk/OuroActionsReins.swift +61 -0
- package/vendor/desk/mcp/src/actions/generated/desk/actions.json +280 -0
- package/vendor/desk/mcp/src/actions/generated/desk/commands.json +145 -0
- package/vendor/desk/mcp/src/actions/generated/desk/mcp.json +256 -0
- package/vendor/desk/mcp/src/actions/generated/desk/web.ts +59 -0
- package/vendor/desk/mcp/src/actions/generated/desk/webmcp.json +250 -0
- package/vendor/desk/mcp/src/actions/generated/desk-web/OuroActions.swift +241 -0
- package/vendor/desk/mcp/src/actions/generated/desk-web/OuroActionsReins.swift +25 -0
- package/vendor/desk/mcp/src/actions/generated/desk-web/actions.json +73 -0
- package/vendor/desk/mcp/src/actions/generated/desk-web/commands.json +53 -0
- package/vendor/desk/mcp/src/actions/generated/desk-web/mcp.json +83 -0
- package/vendor/desk/mcp/src/actions/generated/desk-web/web.ts +47 -0
- package/vendor/desk/mcp/src/actions/generated/desk-web/webmcp.json +81 -0
- package/vendor/desk/mcp/src/actions/served.js +5 -0
- package/vendor/desk/mcp/src/activation/admit.js +77 -0
- package/vendor/desk/mcp/src/activation/failures.js +65 -0
- package/vendor/desk/mcp/src/activation/readiness-policy.js +102 -0
- package/vendor/desk/mcp/src/activation/schema.js +17 -0
- package/vendor/desk/mcp/src/activation/superpowers-context.js +265 -0
- package/vendor/desk/mcp/src/activation/validate.js +540 -0
- package/vendor/desk/mcp/src/artifacts/tombstones.js +61 -0
- package/vendor/desk/mcp/src/crew/initiative.js +287 -0
- package/vendor/desk/mcp/src/crew/workspace.js +1259 -0
- package/vendor/desk/mcp/src/db/init.js +75 -0
- package/vendor/desk/mcp/src/db/schema.sql +83 -0
- package/vendor/desk/mcp/src/desk/active-tasks.js +408 -0
- package/vendor/desk/mcp/src/desk/card-commit-guard.js +281 -0
- package/vendor/desk/mcp/src/desk/cleanup-index.js +53 -0
- package/vendor/desk/mcp/src/desk/content-home.js +246 -0
- package/vendor/desk/mcp/src/desk/crew-config.js +102 -0
- package/vendor/desk/mcp/src/desk/crew-member.js +196 -0
- package/vendor/desk/mcp/src/desk/crew-roster.js +151 -0
- package/vendor/desk/mcp/src/desk/frontmatter-lite.js +228 -0
- package/vendor/desk/mcp/src/desk/gh-logins.js +109 -0
- package/vendor/desk/mcp/src/desk/handles.js +123 -0
- package/vendor/desk/mcp/src/desk/handoff-reference.js +35 -0
- package/vendor/desk/mcp/src/desk/improvement-authority.js +3 -0
- package/vendor/desk/mcp/src/desk/improvement-cards.js +704 -0
- package/vendor/desk/mcp/src/desk/improvement-person.js +51 -0
- package/vendor/desk/mcp/src/desk/lifecycle.js +16 -0
- package/vendor/desk/mcp/src/desk/machine-desks.js +119 -0
- package/vendor/desk/mcp/src/desk/naming.js +333 -0
- package/vendor/desk/mcp/src/desk/organization.js +592 -0
- package/vendor/desk/mcp/src/desk/resources.js +274 -0
- package/vendor/desk/mcp/src/desk/runtime-resolver.js +30 -0
- package/vendor/desk/mcp/src/desk/scratch-paths.js +44 -0
- package/vendor/desk/mcp/src/desk/step-delivery.js +140 -0
- package/vendor/desk/mcp/src/desk/steps.js +263 -0
- package/vendor/desk/mcp/src/desk/tidy.js +930 -0
- package/vendor/desk/mcp/src/desk/unsigned-deliveries.js +359 -0
- package/vendor/desk/mcp/src/factory/agent-types.js +45 -0
- package/vendor/desk/mcp/src/factory/andon-watch.js +109 -0
- package/vendor/desk/mcp/src/factory/binding.js +612 -0
- package/vendor/desk/mcp/src/factory/boot-check.js +645 -0
- package/vendor/desk/mcp/src/factory/capture-classify.js +158 -0
- package/vendor/desk/mcp/src/factory/capture-count.js +183 -0
- package/vendor/desk/mcp/src/factory/capture-flush.js +268 -0
- package/vendor/desk/mcp/src/factory/capture-publish.js +141 -0
- package/vendor/desk/mcp/src/factory/capture-schema.js +193 -0
- package/vendor/desk/mcp/src/factory/capture-sweep.js +239 -0
- package/vendor/desk/mcp/src/factory/catch-point.js +60 -0
- package/vendor/desk/mcp/src/factory/commit-resolve.js +94 -0
- package/vendor/desk/mcp/src/factory/consent-answer.js +37 -0
- package/vendor/desk/mcp/src/factory/context-capability.js +15 -0
- package/vendor/desk/mcp/src/factory/context-outbox.js +885 -0
- package/vendor/desk/mcp/src/factory/context-run.js +386 -0
- package/vendor/desk/mcp/src/factory/context-schema.js +249 -0
- package/vendor/desk/mcp/src/factory/copilot-turn-index.js +93 -0
- package/vendor/desk/mcp/src/factory/copilot-usage.js +148 -0
- package/vendor/desk/mcp/src/factory/credential.js +45 -0
- package/vendor/desk/mcp/src/factory/derive-claude.js +960 -0
- package/vendor/desk/mcp/src/factory/derive-codex.js +734 -0
- package/vendor/desk/mcp/src/factory/derive-common.js +279 -0
- package/vendor/desk/mcp/src/factory/derive-copilot.js +1057 -0
- package/vendor/desk/mcp/src/factory/derive-run.js +807 -0
- package/vendor/desk/mcp/src/factory/desk-problem-file.js +310 -0
- package/vendor/desk/mcp/src/factory/desk-problem-fingerprint.js +70 -0
- package/vendor/desk/mcp/src/factory/desk-problem-known.js +246 -0
- package/vendor/desk/mcp/src/factory/desk-problem-template.js +107 -0
- package/vendor/desk/mcp/src/factory/desk-repo.js +1223 -0
- package/vendor/desk/mcp/src/factory/desk-task-line.js +28 -0
- package/vendor/desk/mcp/src/factory/desk-visibility.js +48 -0
- package/vendor/desk/mcp/src/factory/end-hook.js +14 -0
- package/vendor/desk/mcp/src/factory/evaluate-kick.js +164 -0
- package/vendor/desk/mcp/src/factory/evaluate-run.js +678 -0
- package/vendor/desk/mcp/src/factory/evaluator-step.js +484 -0
- package/vendor/desk/mcp/src/factory/filer-launch.js +79 -0
- package/vendor/desk/mcp/src/factory/flush-health.js +26 -0
- package/vendor/desk/mcp/src/factory/flush.js +1758 -0
- package/vendor/desk/mcp/src/factory/focus.js +326 -0
- package/vendor/desk/mcp/src/factory/headless-flag.cjs +32 -0
- package/vendor/desk/mcp/src/factory/headless-flag.js +25 -0
- package/vendor/desk/mcp/src/factory/headless-ledger.js +743 -0
- package/vendor/desk/mcp/src/factory/headless.js +567 -0
- package/vendor/desk/mcp/src/factory/held-route.js +93 -0
- package/vendor/desk/mcp/src/factory/host-flags.js +36 -0
- package/vendor/desk/mcp/src/factory/improvement-verify.js +429 -0
- package/vendor/desk/mcp/src/factory/kaizen-file.js +231 -0
- package/vendor/desk/mcp/src/factory/label-binding.js +90 -0
- package/vendor/desk/mcp/src/factory/label-schema.js +426 -0
- package/vendor/desk/mcp/src/factory/local-status.js +368 -0
- package/vendor/desk/mcp/src/factory/loop-conditions.js +121 -0
- package/vendor/desk/mcp/src/factory/loop-health.js +500 -0
- package/vendor/desk/mcp/src/factory/loop-slot.js +90 -0
- package/vendor/desk/mcp/src/factory/loop-status.js +100 -0
- package/vendor/desk/mcp/src/factory/loop-switch.cjs +14 -0
- package/vendor/desk/mcp/src/factory/loop-worker-state.js +96 -0
- package/vendor/desk/mcp/src/factory/loop-worker.js +290 -0
- package/vendor/desk/mcp/src/factory/marker.js +61 -0
- package/vendor/desk/mcp/src/factory/mirror-step.js +145 -0
- package/vendor/desk/mcp/src/factory/os-protect.js +243 -0
- package/vendor/desk/mcp/src/factory/outbox.js +2231 -0
- package/vendor/desk/mcp/src/factory/outcome.js +431 -0
- package/vendor/desk/mcp/src/factory/pipeline/andon.js +319 -0
- package/vendor/desk/mcp/src/factory/pipeline/attention-rollup.js +158 -0
- package/vendor/desk/mcp/src/factory/pipeline/attention.js +146 -0
- package/vendor/desk/mcp/src/factory/pipeline/build.js +299 -0
- package/vendor/desk/mcp/src/factory/pipeline/compare.js +148 -0
- package/vendor/desk/mcp/src/factory/pipeline/formulas.js +652 -0
- package/vendor/desk/mcp/src/factory/pipeline/kaizen.js +387 -0
- package/vendor/desk/mcp/src/factory/pipeline/lifecycle-clocks.js +345 -0
- package/vendor/desk/mcp/src/factory/pipeline/normalize.js +73 -0
- package/vendor/desk/mcp/src/factory/pipeline/number-states.js +154 -0
- package/vendor/desk/mcp/src/factory/pipeline/outcomes.js +268 -0
- package/vendor/desk/mcp/src/factory/pipeline/report.js +737 -0
- package/vendor/desk/mcp/src/factory/pipeline/rollups.js +883 -0
- package/vendor/desk/mcp/src/factory/pipeline/stretches.js +523 -0
- package/vendor/desk/mcp/src/factory/pipeline/timeline.js +199 -0
- package/vendor/desk/mcp/src/factory/pipeline/validate-pr.js +238 -0
- package/vendor/desk/mcp/src/factory/pipeline/versions.js +42 -0
- package/vendor/desk/mcp/src/factory/pipeline/walk.js +1177 -0
- package/vendor/desk/mcp/src/factory/plugin-registry.js +72 -0
- package/vendor/desk/mcp/src/factory/plugin-sources.cjs +249 -0
- package/vendor/desk/mcp/src/factory/pr-green.js +77 -0
- package/vendor/desk/mcp/src/factory/process-lock.js +142 -0
- package/vendor/desk/mcp/src/factory/proof-session.js +75 -0
- package/vendor/desk/mcp/src/factory/publish.js +637 -0
- package/vendor/desk/mcp/src/factory/published-schema.js +648 -0
- package/vendor/desk/mcp/src/factory/reconcile-reasons.js +22 -0
- package/vendor/desk/mcp/src/factory/reconcile-step.js +251 -0
- package/vendor/desk/mcp/src/factory/reconcile.js +808 -0
- package/vendor/desk/mcp/src/factory/release-version.js +134 -0
- package/vendor/desk/mcp/src/factory/repo-name.js +13 -0
- package/vendor/desk/mcp/src/factory/retention.js +60 -0
- package/vendor/desk/mcp/src/factory/route-desk.js +40 -0
- package/vendor/desk/mcp/src/factory/route-issues.js +251 -0
- package/vendor/desk/mcp/src/factory/route-local.js +264 -0
- package/vendor/desk/mcp/src/factory/schema.js +957 -0
- package/vendor/desk/mcp/src/factory/session-kind.js +16 -0
- package/vendor/desk/mcp/src/factory/session-lifetime.js +56 -0
- package/vendor/desk/mcp/src/factory/session-route.js +183 -0
- package/vendor/desk/mcp/src/factory/shell-git.js +500 -0
- package/vendor/desk/mcp/src/factory/store-issues.js +143 -0
- package/vendor/desk/mcp/src/factory/store-route.js +208 -0
- package/vendor/desk/mcp/src/factory/test-state-guard.js +103 -0
- package/vendor/desk/mcp/src/factory/time.js +36 -0
- package/vendor/desk/mcp/src/factory/tool-issue-file.js +84 -0
- package/vendor/desk/mcp/src/factory/tool-kinds.js +87 -0
- package/vendor/desk/mcp/src/factory/triage-schema.js +233 -0
- package/vendor/desk/mcp/src/factory/windows-acl.js +679 -0
- package/vendor/desk/mcp/src/indexer/chunk.js +232 -0
- package/vendor/desk/mcp/src/indexer/discover.js +434 -0
- package/vendor/desk/mcp/src/indexer/exclusions.js +247 -0
- package/vendor/desk/mcp/src/indexer/index.js +167 -0
- package/vendor/desk/mcp/src/indexer/refs.js +0 -0
- package/vendor/desk/mcp/src/indexer/text-hash.js +18 -0
- package/vendor/desk/mcp/src/lib/ouro-actions/actions.claims.json +75 -0
- package/vendor/desk/mcp/src/lib/ouro-actions/dist-manifest.json +70 -0
- package/vendor/desk/mcp/src/lib/ouro-actions/ouro-actions.mts +1416 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/LICENSE +21 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/ax-claims.ts +190 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/ax-command.ts +1020 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/checks.ts +343 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/cli.ts +240 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/component.ts +430 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/dev-commands.ts +204 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/doctor.ts +126 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/effects.ts +68 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/exit-codes.ts +75 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/help.ts +220 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/mcp.ts +268 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/outcome.ts +265 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/output.ts +67 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/precise-copy.ts +235 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/problem.ts +124 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/surfaces.kit.mts +8 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/surfaces.ts +568 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/terminal.ts +245 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/voice.ts +136 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/wait.ts +226 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/work-event.ts +181 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/xray.kit.mts +18 -0
- package/vendor/desk/mcp/src/lib/ouro-ui/registry/ouro/ax/xray.ts +2072 -0
- package/vendor/desk/mcp/src/package-metadata.js +20 -0
- package/vendor/desk/mcp/src/protected/legacy-ledger.js +55 -0
- package/vendor/desk/mcp/src/readiness/leftovers.js +75 -0
- package/vendor/desk/mcp/src/readiness/process-start.js +149 -0
- package/vendor/desk/mcp/src/runtime/admission-worker.js +194 -0
- package/vendor/desk/mcp/src/runtime/admission.js +177 -0
- package/vendor/desk/mcp/src/runtime/agency-desk-channel.js +342 -0
- package/vendor/desk/mcp/src/runtime/agents-md.js +62 -0
- package/vendor/desk/mcp/src/runtime/append-lane.js +68 -0
- package/vendor/desk/mcp/src/runtime/argv-safe-reason.js +55 -0
- package/vendor/desk/mcp/src/runtime/boot-dependencies.js +75 -0
- package/vendor/desk/mcp/src/runtime/boot-text.js +504 -0
- package/vendor/desk/mcp/src/runtime/boot.js +1677 -0
- package/vendor/desk/mcp/src/runtime/bootstrap.js +1455 -0
- package/vendor/desk/mcp/src/runtime/chunked-import.js +102 -0
- package/vendor/desk/mcp/src/runtime/copilot-commit-trailer.js +133 -0
- package/vendor/desk/mcp/src/runtime/copilot-session.js +155 -0
- package/vendor/desk/mcp/src/runtime/deliver.js +469 -0
- package/vendor/desk/mcp/src/runtime/desk-channel.js +86 -0
- package/vendor/desk/mcp/src/runtime/desk-failure.js +26 -0
- package/vendor/desk/mcp/src/runtime/desk-health.js +168 -0
- package/vendor/desk/mcp/src/runtime/desk-session.js +1451 -0
- package/vendor/desk/mcp/src/runtime/diagnostic-server.js +72 -0
- package/vendor/desk/mcp/src/runtime/diagnostics.js +241 -0
- package/vendor/desk/mcp/src/runtime/drains-cli.js +187 -0
- package/vendor/desk/mcp/src/runtime/drains.js +781 -0
- package/vendor/desk/mcp/src/runtime/elsewhere-note.js +9 -0
- package/vendor/desk/mcp/src/runtime/failure-evidence.js +21 -0
- package/vendor/desk/mcp/src/runtime/fast-refs.js +209 -0
- package/vendor/desk/mcp/src/runtime/filer-throttle.js +66 -0
- package/vendor/desk/mcp/src/runtime/focused-card.js +147 -0
- package/vendor/desk/mcp/src/runtime/front-door.js +204 -0
- package/vendor/desk/mcp/src/runtime/gate-wait.js +2 -0
- package/vendor/desk/mcp/src/runtime/git-inspection.js +201 -0
- package/vendor/desk/mcp/src/runtime/git-read-worker.js +157 -0
- package/vendor/desk/mcp/src/runtime/health.js +50 -0
- package/vendor/desk/mcp/src/runtime/hooks.js +353 -0
- package/vendor/desk/mcp/src/runtime/hosted.js +163 -0
- package/vendor/desk/mcp/src/runtime/inbox.js +102 -0
- package/vendor/desk/mcp/src/runtime/index-drift.js +118 -0
- package/vendor/desk/mcp/src/runtime/last-start.js +133 -0
- package/vendor/desk/mcp/src/runtime/lesson-section.js +92 -0
- package/vendor/desk/mcp/src/runtime/lessons-shelf.js +100 -0
- package/vendor/desk/mcp/src/runtime/lfs.js +319 -0
- package/vendor/desk/mcp/src/runtime/native-path.js +12 -0
- package/vendor/desk/mcp/src/runtime/newest-release.js +197 -0
- package/vendor/desk/mcp/src/runtime/node-selection.js +233 -0
- package/vendor/desk/mcp/src/runtime/orca-session-title.js +225 -0
- package/vendor/desk/mcp/src/runtime/other-sessions.js +183 -0
- package/vendor/desk/mcp/src/runtime/pending-migrations.js +653 -0
- package/vendor/desk/mcp/src/runtime/plugin-update.js +215 -0
- package/vendor/desk/mcp/src/runtime/pluginless-runtimes.js +34 -0
- package/vendor/desk/mcp/src/runtime/pr-publication.js +226 -0
- package/vendor/desk/mcp/src/runtime/preview-snapshot.js +23 -0
- package/vendor/desk/mcp/src/runtime/publication-mode.js +19 -0
- package/vendor/desk/mcp/src/runtime/relays.js +974 -0
- package/vendor/desk/mcp/src/runtime/release-alert.js +148 -0
- package/vendor/desk/mcp/src/runtime/remote-identity.js +140 -0
- package/vendor/desk/mcp/src/runtime/resolve-here.js +4 -0
- package/vendor/desk/mcp/src/runtime/runtime-deps-cli.js +65 -0
- package/vendor/desk/mcp/src/runtime/runtime-deps.js +1109 -0
- package/vendor/desk/mcp/src/runtime/runtime-identity.js +22 -0
- package/vendor/desk/mcp/src/runtime/runtime-swap.js +101 -0
- package/vendor/desk/mcp/src/runtime/schedules.js +235 -0
- package/vendor/desk/mcp/src/runtime/session-activity.js +190 -0
- package/vendor/desk/mcp/src/runtime/session-label.js +30 -0
- package/vendor/desk/mcp/src/runtime/session-retention.js +662 -0
- package/vendor/desk/mcp/src/runtime/session-sync.js +333 -0
- package/vendor/desk/mcp/src/runtime/session-trailer.js +126 -0
- package/vendor/desk/mcp/src/runtime/sessions-cli.js +301 -0
- package/vendor/desk/mcp/src/runtime/signoff-listed.js +81 -0
- package/vendor/desk/mcp/src/runtime/skills.js +76 -0
- package/vendor/desk/mcp/src/runtime/stale-card-lead.js +52 -0
- package/vendor/desk/mcp/src/runtime/stale-desk-refresh.js +198 -0
- package/vendor/desk/mcp/src/runtime/stale-desk.js +219 -0
- package/vendor/desk/mcp/src/runtime/stalled.js +255 -0
- package/vendor/desk/mcp/src/runtime/standing-authority.js +79 -0
- package/vendor/desk/mcp/src/runtime/startup-boot.js +341 -0
- package/vendor/desk/mcp/src/runtime/startup-resolve.js +140 -0
- package/vendor/desk/mcp/src/runtime/state-branch.js +203 -0
- package/vendor/desk/mcp/src/runtime/status-compact.js +165 -0
- package/vendor/desk/mcp/src/runtime/status-inspection-child.js +26 -0
- package/vendor/desk/mcp/src/runtime/status-inspection.js +147 -0
- package/vendor/desk/mcp/src/runtime/status-root.js +39 -0
- package/vendor/desk/mcp/src/runtime/sync-worker.js +911 -0
- package/vendor/desk/mcp/src/runtime/test-state-guard.js +107 -0
- package/vendor/desk/mcp/src/runtime/unmerged-saves.js +247 -0
- package/vendor/desk/mcp/src/runtime/workspace-claim.js +53 -0
- package/vendor/desk/mcp/src/runtime/workspace-evidence.js +96 -0
- package/vendor/desk/mcp/src/runtime/workspace-tidy.js +509 -0
- package/vendor/desk/mcp/src/search/direct-lexical.js +54 -0
- package/vendor/desk/mcp/src/search/embedder.js +108 -0
- package/vendor/desk/mcp/src/search/engine.js +406 -0
- package/vendor/desk/mcp/src/search/files-router.js +22 -0
- package/vendor/desk/mcp/src/search/old-index.js +46 -0
- package/vendor/desk/mcp/src/search/vectors.js +60 -0
- package/vendor/desk/mcp/src/server.js +389 -0
- package/vendor/desk/mcp/src/tool-names.js +73 -0
- package/vendor/desk/mcp/src/tool-refusal.cjs +35 -0
- package/vendor/desk/mcp/src/tool-schema-parts.js +12 -0
- package/vendor/desk/mcp/src/tool-schemas.js +325 -0
- package/vendor/desk/mcp/src/tools/_card-commit.js +148 -0
- package/vendor/desk/mcp/src/tools/archive-links.js +185 -0
- package/vendor/desk/mcp/src/tools/archive-move.js +18 -0
- package/vendor/desk/mcp/src/tools/archive-native-session.js +728 -0
- package/vendor/desk/mcp/src/tools/archive-state.js +513 -0
- package/vendor/desk/mcp/src/tools/delivery-gate.js +251 -0
- package/vendor/desk/mcp/src/tools/desk-save.js +444 -0
- package/vendor/desk/mcp/src/tools/doctor.js +122 -0
- package/vendor/desk/mcp/src/tools/done-evidence.js +260 -0
- package/vendor/desk/mcp/src/tools/factory-context.js +204 -0
- package/vendor/desk/mcp/src/tools/friction.js +332 -0
- package/vendor/desk/mcp/src/tools/improvement.js +156 -0
- package/vendor/desk/mcp/src/tools/lesson-lines.js +22 -0
- package/vendor/desk/mcp/src/tools/lesson-owners.js +137 -0
- package/vendor/desk/mcp/src/tools/lesson-team.js +169 -0
- package/vendor/desk/mcp/src/tools/lesson.js +254 -0
- package/vendor/desk/mcp/src/tools/local-only.js +151 -0
- package/vendor/desk/mcp/src/tools/move.js +794 -0
- package/vendor/desk/mcp/src/tools/native-stage-context.js +32 -0
- package/vendor/desk/mcp/src/tools/note.js +267 -0
- package/vendor/desk/mcp/src/tools/search.js +634 -0
- package/vendor/desk/mcp/src/tools/shared-write.js +196 -0
- package/vendor/desk/mcp/src/tools/sibling-desk.js +37 -0
- package/vendor/desk/mcp/src/tools/status.js +233 -0
- package/vendor/desk/mcp/src/tools/task-archive-due.js +9 -0
- package/vendor/desk/mcp/src/tools/task-archived-resource.js +53 -0
- package/vendor/desk/mcp/src/tools/task-body.js +141 -0
- package/vendor/desk/mcp/src/tools/task-focus.js +164 -0
- package/vendor/desk/mcp/src/tools/task-log.js +76 -0
- package/vendor/desk/mcp/src/tools/task-signoff.js +155 -0
- package/vendor/desk/mcp/src/tools/task.js +1768 -0
- package/vendor/desk/mcp/src/tools/track-row.js +89 -0
- package/vendor/desk/mcp/src/tools/track.js +240 -0
- package/vendor/desk/mcp/src/util/agency-session.cjs +29 -0
- package/vendor/desk/mcp/src/util/archive-links.js +105 -0
- package/vendor/desk/mcp/src/util/bash.js +36 -0
- package/vendor/desk/mcp/src/util/capture-record.js +73 -0
- package/vendor/desk/mcp/src/util/cas-commit.js +252 -0
- package/vendor/desk/mcp/src/util/created-dirs.js +71 -0
- package/vendor/desk/mcp/src/util/deferred-tools.js +51 -0
- package/vendor/desk/mcp/src/util/desk-owner.js +99 -0
- package/vendor/desk/mcp/src/util/env-value.js +13 -0
- package/vendor/desk/mcp/src/util/file-identity.js +40 -0
- package/vendor/desk/mcp/src/util/finish-commit.js +145 -0
- package/vendor/desk/mcp/src/util/fm.js +410 -0
- package/vendor/desk/mcp/src/util/git-config-file.js +85 -0
- package/vendor/desk/mcp/src/util/git-stage.js +440 -0
- package/vendor/desk/mcp/src/util/main-publish.js +240 -0
- package/vendor/desk/mcp/src/util/markdown-links.cjs +555 -0
- package/vendor/desk/mcp/src/util/object-input.js +59 -0
- package/vendor/desk/mcp/src/util/paths.js +647 -0
- package/vendor/desk/mcp/src/util/rank.js +189 -0
- package/vendor/desk/mcp/src/util/redact.js +92 -0
- package/vendor/desk/mcp/src/util/remove-retry.js +35 -0
- package/vendor/desk/mcp/src/util/rename-retry.js +73 -0
- package/vendor/desk/mcp/src/util/route-around.js +265 -0
- package/vendor/desk/mcp/src/util/shell-quote.js +18 -0
- package/vendor/desk/mcp/src/util/startup-direction.js +124 -0
- package/vendor/desk/mcp/src/util/state-ignore.js +33 -0
- package/vendor/desk/mcp/src/util/tool-commits.js +64 -0
- package/vendor/desk/mcp/src/util/unicode-16/LICENSE-MIT.txt +7 -0
- package/vendor/desk/mcp/src/util/unicode-16/README.md +9 -0
- package/vendor/desk/mcp/src/util/unicode-16/letter.cjs +1 -0
- package/vendor/desk/mcp/src/util/unicode-16/mark.cjs +1 -0
- package/vendor/desk/mcp/src/util/unicode-16/number.cjs +1 -0
- package/vendor/desk/mcp/web-auth.cjs +1897 -0
- package/vendor/desk/mcp/web-browser-discovery.cjs +53 -0
- package/vendor/desk/mcp/web-catalog.json +34 -0
- package/vendor/desk/mcp/web-launch.cjs +101 -0
- package/vendor/desk/mcp/web.cjs +1239 -0
- package/vendor/desk/migrations/01-move-to-ourostack-desk.md +188 -0
- package/vendor/desk/migrations/02-tidy-desk.md +87 -0
- package/vendor/desk/migrations/03-desk-release-channel.md +38 -0
- package/vendor/desk/optional/session-label/consumer.mjs +237 -0
- package/vendor/desk/optional/session-label/extension.mjs +32 -0
- package/vendor/desk/plugin.json +54 -0
- package/vendor/desk/settings.json +3 -0
- package/vendor/desk/skills/add-workspace-mcp/SKILL.md +180 -0
- package/vendor/desk/skills/adopt-inflight-work/SKILL.md +212 -0
- package/vendor/desk/skills/archive-workflow/SKILL.md +132 -0
- package/vendor/desk/skills/content-routing/SKILL.md +95 -0
- package/vendor/desk/skills/core-meeting-capture/SKILL.md +47 -0
- package/vendor/desk/skills/core-meeting-capture/references/capture-contract.md +175 -0
- package/vendor/desk/skills/curator/SKILL.md +103 -0
- package/vendor/desk/skills/delightful-decks/SKILL.md +67 -0
- package/vendor/desk/skills/desk-problem/SKILL.md +87 -0
- package/vendor/desk/skills/directory-structure/SKILL.md +169 -0
- package/vendor/desk/skills/doc-review-rigor/SKILL.md +63 -0
- package/vendor/desk/skills/draining-issues/SKILL.md +62 -0
- package/vendor/desk/skills/evaluate-release/SKILL.md +96 -0
- package/vendor/desk/skills/evidence-discipline/SKILL.md +150 -0
- package/vendor/desk/skills/factory-evaluator/SKILL.md +122 -0
- package/vendor/desk/skills/factory-task-context/SKILL.md +116 -0
- package/vendor/desk/skills/factory-work/SKILL.md +16 -0
- package/vendor/desk/skills/fast-honest-ci/SKILL.md +70 -0
- package/vendor/desk/skills/fast-honest-ci/examples.md +49 -0
- package/vendor/desk/skills/first-run-bootstrap/SKILL.md +95 -0
- package/vendor/desk/skills/friction-management/SKILL.md +98 -0
- package/vendor/desk/skills/git-hygiene/SKILL.md +253 -0
- package/vendor/desk/skills/independent-review/SKILL.md +34 -0
- package/vendor/desk/skills/interaction-style/SKILL.md +239 -0
- package/vendor/desk/skills/lesson-capture/SKILL.md +85 -0
- package/vendor/desk/skills/lesson-capture/agents-md-budget.mjs +61 -0
- package/vendor/desk/skills/online-evaluation/SKILL.md +81 -0
- package/vendor/desk/skills/operator-voice-comments/LICENSE-humanize +21 -0
- package/vendor/desk/skills/operator-voice-comments/SKILL.md +90 -0
- package/vendor/desk/skills/operator-voice-comments/human-voice.md +43 -0
- package/vendor/desk/skills/peer-pr-review/SKILL.md +104 -0
- package/vendor/desk/skills/pr-feedback-on-own-pr/SKILL.md +145 -0
- package/vendor/desk/skills/pr-review-interrogation/SKILL.md +121 -0
- package/vendor/desk/skills/pr-reviewer-audit/SKILL.md +68 -0
- package/vendor/desk/skills/pr-reviewer-audit/helpers/audit.py +335 -0
- package/vendor/desk/skills/pr-reviewer-audit/helpers/test_audit.py +486 -0
- package/vendor/desk/skills/pr-self-review/SKILL.md +86 -0
- package/vendor/desk/skills/pr-surface-hygiene/SKILL.md +105 -0
- package/vendor/desk/skills/pr-surface-hygiene/check-visual-proof.cjs +99 -0
- package/vendor/desk/skills/pr-surface-hygiene/repository-setup.md +19 -0
- package/vendor/desk/skills/pr-surface-hygiene/resources/pr-visual-proof.yml +29 -0
- package/vendor/desk/skills/pr-surface-hygiene/resources/pull-request-template.md +5 -0
- package/vendor/desk/skills/preflight-actions/SKILL.md +60 -0
- package/vendor/desk/skills/preview-feedback/SKILL.md +70 -0
- package/vendor/desk/skills/repo-handling/SKILL.md +67 -0
- package/vendor/desk/skills/rnd-lab/SKILL.md +52 -0
- package/vendor/desk/skills/runtime-symptom-investigation/SKILL.md +106 -0
- package/vendor/desk/skills/session-resumption/SKILL.md +126 -0
- package/vendor/desk/skills/session-start/SKILL.md +54 -0
- package/vendor/desk/skills/session-start/details.md +150 -0
- package/vendor/desk/skills/session-start-migrations/README.md +71 -0
- package/vendor/desk/skills/session-start-migrations/SKILL.md +108 -0
- package/vendor/desk/skills/start-task/SKILL.md +88 -0
- package/vendor/desk/skills/task-card-format/SKILL.md +198 -0
- package/vendor/desk/skills/task-lifecycle/SKILL.md +217 -0
- package/vendor/desk/skills/track-card-format/SKILL.md +90 -0
- package/vendor/desk/skills/using-desk/SKILL.md +58 -0
- package/vendor/desk/skills/using-superpowers-with-desk/SKILL.md +156 -0
- package/vendor/desk/skills/work-orchestration/SKILL.md +162 -0
- package/dist/heart/daemon/auth-flow.js +0 -457
- package/dist/heart/daemon/habit-parser.js +0 -119
- package/dist/heart/daemon/habit-scheduler.js +0 -252
- package/dist/heart/daemon/mcp-server.js +0 -591
- package/dist/heart/daemon/ouro-path-installer.js +0 -221
- package/dist/heart/daemon/ouro-version-manager.js +0 -171
- package/dist/heart/daemon/specialist-tools.js +0 -283
- package/dist/heart/daemon/update-hooks.js +0 -138
- package/dist/heart/obligations.js +0 -197
- package/dist/heart/session-recall.js +0 -216
- package/dist/mind/associative-recall.js +0 -287
- package/dist/mind/friends/resolver.js +0 -84
- package/dist/mind/friends/store-file.js +0 -190
- package/dist/mind/friends/trust-explanation.js +0 -74
- package/dist/mind/friends/types.js +0 -29
- package/dist/mind/journal-index.js +0 -161
- package/dist/mind/obligations.js +0 -134
- package/dist/repertoire/tasks/board.js +0 -134
- package/dist/repertoire/tasks/index.js +0 -224
- package/dist/repertoire/tasks/lifecycle.js +0 -80
- package/dist/repertoire/tasks/middleware.js +0 -65
- package/dist/repertoire/tasks/parser.js +0 -171
- package/dist/repertoire/tasks/scanner.js +0 -132
- package/dist/repertoire/tasks/transitions.js +0 -126
- package/dist/repertoire/tools-bluebubbles.js +0 -94
- package/dist/senses/bluebubbles-entry.js +0 -13
- package/dist/senses/bluebubbles-media.js +0 -339
- package/dist/senses/bluebubbles.js +0 -1268
- package/dist/senses/contextual-heartbeat.js +0 -106
- package/dist/senses/debug-activity.js +0 -154
- package/dist/senses/inner-dialog-worker.js +0 -154
- package/dist/senses/inner-dialog.js +0 -768
- package/subagents/README.md +0 -7
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/basilisk.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jafar.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jormungandr.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/kaa.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/medusa.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/monty.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/nagini.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/ouroboros.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/python.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/quetzalcoatl.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/sir-hiss.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-snake.md +0 -0
- /package/dist/{repertoire/tasks/types.js → heart/attachments/sources/adapter.js} +0 -0
- /package/dist/heart/{daemon → hatch}/hatch-animation.js +0 -0
- /package/dist/heart/{daemon → hatch}/specialist-orchestrator.js +0 -0
- /package/dist/heart/{daemon → versioning}/ouro-uti.js +0 -0
- /package/dist/heart/{daemon → versioning}/wrapper-publish-guard.js +0 -0
- /package/{dist/mind/friends → node_modules/@ouro.bot/friends/dist}/store.js +0 -0
package/dist/heart/core.js
CHANGED
|
@@ -1,88 +1,176 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.STEP_BUDGET_NOTICE_AT = exports.MAX_PROVIDER_ITERATIONS_CEILING = exports.STEP_BUDGET_EXTENSION = exports.MAX_PROVIDER_ITERATIONS = void 0;
|
|
4
|
+
exports.validateToolCallBatchAtProductionBoundary = validateToolCallBatchAtProductionBoundary;
|
|
4
5
|
exports.createProviderRegistry = createProviderRegistry;
|
|
6
|
+
exports.getProviderRuntime = getProviderRuntime;
|
|
5
7
|
exports.resetProviderRuntime = resetProviderRuntime;
|
|
6
8
|
exports.getModel = getModel;
|
|
7
9
|
exports.getProvider = getProvider;
|
|
8
10
|
exports.createSummarize = createSummarize;
|
|
9
11
|
exports.getProviderDisplayLabel = getProviderDisplayLabel;
|
|
12
|
+
exports.createHabitCallbackBuffer = createHabitCallbackBuffer;
|
|
13
|
+
exports.stepBudgetNotice = stepBudgetNotice;
|
|
14
|
+
exports.resumeApprovalContinuation = resumeApprovalContinuation;
|
|
15
|
+
exports.unsentSurfaceResult = unsentSurfaceResult;
|
|
16
|
+
exports.surfacesReachedLater = surfacesReachedLater;
|
|
17
|
+
exports.isChatStyleChannel = isChatStyleChannel;
|
|
18
|
+
exports.buildPonderResult = buildPonderResult;
|
|
10
19
|
exports.isExternalStateQuery = isExternalStateQuery;
|
|
20
|
+
exports.settleContentMismatchError = settleContentMismatchError;
|
|
11
21
|
exports.getSettleRetryError = getSettleRetryError;
|
|
12
22
|
exports.stripLastToolCalls = stripLastToolCalls;
|
|
13
23
|
exports.repairOrphanedToolCalls = repairOrphanedToolCalls;
|
|
14
|
-
exports.
|
|
15
|
-
exports.
|
|
24
|
+
exports.isRejectedRequest = isRejectedRequest;
|
|
25
|
+
exports.dropReplayedReasoning = dropReplayedReasoning;
|
|
16
26
|
exports.runAgent = runAgent;
|
|
17
27
|
const config_1 = require("./config");
|
|
18
28
|
const identity_1 = require("./identity");
|
|
29
|
+
const model_limits_1 = require("./model-limits");
|
|
30
|
+
const source_grounding_1 = require("./source-grounding");
|
|
31
|
+
const shelf_claims_1 = require("./shelf-claims");
|
|
32
|
+
const reply_style_1 = require("./reply-style");
|
|
33
|
+
const tool_catalog_1 = require("../repertoire/tool-catalog");
|
|
34
|
+
const skill_search_1 = require("../repertoire/skill-search");
|
|
35
|
+
const skill_summaries_1 = require("../repertoire/skill-summaries");
|
|
19
36
|
const tools_1 = require("../repertoire/tools");
|
|
20
|
-
const
|
|
21
|
-
const
|
|
37
|
+
const tools_base_1 = require("../repertoire/tools-base");
|
|
38
|
+
const tools_flow_1 = require("../repertoire/tools-flow");
|
|
39
|
+
const tool_images_1 = require("./tool-images");
|
|
40
|
+
const tool_arguments_1 = require("../repertoire/tool-arguments");
|
|
41
|
+
const session_events_1 = require("./session-events");
|
|
42
|
+
const tool_approval_1 = require("./tool-approval");
|
|
43
|
+
const friends_1 = require("@ouro.bot/friends");
|
|
44
|
+
const streaming_1 = require("./streaming");
|
|
22
45
|
const runtime_1 = require("../nerves/runtime");
|
|
46
|
+
function validateToolCallBatchAtProductionBoundary(calls, activeTools) {
|
|
47
|
+
const callIdCounts = new Map();
|
|
48
|
+
for (const call of calls)
|
|
49
|
+
callIdCounts.set(call.id, (callIdCounts.get(call.id) ?? 0) + 1);
|
|
50
|
+
return calls.map((call) => {
|
|
51
|
+
if (callIdCounts.get(call.id) !== 1)
|
|
52
|
+
return { call, error: "duplicate tool call id" };
|
|
53
|
+
const advertised = activeTools.find((tool) => tool.function.name === call.name);
|
|
54
|
+
if (!advertised || !advertised.function.parameters || typeof advertised.function.parameters !== "object")
|
|
55
|
+
return { call, error: "tool was not advertised with a valid argument schema" };
|
|
56
|
+
const validated = (0, tool_arguments_1.validateAdvertisedToolArguments)(call.arguments, advertised.function.parameters);
|
|
57
|
+
return validated.ok ? { call, advertised, validated: validated.value } : { call, error: validated.reason };
|
|
58
|
+
});
|
|
59
|
+
}
|
|
23
60
|
const context_1 = require("../mind/context");
|
|
61
|
+
const pending_1 = require("../mind/pending");
|
|
62
|
+
const prompt_budget_1 = require("../mind/prompt-budget");
|
|
24
63
|
const prompt_1 = require("../mind/prompt");
|
|
25
|
-
const
|
|
64
|
+
const kept_notes_1 = require("./kept-notes");
|
|
65
|
+
const error_classification_1 = require("./providers/error-classification");
|
|
26
66
|
const anthropic_1 = require("./providers/anthropic");
|
|
27
67
|
const azure_1 = require("./providers/azure");
|
|
28
68
|
const minimax_1 = require("./providers/minimax");
|
|
29
69
|
const openai_codex_1 = require("./providers/openai-codex");
|
|
30
70
|
const github_copilot_1 = require("./providers/github-copilot");
|
|
31
|
-
const
|
|
71
|
+
const openai_compatible_1 = require("./providers/openai-compatible");
|
|
72
|
+
const orientation_frame_1 = require("./orientation-frame");
|
|
32
73
|
const identity_2 = require("./identity");
|
|
33
74
|
const socket_client_1 = require("./daemon/socket-client");
|
|
34
|
-
const obligations_1 = require("
|
|
75
|
+
const obligations_1 = require("../arc/obligations");
|
|
35
76
|
const tool_loop_1 = require("./tool-loop");
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
77
|
+
const packets_1 = require("../arc/packets");
|
|
78
|
+
const tool_friction_1 = require("./tool-friction");
|
|
79
|
+
const tool_output_budget_1 = require("./tool-output-budget");
|
|
80
|
+
const delegated_command_1 = require("../a2a/delegated-command");
|
|
81
|
+
const provider_models_1 = require("./provider-models");
|
|
82
|
+
const provider_credentials_1 = require("./provider-credentials");
|
|
83
|
+
const provider_fallback_1 = require("./provider-fallback");
|
|
84
|
+
const habit_session_1 = require("./habits/habit-session");
|
|
85
|
+
const provider_attempt_1 = require("./provider-attempt");
|
|
86
|
+
const openai_codex_token_1 = require("./providers/openai-codex-token");
|
|
87
|
+
const turn_summary_1 = require("./turn-summary");
|
|
88
|
+
// Cache only immutable provider construction inputs. ProviderRuntime owns
|
|
89
|
+
// mutable per-turn state (for example Responses nativeInput), so every caller
|
|
90
|
+
// must receive a fresh instance even when its binding fingerprint is unchanged.
|
|
91
|
+
const _providerRuntimeFactories = {
|
|
92
|
+
human: null,
|
|
93
|
+
agent: null,
|
|
94
|
+
};
|
|
95
|
+
function providerLaneForFacing(facing) {
|
|
96
|
+
return facing === "human" ? "outward" : "inner";
|
|
97
|
+
}
|
|
98
|
+
function resolveRuntimeProviderBinding(facing, owner) {
|
|
99
|
+
const lane = providerLaneForFacing(facing);
|
|
100
|
+
const config = (0, identity_1.loadAgentConfig)(owner);
|
|
101
|
+
const facingConfig = facing === "human" ? config.humanFacing : config.agentFacing;
|
|
102
|
+
return { lane, provider: facingConfig.provider, model: facingConfig.model };
|
|
103
|
+
}
|
|
104
|
+
async function getProviderRuntimeFingerprint(facing, owner) {
|
|
105
|
+
const agentName = owner?.agentName ?? (0, identity_2.getAgentName)();
|
|
106
|
+
const binding = resolveRuntimeProviderBinding(facing, owner);
|
|
107
|
+
const credential = await (0, provider_credentials_1.readProviderCredentialRecord)(agentName, binding.provider);
|
|
108
|
+
if (!credential.ok) {
|
|
109
|
+
throw new Error([
|
|
110
|
+
`${binding.lane} provider ${binding.provider} (${binding.model}) has no credentials for ${agentName}.`,
|
|
111
|
+
credential.error,
|
|
112
|
+
`Run \`ouro auth --agent ${agentName} --provider ${binding.provider}\`.`,
|
|
113
|
+
].join("\n"));
|
|
114
|
+
}
|
|
115
|
+
let record = credential.record;
|
|
116
|
+
if (binding.provider === "openai-codex") {
|
|
117
|
+
const refresh = await (0, openai_codex_token_1.refreshOpenAICodexProviderCredentials)(agentName, {
|
|
118
|
+
record,
|
|
119
|
+
reason: "runtime-init",
|
|
120
|
+
});
|
|
121
|
+
if (refresh.ok) {
|
|
122
|
+
record = refresh.record;
|
|
61
123
|
}
|
|
62
|
-
/* v8 ignore stop */
|
|
63
124
|
}
|
|
125
|
+
return {
|
|
126
|
+
binding,
|
|
127
|
+
fingerprint: JSON.stringify({
|
|
128
|
+
...(owner ? { agentName: owner.agentName, agentRoot: owner.agentRoot } : {}),
|
|
129
|
+
lane: binding.lane,
|
|
130
|
+
provider: binding.provider,
|
|
131
|
+
model: binding.model,
|
|
132
|
+
credentialRevision: record.revision,
|
|
133
|
+
}),
|
|
134
|
+
credential: record,
|
|
135
|
+
};
|
|
64
136
|
}
|
|
65
137
|
function createProviderRegistry() {
|
|
66
|
-
const factories = {
|
|
67
|
-
azure: azure_1.createAzureProviderRuntime,
|
|
68
|
-
anthropic: anthropic_1.createAnthropicProviderRuntime,
|
|
69
|
-
minimax: minimax_1.createMinimaxProviderRuntime,
|
|
70
|
-
"openai-codex": openai_codex_1.createOpenAICodexProviderRuntime,
|
|
71
|
-
"github-copilot": github_copilot_1.createGithubCopilotProviderRuntime,
|
|
72
|
-
};
|
|
73
138
|
return {
|
|
74
|
-
resolve() {
|
|
75
|
-
const
|
|
76
|
-
|
|
139
|
+
resolve(provider, model, credential, owner) {
|
|
140
|
+
const providerConfig = { ...credential.config, ...credential.credentials };
|
|
141
|
+
switch (provider) {
|
|
142
|
+
case "azure":
|
|
143
|
+
return (0, azure_1.createAzureProviderRuntime)(model, providerConfig);
|
|
144
|
+
case "anthropic":
|
|
145
|
+
return (0, anthropic_1.createAnthropicProviderRuntime)(model, providerConfig);
|
|
146
|
+
case "minimax":
|
|
147
|
+
return (0, minimax_1.createMinimaxProviderRuntime)(model, providerConfig);
|
|
148
|
+
case "openai-codex":
|
|
149
|
+
return (0, openai_codex_1.createOpenAICodexProviderRuntime)(model, providerConfig);
|
|
150
|
+
case "github-copilot":
|
|
151
|
+
return (0, github_copilot_1.createGithubCopilotProviderRuntime)(model, providerConfig, owner);
|
|
152
|
+
case "openai-compatible":
|
|
153
|
+
case "openai-compatible-gemini":
|
|
154
|
+
return (0, openai_compatible_1.createOpenAICompatibleProviderRuntime)(provider, model, providerConfig);
|
|
155
|
+
}
|
|
77
156
|
},
|
|
78
157
|
};
|
|
79
158
|
}
|
|
80
|
-
function getProviderRuntime() {
|
|
159
|
+
async function getProviderRuntime(facing = "human", owner) {
|
|
160
|
+
const scope = owner ? { agentName: owner.agentName, agentRoot: owner.agentRoot } : undefined;
|
|
161
|
+
let runtime = null;
|
|
81
162
|
try {
|
|
82
|
-
const fingerprint = getProviderRuntimeFingerprint();
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
163
|
+
const { binding, fingerprint, credential } = await getProviderRuntimeFingerprint(facing, scope);
|
|
164
|
+
const cached = _providerRuntimeFactories[facing];
|
|
165
|
+
if (!cached || cached.fingerprint !== fingerprint) {
|
|
166
|
+
const agentName = scope?.agentName ?? (0, identity_2.getAgentName)();
|
|
167
|
+
const runtimeOwner = { agentName, agentRoot: scope?.agentRoot ?? (0, identity_2.getAgentRoot)(agentName) };
|
|
168
|
+
const create = () => createProviderRegistry().resolve(binding.provider, binding.model, credential, runtimeOwner);
|
|
169
|
+
runtime = create();
|
|
170
|
+
_providerRuntimeFactories[facing] = runtime ? { fingerprint, create } : null;
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
runtime = cached.create();
|
|
86
174
|
}
|
|
87
175
|
}
|
|
88
176
|
catch (error) {
|
|
@@ -92,43 +180,65 @@ function getProviderRuntime() {
|
|
|
92
180
|
event: "engine.provider_init_error",
|
|
93
181
|
component: "engine",
|
|
94
182
|
message: msg,
|
|
95
|
-
meta: {},
|
|
183
|
+
meta: { facing },
|
|
96
184
|
});
|
|
97
185
|
// eslint-disable-next-line no-console -- pre-boot guard: provider init failure
|
|
98
186
|
console.error(`\n[fatal] ${msg}\n`);
|
|
99
|
-
|
|
100
|
-
throw new Error("unreachable");
|
|
187
|
+
throw error instanceof Error ? error : new Error(msg);
|
|
101
188
|
}
|
|
102
|
-
if (!
|
|
189
|
+
if (!runtime) {
|
|
190
|
+
const msg = "provider runtime could not be initialized.";
|
|
103
191
|
(0, runtime_1.emitNervesEvent)({
|
|
104
192
|
level: "error",
|
|
105
193
|
event: "engine.provider_init_error",
|
|
106
194
|
component: "engine",
|
|
107
|
-
message:
|
|
108
|
-
meta: {},
|
|
195
|
+
message: msg,
|
|
196
|
+
meta: { facing },
|
|
109
197
|
});
|
|
110
|
-
|
|
111
|
-
|
|
198
|
+
// eslint-disable-next-line no-console -- pre-boot guard: provider init failure
|
|
199
|
+
console.error(`\n[fatal] ${msg}\n`);
|
|
200
|
+
throw new Error(msg);
|
|
112
201
|
}
|
|
113
|
-
|
|
202
|
+
await (0, model_limits_1.learnContextWindow)(runtime);
|
|
203
|
+
// The shared tool loop supplies approval continuation to every provider adapter.
|
|
204
|
+
return { ...runtime, capabilities: new Set([...runtime.capabilities, "approval-continuation"]) };
|
|
205
|
+
}
|
|
206
|
+
/** A runtime for one entry of an agent's provider fallback chain, built fresh from its vault credentials. */
|
|
207
|
+
async function getChainEntryRuntime(entry, owner) {
|
|
208
|
+
const agentName = owner?.agentName ?? (0, identity_2.getAgentName)();
|
|
209
|
+
const credential = await (0, provider_credentials_1.readProviderCredentialRecord)(agentName, entry.provider);
|
|
210
|
+
if (!credential.ok)
|
|
211
|
+
throw new Error(`${entry.provider} (${entry.model}) has no credentials for ${agentName}: ${credential.error}`);
|
|
212
|
+
const runtimeOwner = { agentName, agentRoot: owner?.agentRoot ?? (0, identity_2.getAgentRoot)(agentName) };
|
|
213
|
+
const runtime = createProviderRegistry().resolve(entry.provider, entry.model, credential.record, runtimeOwner);
|
|
214
|
+
/* v8 ignore next -- defensive: the registry resolves every provider id @preserve */
|
|
215
|
+
if (!runtime)
|
|
216
|
+
throw new Error(`${entry.provider} (${entry.model}) runtime could not be initialized.`);
|
|
217
|
+
await (0, model_limits_1.learnContextWindow)(runtime);
|
|
218
|
+
return { ...runtime, capabilities: new Set([...runtime.capabilities, "approval-continuation"]) };
|
|
219
|
+
}
|
|
220
|
+
// Called after getProviderRuntime has loaded the same agent.json, so a bad config has already failed the turn.
|
|
221
|
+
function resolveTurnFallbackChain(facing, owner) {
|
|
222
|
+
return (0, provider_fallback_1.providerFallbackChain)((0, identity_1.loadAgentConfig)(owner), providerLaneForFacing(facing));
|
|
114
223
|
}
|
|
115
224
|
/**
|
|
116
|
-
* Clear
|
|
117
|
-
* current config. Runtime
|
|
118
|
-
*
|
|
225
|
+
* Clear cached provider construction inputs so the next access re-reads them
|
|
226
|
+
* from current config. Runtime instances are always per-caller and are never
|
|
227
|
+
* shared across turns.
|
|
119
228
|
*/
|
|
120
229
|
function resetProviderRuntime() {
|
|
121
|
-
|
|
230
|
+
_providerRuntimeFactories.human = null;
|
|
231
|
+
_providerRuntimeFactories.agent = null;
|
|
122
232
|
}
|
|
123
|
-
function getModel() {
|
|
124
|
-
return
|
|
233
|
+
function getModel(facing = "human") {
|
|
234
|
+
return resolveRuntimeProviderBinding(facing).model;
|
|
125
235
|
}
|
|
126
|
-
function getProvider() {
|
|
127
|
-
return
|
|
236
|
+
function getProvider(facing = "human") {
|
|
237
|
+
return resolveRuntimeProviderBinding(facing).provider;
|
|
128
238
|
}
|
|
129
|
-
function createSummarize() {
|
|
239
|
+
function createSummarize(facing = "human") {
|
|
130
240
|
return async (transcript, instruction) => {
|
|
131
|
-
const runtime = getProviderRuntime();
|
|
241
|
+
const runtime = await getProviderRuntime(facing);
|
|
132
242
|
const client = runtime.client;
|
|
133
243
|
const response = await client.chat.completions.create({
|
|
134
244
|
model: runtime.model,
|
|
@@ -141,103 +251,644 @@ function createSummarize() {
|
|
|
141
251
|
return response.choices?.[0]?.message?.content ?? transcript;
|
|
142
252
|
};
|
|
143
253
|
}
|
|
144
|
-
function getProviderDisplayLabel() {
|
|
145
|
-
const
|
|
254
|
+
function getProviderDisplayLabel(facing = "human") {
|
|
255
|
+
const binding = resolveRuntimeProviderBinding(facing);
|
|
256
|
+
const provider = binding.provider;
|
|
257
|
+
const model = binding.model || "unknown";
|
|
146
258
|
const providerLabelBuilders = {
|
|
147
259
|
azure: () => {
|
|
148
|
-
|
|
149
|
-
return `azure openai (${config.deployment || "default"}, model: ${config.modelName || "unknown"})`;
|
|
260
|
+
return `azure openai (model: ${model})`;
|
|
150
261
|
},
|
|
151
|
-
anthropic: () => `anthropic (${
|
|
152
|
-
minimax: () => `minimax (${
|
|
153
|
-
"openai-codex": () => `openai codex (${
|
|
262
|
+
anthropic: () => `anthropic (${model})`,
|
|
263
|
+
minimax: () => `minimax (${model})`,
|
|
264
|
+
"openai-codex": () => `openai codex (${model})`,
|
|
154
265
|
/* v8 ignore next -- branch: tested via display label unit test @preserve */
|
|
155
|
-
"github-copilot": () => `github copilot (${
|
|
266
|
+
"github-copilot": () => `github copilot (${model})`,
|
|
267
|
+
"openai-compatible": () => `z.ai openai-compatible (${model})`,
|
|
268
|
+
"openai-compatible-gemini": () => `gemini openai-compatible (${model})`,
|
|
156
269
|
};
|
|
157
270
|
return providerLabelBuilders[provider]();
|
|
158
271
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
272
|
+
function createCallbackBuffer(callbacks, mode) {
|
|
273
|
+
const events = [];
|
|
274
|
+
const bufferedCallbacks = {
|
|
275
|
+
...callbacks,
|
|
276
|
+
onTextChunk: (text) => { events.push({ kind: "text", text }); },
|
|
277
|
+
onClearText: () => { events.push({ kind: "clear" }); },
|
|
278
|
+
flushNow: () => { events.push({ kind: "flush" }); },
|
|
279
|
+
};
|
|
280
|
+
if (mode === "all") {
|
|
281
|
+
bufferedCallbacks.onModelStreamStart = () => { events.push({ kind: "stream-start" }); };
|
|
282
|
+
bufferedCallbacks.onReasoningChunk = (text) => { events.push({ kind: "reasoning", text }); };
|
|
283
|
+
}
|
|
284
|
+
return {
|
|
285
|
+
callbacks: bufferedCallbacks,
|
|
286
|
+
async flush() {
|
|
287
|
+
for (const event of events.splice(0)) {
|
|
288
|
+
switch (event.kind) {
|
|
289
|
+
case "stream-start":
|
|
290
|
+
callbacks.onModelStreamStart();
|
|
291
|
+
break;
|
|
292
|
+
case "text":
|
|
293
|
+
callbacks.onTextChunk(event.text);
|
|
294
|
+
break;
|
|
295
|
+
case "reasoning":
|
|
296
|
+
callbacks.onReasoningChunk(event.text);
|
|
297
|
+
break;
|
|
298
|
+
case "clear":
|
|
299
|
+
callbacks.onClearText?.();
|
|
300
|
+
break;
|
|
301
|
+
case "flush":
|
|
302
|
+
await callbacks.flushNow?.();
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
discard() {
|
|
308
|
+
events.splice(0);
|
|
309
|
+
},
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
function createHabitCallbackBuffer(callbacks) {
|
|
313
|
+
return createCallbackBuffer(callbacks, "all");
|
|
314
|
+
}
|
|
315
|
+
function createFinalOnlyTextBuffer(callbacks) {
|
|
316
|
+
return createCallbackBuffer(callbacks, "text-only");
|
|
317
|
+
}
|
|
318
|
+
/** Base per-turn provider-call budget. Grows while tool calls keep making progress. */
|
|
319
|
+
exports.MAX_PROVIDER_ITERATIONS = 8;
|
|
320
|
+
/** How many provider calls each progress-earned extension adds. */
|
|
321
|
+
exports.STEP_BUDGET_EXTENSION = 4;
|
|
322
|
+
/** Hard ceiling on the per-turn provider-call budget, however much progress is made. */
|
|
323
|
+
exports.MAX_PROVIDER_ITERATIONS_CEILING = 24;
|
|
324
|
+
const STEP_BUDGET_REPORT_INSTRUCTION = "the step budget for this turn is used up. do not call any more work tools; none of the tool calls in your last message were executed. call settle now with a short progress report: what is done (with evidence from tool results above), what is still in flight, and what you will do next. say you can continue where you left off when the conversation resumes.";
|
|
325
|
+
/** How few tool-running steps a turn has left before the model is told, so it finishes the asked-for change before the stop. */
|
|
326
|
+
exports.STEP_BUDGET_NOTICE_AT = 2;
|
|
327
|
+
/**
|
|
328
|
+
* The note on a batch's last tool result once the turn is near its step budget: how many more steps can run tools, whether
|
|
329
|
+
* more can still be earned, and what to do with them. `left` counts the steps that will run tools if no further call makes
|
|
330
|
+
* progress; `ceilingLeft` the most the turn can ever get.
|
|
331
|
+
*/
|
|
332
|
+
function stepBudgetNotice(left, ceilingLeft, wrapUpTool) {
|
|
333
|
+
if (left <= 0)
|
|
334
|
+
return `[step budget] that was the last step in this turn that can run tools. call ${wrapUpTool} now: what is done (with evidence from the results above), what is still open, and what you will do next.`;
|
|
335
|
+
const steps = left === 1 ? "at most 1 more step" : `at most ${left} more steps`;
|
|
336
|
+
const more = left >= ceilingLeft ? ", and that is this turn's limit" : "; more come only while new calls keep succeeding";
|
|
337
|
+
return `[step budget] ${steps} in this turn can run tools${more}. finish what was asked first (a change or a send you have ready), leave extra checks for later, then call ${wrapUpTool}.`;
|
|
338
|
+
}
|
|
339
|
+
const STEP_BUDGET_REST_INSTRUCTION = "the step budget for this turn is used up. do not call any more work tools; none of the tool calls in your last message were executed. call rest now with a short note: what is done, what is still open, and what to pick up next time.";
|
|
340
|
+
function continuationCallbacks(callbacks, text) {
|
|
341
|
+
const noop = () => undefined;
|
|
342
|
+
return {
|
|
343
|
+
onModelStart: callbacks.onModelStart ?? noop,
|
|
344
|
+
onModelStreamStart: callbacks.onModelStreamStart ?? noop,
|
|
345
|
+
onTextChunk: (chunk) => {
|
|
346
|
+
text.value += chunk;
|
|
347
|
+
callbacks.onTextChunk?.(chunk);
|
|
348
|
+
},
|
|
349
|
+
onReasoningChunk: callbacks.onReasoningChunk ?? noop,
|
|
350
|
+
onToolStart: callbacks.onToolStart ?? noop,
|
|
351
|
+
...(callbacks.onToolDispatch ? { onToolDispatch: callbacks.onToolDispatch } : {}),
|
|
352
|
+
onToolEnd: callbacks.onToolEnd ?? noop,
|
|
353
|
+
onError: callbacks.onError ?? noop,
|
|
354
|
+
...(callbacks.onClearText ? { onClearText: callbacks.onClearText } : {}),
|
|
355
|
+
...(callbacks.flushNow ? { flushNow: callbacks.flushNow } : {}),
|
|
356
|
+
...(callbacks.settleOutputMode ? { settleOutputMode: callbacks.settleOutputMode } : {}),
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
async function resumeApprovalContinuation(options) {
|
|
360
|
+
const claim = options.claimContinuation();
|
|
361
|
+
if (!claim.claimed) {
|
|
362
|
+
if (claim.interruptedAfterAttempt) {
|
|
363
|
+
const notice = "the approval continuation was interrupted after provider work began; its outcome is indeterminate and it will not be retried automatically";
|
|
364
|
+
await options.deliver(notice);
|
|
365
|
+
(0, runtime_1.emitNervesEvent)({
|
|
366
|
+
level: "error",
|
|
367
|
+
component: "engine",
|
|
368
|
+
event: "engine.approval_continuation_indeterminate",
|
|
369
|
+
message: "approval continuation interrupted after provider attempt",
|
|
370
|
+
meta: { approvalId: options.record.approvalId, continuationState: claim.record.continuationState },
|
|
371
|
+
});
|
|
372
|
+
return { outcome: "terminal_notice", messages: structuredClone(options.sessionMessages) };
|
|
373
|
+
}
|
|
374
|
+
(0, runtime_1.emitNervesEvent)({
|
|
375
|
+
component: "engine",
|
|
376
|
+
event: "engine.approval_continuation_duplicate",
|
|
377
|
+
message: "approval continuation was already consumed",
|
|
378
|
+
meta: { approvalId: options.record.approvalId },
|
|
379
|
+
});
|
|
380
|
+
return { outcome: "already_continued", messages: structuredClone(options.sessionMessages) };
|
|
381
|
+
}
|
|
382
|
+
const materialized = (0, session_events_1.materializeApprovalTerminal)({
|
|
383
|
+
messages: options.sessionMessages,
|
|
384
|
+
checkpoint: options.checkpoint,
|
|
385
|
+
record: options.record,
|
|
386
|
+
currentSessionRevision: options.currentSessionRevision,
|
|
387
|
+
materializedApprovalIds: options.materializedApprovalIds,
|
|
388
|
+
});
|
|
389
|
+
const recoveredMaterialization = claim.record.continuationState === "materialized";
|
|
390
|
+
if (!recoveredMaterialization) {
|
|
391
|
+
await options.persist(materialized.messages);
|
|
392
|
+
await options.markContinuationMaterialized();
|
|
393
|
+
}
|
|
394
|
+
const currentOptions = options.revalidate ? await options.revalidate()
|
|
395
|
+
: options.runAgentOptions?.toolContext?.relationshipAuthorization ? null : options.runAgentOptions;
|
|
396
|
+
if (!materialized.resumeProvider || currentOptions === null) {
|
|
397
|
+
if (currentOptions === null)
|
|
398
|
+
(0, runtime_1.emitNervesEvent)({
|
|
399
|
+
level: "warn", component: "engine", event: "engine.approval_continuation_authority_block",
|
|
400
|
+
message: "approval continuation has no current relationship authority",
|
|
401
|
+
meta: { approvalId: options.record.approvalId, state: options.record.state },
|
|
402
|
+
});
|
|
403
|
+
const effect = options.record.state === "succeeded" ? "the approved action completed"
|
|
404
|
+
: options.record.state === "failed" ? "the approved action failed" : "the protected action was not executed";
|
|
405
|
+
await options.deliver(materialized.directNotice ?? `${effect}; current relationship access is unavailable, so no model continuation was run`);
|
|
406
|
+
await options.completeContinuation();
|
|
407
|
+
return { outcome: "terminal_notice", messages: materialized.messages };
|
|
408
|
+
}
|
|
409
|
+
const outward = { value: "" };
|
|
410
|
+
const callbacks = continuationCallbacks(options.callbacks, outward);
|
|
411
|
+
await options.markContinuationAttempted();
|
|
412
|
+
const result = await options.runAgent(materialized.messages, callbacks, options.channel, options.signal, currentOptions);
|
|
413
|
+
if (result.outcome === "suspended") {
|
|
414
|
+
await options.completeContinuation();
|
|
415
|
+
return { outcome: result.outcome, messages: materialized.messages, suspension: result.suspension };
|
|
416
|
+
}
|
|
417
|
+
await options.persist(materialized.messages, result);
|
|
418
|
+
if (outward.value)
|
|
419
|
+
await options.deliver(outward.value);
|
|
420
|
+
await options.completeContinuation();
|
|
421
|
+
(0, runtime_1.emitNervesEvent)({
|
|
422
|
+
component: "engine",
|
|
423
|
+
event: "engine.approval_continuation_completed",
|
|
424
|
+
message: "approval continuation completed through existing provider loop",
|
|
425
|
+
meta: { approvalId: options.record.approvalId, outcome: result.outcome },
|
|
426
|
+
});
|
|
427
|
+
return { outcome: result.outcome, messages: materialized.messages };
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Strip <think>...</think> blocks for the violation-detection check at the
|
|
431
|
+
* end of a streaming turn. Used to tell legitimate text-only responses
|
|
432
|
+
* apart from the MiniMax-M2.7 "only thinking, no tool call" violation
|
|
433
|
+
* shape. Mirrors the more thorough stripThinkBlocks helper in
|
|
434
|
+
* senses/shared-turn.ts (which is for operator-facing output) — kept
|
|
435
|
+
* inline here to avoid pulling senses/ into the core module's import graph.
|
|
436
|
+
*/
|
|
437
|
+
function stripThinkBlocksForViolationCheck(input) {
|
|
438
|
+
let out = input;
|
|
439
|
+
for (;;) {
|
|
440
|
+
const open = out.indexOf("<think>");
|
|
441
|
+
if (open === -1)
|
|
442
|
+
break;
|
|
443
|
+
const close = out.indexOf("</think>", open + "<think>".length);
|
|
444
|
+
if (close === -1) {
|
|
445
|
+
out = out.slice(0, open);
|
|
446
|
+
break;
|
|
447
|
+
}
|
|
448
|
+
out = out.slice(0, open) + out.slice(close + "</think>".length);
|
|
449
|
+
}
|
|
450
|
+
return out.trim();
|
|
451
|
+
}
|
|
452
|
+
/** Who a send was for: its friendId, or for a surface addressed only by delegationId, that held thought. */
|
|
453
|
+
const surfaceFriendKey = (record) => {
|
|
454
|
+
const friendId = (record.args.friendId ?? "").trim().toLowerCase();
|
|
455
|
+
return friendId || (record.args.delegationId ? `delegation:${record.args.delegationId.trim()}` : "");
|
|
456
|
+
};
|
|
457
|
+
const isUnsentSurface = (record) => record.name === "surface" && /\(code: surface-not-sent\)$/u.test(record.result);
|
|
458
|
+
/** A surface or send_message that reached the friend now, or may have (unconfirmed). */
|
|
459
|
+
const reachedSurfaceFriend = (record) => (record.name === "surface" && /^(?:delivered|forwarded|unconfirmed)\b/u.test(record.result))
|
|
460
|
+
|| (record.name === "send_message" && /^delivered now$/mu.test(record.result) && !/\(code: [a-z0-9-]+\)$/u.test(record.result));
|
|
461
|
+
/**
|
|
462
|
+
* This turn's newest surface result that came back not sent (it ends with the surface-not-sent code), among the
|
|
463
|
+
* friends no later surface or send_message reached. Rest uses it to say once that the person was not told.
|
|
464
|
+
*/
|
|
465
|
+
function unsentSurfaceResult(records) {
|
|
466
|
+
const unsent = new Map();
|
|
467
|
+
for (const record of records) {
|
|
468
|
+
const friend = surfaceFriendKey(record);
|
|
469
|
+
if (isUnsentSurface(record)) {
|
|
470
|
+
unsent.delete(friend);
|
|
471
|
+
unsent.set(friend, record.result);
|
|
472
|
+
}
|
|
473
|
+
else if (reachedSurfaceFriend(record)) {
|
|
474
|
+
unsent.delete(friend);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
return [...unsent.values()].at(-1) ?? null;
|
|
478
|
+
}
|
|
479
|
+
const sameWords = (left, right) => {
|
|
480
|
+
const words = (text) => (text ?? "").trim().replace(/\s+/gu, " ").toLowerCase();
|
|
481
|
+
return words(left) !== "" && words(left) === words(right);
|
|
482
|
+
};
|
|
483
|
+
/**
|
|
484
|
+
* When the newest record reached a friend with the same words as surfaces to that friend saved earlier this turn,
|
|
485
|
+
* those saved copies are now redundant. Different words leave the saved copy alone, since that news has not reached
|
|
486
|
+
* them. A surface addressed only by delegationId names no friend and is left alone.
|
|
487
|
+
*/
|
|
488
|
+
function surfacesReachedLater(records) {
|
|
489
|
+
const latest = records.at(-1);
|
|
490
|
+
if (!latest || !reachedSurfaceFriend(latest) || !latest.args.friendId?.trim())
|
|
491
|
+
return [];
|
|
492
|
+
const said = latest.args.content;
|
|
493
|
+
let saved = [];
|
|
494
|
+
for (const record of records.slice(0, -1)) {
|
|
495
|
+
if (surfaceFriendKey(record) !== surfaceFriendKey(latest))
|
|
496
|
+
continue;
|
|
497
|
+
if (isUnsentSurface(record) && sameWords(record.args.content, said))
|
|
498
|
+
saved.push({ friendId: record.args.friendId.trim(), content: record.args.content });
|
|
499
|
+
else if (reachedSurfaceFriend(record) && sameWords(record.args.content, said))
|
|
500
|
+
saved = [];
|
|
501
|
+
}
|
|
502
|
+
return saved;
|
|
503
|
+
}
|
|
504
|
+
function hasFreshPendingWork(options) {
|
|
505
|
+
const pendingMessages = options?.pendingMessages;
|
|
506
|
+
if (!Array.isArray(pendingMessages))
|
|
507
|
+
return false;
|
|
508
|
+
return pendingMessages.some((message) => typeof message?.content === "string"
|
|
509
|
+
&& message.content.trim().length > 0);
|
|
510
|
+
}
|
|
511
|
+
const HABIT_CONTROL_TOOLS = new Set(["rest", "ponder", "observe"]);
|
|
512
|
+
function highRiskExternalMutation(profile) {
|
|
513
|
+
if (profile.risk !== "high")
|
|
514
|
+
return null;
|
|
515
|
+
const mutates = typeof profile.mutates === "string" ? [profile.mutates] : [...profile.mutates];
|
|
516
|
+
return mutates.includes("external_side_effect") ? mutates.join(", ") : null;
|
|
517
|
+
}
|
|
518
|
+
function recordBlockedHabitSurfaceAttempts(habitSession, toolCalls, reason) {
|
|
519
|
+
if (toolCalls.some((call) => call.name !== "send_message" && call.name !== "surface")) {
|
|
520
|
+
habitSession?.recordError?.(`blocked habit tool batch: ${reason}`);
|
|
521
|
+
}
|
|
522
|
+
if (!habitSession?.recordSurfaceAttempt)
|
|
523
|
+
return;
|
|
524
|
+
for (const call of toolCalls) {
|
|
525
|
+
if (call.name !== "send_message" && call.name !== "surface")
|
|
526
|
+
continue;
|
|
527
|
+
// The canonical pre-batch schema gate guarantees object arguments here.
|
|
528
|
+
const args = JSON.parse(call.arguments);
|
|
529
|
+
habitSession.recordSurfaceAttempt({
|
|
530
|
+
recipient: String(args.friendId ?? args.delegationId ?? "unknown"),
|
|
531
|
+
channel: String(args.channel ?? call.name),
|
|
532
|
+
reason: "blocked",
|
|
533
|
+
result: "blocked",
|
|
534
|
+
rawStatus: "blocked",
|
|
535
|
+
error: reason,
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
async function habitToolBatchBlockReason(habitSession, toolCalls, delegatedOrigins, selection) {
|
|
540
|
+
if (!habitSession)
|
|
541
|
+
return null;
|
|
542
|
+
const granted = new Set(habitSession.toolPolicy.grantedTools);
|
|
543
|
+
const denied = new Set(habitSession.toolPolicy.deniedTools);
|
|
544
|
+
for (const call of toolCalls) {
|
|
545
|
+
if (denied.has(call.name))
|
|
546
|
+
return `habit tool '${call.name}' is denied by this habit session`;
|
|
547
|
+
if (HABIT_CONTROL_TOOLS.has(call.name))
|
|
548
|
+
continue;
|
|
549
|
+
if (!granted.has(call.name))
|
|
550
|
+
return `habit tool '${call.name}' was not granted to this habit session`;
|
|
551
|
+
// The canonical pre-batch schema gate guarantees object arguments here.
|
|
552
|
+
const args = JSON.parse(call.arguments);
|
|
553
|
+
const riskProfile = (0, tools_1.riskProfileForToolName)(call.name, args, selection);
|
|
554
|
+
if (!riskProfile)
|
|
555
|
+
return `habit tool '${call.name}' does not have a known executable risk profile`;
|
|
556
|
+
const externalMutation = highRiskExternalMutation(riskProfile);
|
|
557
|
+
if (externalMutation && call.name !== "send_message" && call.name !== "surface") {
|
|
558
|
+
return `habit tool '${call.name}' has high-risk executable mutation ${externalMutation}: ${riskProfile.reason}`;
|
|
559
|
+
}
|
|
560
|
+
if (call.name === "send_message" || call.name === "surface") {
|
|
561
|
+
const route = await (0, habit_session_1.resolveHabitReturnRoute)({
|
|
562
|
+
agentRoot: (0, identity_2.getAgentRoot)(),
|
|
563
|
+
envelope: habitSession.permissionEnvelope,
|
|
564
|
+
toolName: call.name,
|
|
565
|
+
args,
|
|
566
|
+
friendStore: habitSession.friendStore,
|
|
567
|
+
delegatedOrigins,
|
|
568
|
+
});
|
|
569
|
+
if (!route.allowed)
|
|
570
|
+
return route.reason;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
return null;
|
|
574
|
+
}
|
|
575
|
+
/** Channels that deliberately support mid-turn delivery expose `speak`.
|
|
576
|
+
* BlueBubbles is final-only: its adapter owns one accepted visibility boundary.
|
|
577
|
+
* The private runtime has `ponder`; MCP returns synchronously; mail is batch. */
|
|
578
|
+
function isChatStyleChannel(channel) {
|
|
579
|
+
return (0, friends_1.getChannelCapabilities)(channel).chatStyle;
|
|
580
|
+
}
|
|
581
|
+
function bindCurrentIngressEvidenceLocator(toolList, evidence) {
|
|
582
|
+
if (!evidence
|
|
583
|
+
|| evidence.schemaVersion !== 1
|
|
584
|
+
|| evidence.provider !== "bluebubbles"
|
|
585
|
+
|| !/^[a-f0-9]{64}$/.test(evidence.captureKeyHash))
|
|
586
|
+
return toolList;
|
|
587
|
+
const locator = `capture:${evidence.captureKeyHash}`;
|
|
588
|
+
return toolList.map((tool) => {
|
|
589
|
+
if (tool.function.name !== "habit_cancel")
|
|
590
|
+
return tool;
|
|
591
|
+
const parameters = tool.function.parameters;
|
|
592
|
+
const properties = parameters.properties;
|
|
593
|
+
return {
|
|
594
|
+
...tool,
|
|
595
|
+
function: {
|
|
596
|
+
...tool.function,
|
|
597
|
+
parameters: {
|
|
598
|
+
...parameters,
|
|
599
|
+
properties: {
|
|
600
|
+
...properties,
|
|
601
|
+
evidence: {
|
|
602
|
+
...properties.evidence,
|
|
603
|
+
enum: [locator],
|
|
604
|
+
},
|
|
605
|
+
},
|
|
606
|
+
},
|
|
607
|
+
},
|
|
608
|
+
};
|
|
609
|
+
});
|
|
610
|
+
}
|
|
174
611
|
// Sole-call tools must be the only tool call in a turn. When they appear
|
|
175
612
|
// alongside other tools, the sole-call tool is rejected with this message.
|
|
176
613
|
const SOLE_CALL_REJECTION = {
|
|
177
|
-
settle:
|
|
178
|
-
observe:
|
|
179
|
-
|
|
180
|
-
rest: "rejected: rest must be the only tool call. finish your work first, then call rest alone.",
|
|
614
|
+
settle: tools_flow_1.FLOW_TOOL_REFUSALS.settleAlone,
|
|
615
|
+
observe: tools_flow_1.FLOW_TOOL_REFUSALS.observeAlone,
|
|
616
|
+
rest: tools_flow_1.FLOW_TOOL_REFUSALS.restAlone,
|
|
181
617
|
};
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
if (
|
|
200
|
-
|
|
618
|
+
function parseSettlePayload(argumentsText) {
|
|
619
|
+
const parsed = JSON.parse(argumentsText);
|
|
620
|
+
// Provider finalization validates settle.answer as a string before this
|
|
621
|
+
// terminal handling path. Keep this parser focused on projection instead
|
|
622
|
+
// of carrying an unreachable second shape check.
|
|
623
|
+
const answer = parsed.answer;
|
|
624
|
+
const rawIntent = parsed.intent;
|
|
625
|
+
const intent = rawIntent === "complete" || rawIntent === "blocked" || rawIntent === "direct_reply"
|
|
626
|
+
? rawIntent
|
|
627
|
+
: undefined;
|
|
628
|
+
return { answer, intent };
|
|
629
|
+
}
|
|
630
|
+
function parsePonderPayload(argumentsText) {
|
|
631
|
+
// The canonical pre-batch schema gate guarantees a valid object payload.
|
|
632
|
+
return JSON.parse(argumentsText);
|
|
633
|
+
}
|
|
634
|
+
function parseSuccessCriteria(raw) {
|
|
635
|
+
if (typeof raw !== "string")
|
|
636
|
+
return null;
|
|
637
|
+
const criteria = raw
|
|
638
|
+
.split("\n")
|
|
639
|
+
.map((line) => line.replace(/^\s*[-*]\s*/, "").trim())
|
|
640
|
+
.filter((line) => line.length > 0);
|
|
641
|
+
return criteria.length > 0 ? criteria : null;
|
|
642
|
+
}
|
|
643
|
+
function parsePacketPayload(raw) {
|
|
644
|
+
if (typeof raw !== "string")
|
|
645
|
+
return null;
|
|
646
|
+
try {
|
|
647
|
+
const parsed = JSON.parse(raw);
|
|
648
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed)
|
|
649
|
+
? parsed
|
|
650
|
+
: null;
|
|
201
651
|
}
|
|
202
|
-
|
|
203
|
-
|
|
652
|
+
catch {
|
|
653
|
+
return null;
|
|
204
654
|
}
|
|
205
|
-
return [
|
|
206
|
-
"## what i need to think about",
|
|
207
|
-
params.topic,
|
|
208
|
-
"",
|
|
209
|
-
"## why this came up",
|
|
210
|
-
reasonProse,
|
|
211
|
-
"",
|
|
212
|
-
"## who asked",
|
|
213
|
-
whoAsked,
|
|
214
|
-
"",
|
|
215
|
-
"## what i'm holding",
|
|
216
|
-
holdingLine,
|
|
217
|
-
"",
|
|
218
|
-
"## thinking mode",
|
|
219
|
-
params.mode,
|
|
220
|
-
].join("\n");
|
|
221
655
|
}
|
|
222
|
-
function
|
|
656
|
+
function normalizeLegacyPonderArgs(parsed) {
|
|
657
|
+
if (typeof parsed.thought !== "string" || parsed.thought.trim().length === 0) {
|
|
658
|
+
return parsed;
|
|
659
|
+
}
|
|
660
|
+
return {
|
|
661
|
+
action: "create",
|
|
662
|
+
kind: "reflection",
|
|
663
|
+
objective: parsed.thought.trim(),
|
|
664
|
+
summary: typeof parsed.say === "string" ? parsed.say.trim() : "",
|
|
665
|
+
success_criteria: "- preserve the thread for later work",
|
|
666
|
+
payload_json: "{}",
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
function messageContentText(content) {
|
|
670
|
+
if (typeof content === "string")
|
|
671
|
+
return content;
|
|
672
|
+
if (!Array.isArray(content))
|
|
673
|
+
return "";
|
|
674
|
+
return content
|
|
675
|
+
.map((part) => {
|
|
676
|
+
if (typeof part === "string")
|
|
677
|
+
return part;
|
|
678
|
+
if (!part || typeof part !== "object")
|
|
679
|
+
return "";
|
|
680
|
+
const maybeText = part.text;
|
|
681
|
+
return typeof maybeText === "string" ? maybeText : "";
|
|
682
|
+
})
|
|
683
|
+
.filter(Boolean)
|
|
684
|
+
.join("\n");
|
|
685
|
+
}
|
|
686
|
+
function toolResultIndicatesFailure(content) {
|
|
687
|
+
const normalized = content.trim().toLowerCase();
|
|
688
|
+
return normalized.startsWith("error:")
|
|
689
|
+
|| normalized.startsWith("invalid tool arguments:")
|
|
690
|
+
|| normalized.startsWith("unknown:")
|
|
691
|
+
|| normalized.startsWith("relationship authorization required:")
|
|
692
|
+
|| normalized.startsWith("orientation hold:")
|
|
693
|
+
|| normalized.startsWith("commerce authority required:")
|
|
694
|
+
|| normalized.startsWith("blocked:")
|
|
695
|
+
|| normalized.startsWith("rejected:");
|
|
696
|
+
}
|
|
697
|
+
function requiredToolResultSucceeded(name, content, args, validate) {
|
|
698
|
+
if (toolResultIndicatesFailure(content))
|
|
699
|
+
return false;
|
|
700
|
+
return validate?.(name, content, args) ?? true;
|
|
701
|
+
}
|
|
702
|
+
function effectFingerprint(name, rawArguments, selection) {
|
|
703
|
+
let args;
|
|
223
704
|
try {
|
|
224
|
-
const parsed = JSON.parse(
|
|
225
|
-
if (typeof parsed
|
|
226
|
-
return
|
|
705
|
+
const parsed = JSON.parse(rawArguments);
|
|
706
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
707
|
+
return null;
|
|
708
|
+
args = { ...parsed };
|
|
709
|
+
}
|
|
710
|
+
catch {
|
|
711
|
+
return null;
|
|
712
|
+
}
|
|
713
|
+
const profile = (0, tools_1.riskProfileForToolName)(name, args, selection);
|
|
714
|
+
if (!profile || profile.mutates === "none")
|
|
715
|
+
return null;
|
|
716
|
+
delete args.expectedVersion;
|
|
717
|
+
return (0, tool_arguments_1.digestJson)({ name, args });
|
|
718
|
+
}
|
|
719
|
+
function historicalFailedEffectsForExactRepeatedRequest(messages, selection) {
|
|
720
|
+
const userRequests = [];
|
|
721
|
+
for (let index = 0; index < messages.length; index += 1) {
|
|
722
|
+
const message = messages[index];
|
|
723
|
+
if (message?.role !== "user")
|
|
724
|
+
continue;
|
|
725
|
+
const text = messageContentText(message.content).replace(/\s+/g, " ").trim();
|
|
726
|
+
if (!text)
|
|
727
|
+
continue;
|
|
728
|
+
userRequests.push({ index, text });
|
|
729
|
+
}
|
|
730
|
+
const current = userRequests.at(-1);
|
|
731
|
+
if (!current)
|
|
732
|
+
return [];
|
|
733
|
+
const prior = userRequests.slice(0, -1).find((request) => request.text === current.text);
|
|
734
|
+
if (!prior)
|
|
735
|
+
return [];
|
|
736
|
+
const effectsByCallId = new Map();
|
|
737
|
+
const failedEffects = new Map();
|
|
738
|
+
// Scan through the end: an effect the approval runtime already ran after the current request (the owner tapped
|
|
739
|
+
// Approve) is resolved by its success. A failure after the current request never adds a new forced effect.
|
|
740
|
+
for (let index = prior.index + 1; index < messages.length; index += 1) {
|
|
741
|
+
if (index === current.index)
|
|
742
|
+
continue;
|
|
743
|
+
const message = messages[index];
|
|
744
|
+
if (message?.role === "assistant" && Array.isArray(message.tool_calls)) {
|
|
745
|
+
for (const call of message.tool_calls) {
|
|
746
|
+
if (call.type !== "function" || !call.id || !call.function.name)
|
|
747
|
+
continue;
|
|
748
|
+
const fingerprint = effectFingerprint(call.function.name, call.function.arguments, selection);
|
|
749
|
+
if (fingerprint)
|
|
750
|
+
effectsByCallId.set(call.id, { name: call.function.name, fingerprint });
|
|
751
|
+
}
|
|
752
|
+
continue;
|
|
753
|
+
}
|
|
754
|
+
if (message?.role !== "tool")
|
|
755
|
+
continue;
|
|
756
|
+
const content = messageContentText(message.content);
|
|
757
|
+
const effect = effectsByCallId.get(message.tool_call_id);
|
|
758
|
+
if (!effect)
|
|
759
|
+
continue;
|
|
760
|
+
if (toolResultIndicatesFailure(content)) {
|
|
761
|
+
if (index < current.index)
|
|
762
|
+
failedEffects.set(effect.fingerprint, effect);
|
|
227
763
|
}
|
|
228
|
-
|
|
229
|
-
|
|
764
|
+
else {
|
|
765
|
+
failedEffects.delete(effect.fingerprint);
|
|
230
766
|
}
|
|
231
|
-
const answer = typeof parsed.answer === "string" ? parsed.answer : undefined;
|
|
232
|
-
const rawIntent = parsed.intent;
|
|
233
|
-
const intent = rawIntent === "complete" || rawIntent === "blocked" || rawIntent === "direct_reply"
|
|
234
|
-
? rawIntent
|
|
235
|
-
: undefined;
|
|
236
|
-
return { answer, intent };
|
|
237
767
|
}
|
|
238
|
-
|
|
239
|
-
|
|
768
|
+
return [...failedEffects.values()];
|
|
769
|
+
}
|
|
770
|
+
const ANSWER_GATE_MAX_REJECTIONS = 2;
|
|
771
|
+
/** Brevity and shelf claims are retried once; after that the reply goes out (an unbacked shelf claim with a disclosure), because a real draft beats another lap. */
|
|
772
|
+
const ANSWER_STYLE_MAX_RETRIES = 1;
|
|
773
|
+
function privateGateNote(reason) {
|
|
774
|
+
return `[private runtime note, not from the person: do not mention, quote or acknowledge it. your draft was not sent and the person has not seen it, so send the whole corrected reply as if it were your first, never as a correction or follow-up] ${reason}`;
|
|
775
|
+
}
|
|
776
|
+
/** A reply that talks about the runtime's correction (its formatting rules, the retry itself) instead of answering the person. */
|
|
777
|
+
const GATE_NOTE_ECHO = /\b(?:markdown|bold\s+(?:section\s+)?labels?|section\s+labels?|question\s+at\s+the\s+end|closing\s+question|settle\s+again|rewrite\s+the\s+reply|cap\s+it|runtime\s+note|private\s+note)\b/i;
|
|
778
|
+
/** The settle call as delivered, so the history holds what the person got rather than a draft the runtime replaced. */
|
|
779
|
+
function withSettleAnswer(msg, settleArgs, answer) {
|
|
780
|
+
const call = msg.tool_calls[0];
|
|
781
|
+
const args = { ...settleArgs, answer };
|
|
782
|
+
return { ...msg, tool_calls: [{ ...call, function: { ...call.function, arguments: JSON.stringify(args) } }, ...msg.tool_calls.slice(1)] };
|
|
783
|
+
}
|
|
784
|
+
function userTexts(messages) {
|
|
785
|
+
return messages.filter((message) => message.role === "user").map((message) => messageContentText(message.content));
|
|
786
|
+
}
|
|
787
|
+
/** What earlier turns already said or read: assistant replies and tool results before the latest user message. Names in them are not new to this turn. */
|
|
788
|
+
function priorTurnsText(messages) {
|
|
789
|
+
const latest = messages.findLastIndex((message) => message.role === "user");
|
|
790
|
+
return messages.slice(0, Math.max(latest, 0)).filter((message) => message.role === "assistant" || message.role === "tool").map((message) => messageContentText(message.content)).join("\n");
|
|
791
|
+
}
|
|
792
|
+
function latestUserMessageText(messages) {
|
|
793
|
+
for (let i = messages.length - 1; i >= 0; i -= 1) {
|
|
794
|
+
const message = messages[i];
|
|
795
|
+
if (message?.role !== "user")
|
|
796
|
+
continue;
|
|
797
|
+
const text = messageContentText(message.content).trim();
|
|
798
|
+
if (text.length > 0)
|
|
799
|
+
return text;
|
|
800
|
+
}
|
|
801
|
+
return "";
|
|
802
|
+
}
|
|
803
|
+
function truncatePonderDelegatedContent(value) {
|
|
804
|
+
return value.length > 120 ? `${value.slice(0, 117)}...` : value;
|
|
805
|
+
}
|
|
806
|
+
function buildPonderDelegatedContent(input) {
|
|
807
|
+
const primary = (input.summary || input.objective).trim();
|
|
808
|
+
const sourceRequest = input.sourceRequest.trim();
|
|
809
|
+
if (!sourceRequest || sourceRequest === primary || sourceRequest === input.objective.trim()) {
|
|
810
|
+
return truncatePonderDelegatedContent(primary);
|
|
811
|
+
}
|
|
812
|
+
return truncatePonderDelegatedContent(`${primary}\nsource request: ${sourceRequest}`);
|
|
813
|
+
}
|
|
814
|
+
function looksLikePrivateReturnRequest(text) {
|
|
815
|
+
const normalized = text.toLowerCase();
|
|
816
|
+
return /\b(private|privately|private-attention|think|reflect|reflection)\b/.test(normalized)
|
|
817
|
+
&& /\b(return|bring back|come back|surface|report back)\b/.test(normalized);
|
|
818
|
+
}
|
|
819
|
+
function extractPrivateReturnHeldTokens(text) {
|
|
820
|
+
const tokens = new Set();
|
|
821
|
+
for (const match of text.matchAll(/\b[A-Z][A-Z0-9]*(?:_[A-Z0-9]+){2,}\b/g)) {
|
|
822
|
+
const token = match[0];
|
|
823
|
+
if (token.length >= 8)
|
|
824
|
+
tokens.add(token);
|
|
825
|
+
}
|
|
826
|
+
return [...tokens];
|
|
827
|
+
}
|
|
828
|
+
function privateReturnAckLeakError(answer, heldTokens) {
|
|
829
|
+
if (!answer || heldTokens.size === 0)
|
|
830
|
+
return null;
|
|
831
|
+
for (const token of heldTokens) {
|
|
832
|
+
if (answer.includes(token)) {
|
|
833
|
+
return "private return is queued; do not repeat private markers or requested private-return content in the outward acknowledgement. Say only that the private pass is queued and will return when ready.";
|
|
834
|
+
}
|
|
240
835
|
}
|
|
836
|
+
return null;
|
|
837
|
+
}
|
|
838
|
+
function claimsPrivateReturnQueued(answer) {
|
|
839
|
+
if (!answer)
|
|
840
|
+
return false;
|
|
841
|
+
const normalized = answer.toLowerCase();
|
|
842
|
+
return /\b(queued|queue|will return|return when|when .*complete|when .*completes|private pass|private runtime completes|inner dialog completes|later)\b/.test(normalized)
|
|
843
|
+
&& /\b(private|inner|return|queued|later)\b/.test(normalized);
|
|
844
|
+
}
|
|
845
|
+
function privateReturnMissingPonderError(input) {
|
|
846
|
+
if (input.sawPonder)
|
|
847
|
+
return null;
|
|
848
|
+
if (!looksLikePrivateReturnRequest(input.latestUserRequest))
|
|
849
|
+
return null;
|
|
850
|
+
if (!claimsPrivateReturnQueued(input.answer))
|
|
851
|
+
return null;
|
|
852
|
+
return "private-return acknowledgement claimed work was queued, but no ponder packet was created this turn. Call ponder(action=create, ...) first so the return has a packet, return obligation, and private-runtime wake; then settle with only a queued acknowledgement. If you cannot create the packet, ask a blocking clarification without saying it is queued.";
|
|
853
|
+
}
|
|
854
|
+
function activeReturnObligationId(agentName, obligationId) {
|
|
855
|
+
if (!obligationId)
|
|
856
|
+
return null;
|
|
857
|
+
const obligation = (0, obligations_1.readReturnObligation)(agentName, obligationId);
|
|
858
|
+
return obligation?.status === "queued" || obligation?.status === "running" ? obligationId : null;
|
|
859
|
+
}
|
|
860
|
+
function ponderReturnSessionId(packet) {
|
|
861
|
+
const origin = packet.origin;
|
|
862
|
+
if (!origin)
|
|
863
|
+
return "unknown/unknown/unknown";
|
|
864
|
+
return `${origin.friendId}/${origin.channel}/${origin.key}`;
|
|
865
|
+
}
|
|
866
|
+
function buildPonderReturnPrivateWakeOptions(input) {
|
|
867
|
+
const sessionId = ponderReturnSessionId(input.packet);
|
|
868
|
+
return {
|
|
869
|
+
reason: "ponder return obligation private attention",
|
|
870
|
+
triggerSource: "ponder-return-obligation",
|
|
871
|
+
budgetClass: "interactive",
|
|
872
|
+
idempotencyKey: `ponder-return:${input.agentName}:${input.returnObligationId}:${input.packet.id}:${sessionId}`,
|
|
873
|
+
originRefs: [
|
|
874
|
+
{ kind: "tool", id: "ponder" },
|
|
875
|
+
{ kind: "ponder-packet", id: input.packet.id },
|
|
876
|
+
{ kind: "return-obligation", id: input.returnObligationId },
|
|
877
|
+
{ kind: "session", id: sessionId },
|
|
878
|
+
],
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
function buildPonderResult(packet, action, returnObligationId) {
|
|
882
|
+
return JSON.stringify({
|
|
883
|
+
ok: true,
|
|
884
|
+
packet_id: packet.id,
|
|
885
|
+
action,
|
|
886
|
+
status: packet.status,
|
|
887
|
+
return_obligation_id: returnObligationId,
|
|
888
|
+
private_return_contract: returnObligationId
|
|
889
|
+
? "queued for private-runtime attention; do not present the requested private answer as complete in this same outward turn. if you answer now, only say the private pass is queued and will return when ready."
|
|
890
|
+
: null,
|
|
891
|
+
}, null, 2);
|
|
241
892
|
}
|
|
242
893
|
/** Returns true when a tool call queries external state (GitHub, npm registry). */
|
|
243
894
|
function isExternalStateQuery(toolName, args) {
|
|
@@ -246,7 +897,28 @@ function isExternalStateQuery(toolName, args) {
|
|
|
246
897
|
const cmd = String(args.command ?? "");
|
|
247
898
|
return /\bgh\s+(pr|run|api|issue)\b/.test(cmd) || /\bnpm\s+(view|info|show)\b/.test(cmd);
|
|
248
899
|
}
|
|
249
|
-
|
|
900
|
+
const SETTLE_CONTENT_MISMATCH_MIN_CHARS = 40;
|
|
901
|
+
// Markdown markers and smart punctuation differ between a reply and its settle copy without changing it.
|
|
902
|
+
const normalizeForSettleComparison = (text) => text.replace(/[*_`>#~]/g, "").replace(/[\u2018\u2019]/g, "'").replace(/[\u201c\u201d]/g, '"').replace(/[\u2013\u2014]/g, "-").replace(/\s+/g, " ").trim().toLowerCase();
|
|
903
|
+
/**
|
|
904
|
+
* Only `settle.answer` reaches the friend; assistant message text in the same
|
|
905
|
+
* message does not. When a model writes its real reply as message text and puts
|
|
906
|
+
* something else (often a third-person recap) in the answer, the friend gets the
|
|
907
|
+
* recap. Ask once for the reply to be resent as the answer. Short preambles and
|
|
908
|
+
* text the answer already contains (or that contains the answer) pass.
|
|
909
|
+
*/
|
|
910
|
+
function settleContentMismatchError(content, answer) {
|
|
911
|
+
if (typeof content !== "string")
|
|
912
|
+
return null;
|
|
913
|
+
const text = normalizeForSettleComparison(content);
|
|
914
|
+
if (text.length < SETTLE_CONTENT_MISMATCH_MIN_CHARS)
|
|
915
|
+
return null;
|
|
916
|
+
const reply = normalizeForSettleComparison(answer);
|
|
917
|
+
if (reply.includes(text) || text.includes(reply))
|
|
918
|
+
return null;
|
|
919
|
+
return "only settle.answer reaches the person; the message text you wrote alongside it does not. if that text is your reply, call settle again with the complete reply, in your own voice, as answer. if it was only working notes, call settle again with the same answer.";
|
|
920
|
+
}
|
|
921
|
+
function getSettleRetryError(mustResolveBeforeHandoff, intent, sawSteeringFollowUp, _delegationDecision, sawSendMessageSelf, sawPonder, _sawQuerySession, currentObligation, innerJob, _sawExternalStateQuery) {
|
|
250
922
|
// Delegation adherence removed: the delegation decision is surfaced in the
|
|
251
923
|
// system prompt as a suggestion. Hard-gating settle caused infinite
|
|
252
924
|
// rejection loops where the agent couldn't respond to the user at all.
|
|
@@ -267,24 +939,27 @@ function getSettleRetryError(mustResolveBeforeHandoff, intent, sawSteeringFollow
|
|
|
267
939
|
if (mustResolveBeforeHandoff && intent === "complete" && currentObligation && !sawSteeringFollowUp) {
|
|
268
940
|
return "you still owe the live session a visible return on this work. don't end the turn yet — continue until you've brought back the external-state update, or use intent=blocked with the concrete blocker.";
|
|
269
941
|
}
|
|
270
|
-
// 6. External-state grounding: obligation + complete requires fresh external verification
|
|
271
|
-
if (intent === "complete" && currentObligation && !sawExternalStateQuery && !sawSteeringFollowUp) {
|
|
272
|
-
return "you're claiming this work is complete, but the external state hasn't been verified this turn. ground your claim with a fresh check (gh pr view, npm view, gh run view, etc.) before calling settle.";
|
|
273
|
-
}
|
|
274
942
|
return null;
|
|
275
943
|
}
|
|
276
|
-
|
|
277
|
-
var kicks_1 = require("./kicks");
|
|
278
|
-
Object.defineProperty(exports, "hasToolIntent", { enumerable: true, get: function () { return kicks_1.hasToolIntent; } });
|
|
279
|
-
function upsertSystemPrompt(messages, systemText) {
|
|
944
|
+
function upsertSystemPrompt(messages, systemText, protectedSystemMessages = []) {
|
|
280
945
|
const systemMessage = { role: "system", content: systemText };
|
|
281
|
-
|
|
946
|
+
const protectedMessages = new Set(protectedSystemMessages.filter((message) => message.role === "system"));
|
|
947
|
+
if (messages[0]?.role === "system" && !protectedMessages.has(messages[0])) {
|
|
282
948
|
messages[0] = systemMessage;
|
|
283
949
|
}
|
|
284
950
|
else {
|
|
285
951
|
messages.unshift(systemMessage);
|
|
286
952
|
}
|
|
287
953
|
}
|
|
954
|
+
/**
|
|
955
|
+
* A prompt refresh failure must not revive any generated text from an older
|
|
956
|
+
* turn or release. Even the nominally stable region contains actor-scoped trust,
|
|
957
|
+
* tool, and channel context, so it is not safe to reconstruct. Fail closed to a
|
|
958
|
+
* neutral base and put the freshly derived trigger first.
|
|
959
|
+
*/
|
|
960
|
+
function repairFallbackSystemPrompt(orientationFrame) {
|
|
961
|
+
return `${(0, orientation_frame_1.renderOrientationFrame)(orientationFrame)}\n\nYou are a helpful assistant.`;
|
|
962
|
+
}
|
|
288
963
|
// Remove orphan tool_calls from the last assistant message and any
|
|
289
964
|
// trailing tool-result messages that lack a matching tool_call.
|
|
290
965
|
// This keeps the conversation valid after an abort or tool-loop limit.
|
|
@@ -313,27 +988,39 @@ const TOOL_SCAN_BOUNDARY_ROLES = new Set(["assistant", "user"]);
|
|
|
313
988
|
// 1. If an assistant message has tool_calls but missing tool results, inject synthetic error results.
|
|
314
989
|
// 2. If a tool result's tool_call_id doesn't match any tool_calls in a preceding assistant message, remove it.
|
|
315
990
|
// This prevents 400 errors from the API after an aborted turn.
|
|
991
|
+
//
|
|
992
|
+
// Position-aware: a tool result is orphaned when its tool_call_id hasn't been
|
|
993
|
+
// defined by an assistant message AT THIS POSITION yet. MiniMax-M2.7 reuses
|
|
994
|
+
// canonical tool_call_ids across turns, so the global-set check that this
|
|
995
|
+
// function used previously kept misordered tool results that MiniMax then
|
|
996
|
+
// rejected with error 2013 ("tool result's tool id not found"). Walking
|
|
997
|
+
// in order matches what MiniMax actually enforces.
|
|
316
998
|
function repairOrphanedToolCalls(messages) {
|
|
317
|
-
// Pass 1:
|
|
318
|
-
|
|
319
|
-
|
|
999
|
+
// Pass 1: walk in order, accumulate seen tool_call_ids per-position, and
|
|
1000
|
+
// mark tool results for removal if their id hasn't been defined yet.
|
|
1001
|
+
const seenCallIds = new Set();
|
|
1002
|
+
const removeIndices = [];
|
|
1003
|
+
for (let i = 0; i < messages.length; i++) {
|
|
1004
|
+
const msg = messages[i];
|
|
320
1005
|
if (msg.role === "assistant") {
|
|
321
1006
|
const asst = msg;
|
|
322
1007
|
if (asst.tool_calls) {
|
|
323
1008
|
for (const tc of asst.tool_calls)
|
|
324
|
-
|
|
1009
|
+
seenCallIds.add(tc.id);
|
|
325
1010
|
}
|
|
1011
|
+
continue;
|
|
326
1012
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
const toolMsg = messages[i];
|
|
332
|
-
if (!validCallIds.has(toolMsg.tool_call_id)) {
|
|
333
|
-
messages.splice(i, 1);
|
|
1013
|
+
if (msg.role === "tool") {
|
|
1014
|
+
const toolMsg = msg;
|
|
1015
|
+
if (!seenCallIds.has(toolMsg.tool_call_id)) {
|
|
1016
|
+
removeIndices.push(i);
|
|
334
1017
|
}
|
|
335
1018
|
}
|
|
336
1019
|
}
|
|
1020
|
+
// Splice from the end so earlier indices stay valid.
|
|
1021
|
+
for (let i = removeIndices.length - 1; i >= 0; i--) {
|
|
1022
|
+
messages.splice(removeIndices[i], 1);
|
|
1023
|
+
}
|
|
337
1024
|
// Pass 3: inject synthetic results for tool_calls missing their tool results
|
|
338
1025
|
for (let i = 0; i < messages.length; i++) {
|
|
339
1026
|
const msg = messages[i];
|
|
@@ -355,10 +1042,13 @@ function repairOrphanedToolCalls(messages) {
|
|
|
355
1042
|
}
|
|
356
1043
|
const missing = asst.tool_calls.filter((tc) => !resultIds.has(tc.id));
|
|
357
1044
|
if (missing.length > 0) {
|
|
1045
|
+
// AX rule: the agent must see what happened. Don't say "interrupted"
|
|
1046
|
+
// — that's vague. Tell them the result was lost, possible causes,
|
|
1047
|
+
// and what to do next.
|
|
358
1048
|
const syntheticResults = missing.map((tc) => ({
|
|
359
1049
|
role: "tool",
|
|
360
1050
|
tool_call_id: tc.id,
|
|
361
|
-
content: "error: tool call was
|
|
1051
|
+
content: "error: this tool call's result was lost — the previous turn ended before the tool finished (provider rejection, daemon interrupt, or the tool itself errored). if the work needs to be done, retry the tool call now.",
|
|
362
1052
|
}));
|
|
363
1053
|
let insertAt = i + 1;
|
|
364
1054
|
while (insertAt < messages.length && messages[insertAt].role === "tool")
|
|
@@ -381,48 +1071,25 @@ function isContextOverflow(err) {
|
|
|
381
1071
|
return true;
|
|
382
1072
|
return false;
|
|
383
1073
|
}
|
|
384
|
-
//
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
const msg = err.message || "";
|
|
389
|
-
const code = err.code || "";
|
|
390
|
-
// Node.js network error codes
|
|
391
|
-
if (["ECONNRESET", "ECONNREFUSED", "ENOTFOUND", "ETIMEDOUT", "EPIPE",
|
|
392
|
-
"EAI_AGAIN", "EHOSTUNREACH", "ENETUNREACH", "ECONNABORTED"].includes(code))
|
|
393
|
-
return true;
|
|
394
|
-
// OpenAI SDK / fetch errors
|
|
395
|
-
if (msg.includes("fetch failed"))
|
|
396
|
-
return true;
|
|
397
|
-
if (msg.includes("network") && !msg.includes("context"))
|
|
398
|
-
return true;
|
|
399
|
-
if (msg.includes("ECONNRESET") || msg.includes("ETIMEDOUT"))
|
|
400
|
-
return true;
|
|
401
|
-
if (msg.includes("socket hang up"))
|
|
402
|
-
return true;
|
|
403
|
-
if (msg.includes("getaddrinfo"))
|
|
404
|
-
return true;
|
|
405
|
-
// HTTP 429 / 500 / 502 / 503 / 504
|
|
406
|
-
const status = err.status;
|
|
407
|
-
if (status === 429 || status === 500 || status === 502 || status === 503 || status === 504)
|
|
408
|
-
return true;
|
|
409
|
-
return false;
|
|
1074
|
+
// The provider refused the request itself (a 400 that is not a context overflow): something in what the runtime sent, not
|
|
1075
|
+
// an outage. The agent gets one corrected retry instead of the turn failing (a replayed reasoning signature, a gap in tool results).
|
|
1076
|
+
function isRejectedRequest(err) {
|
|
1077
|
+
return err instanceof Error && err.status === 400 && !isContextOverflow(err);
|
|
410
1078
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
const
|
|
425
|
-
const TRANSIENT_RETRY_LABELS = {
|
|
1079
|
+
// Reasoning blocks replayed from earlier turns are the agent's private scratch, and a provider may refuse their signatures.
|
|
1080
|
+
// The current turn's own blocks stay: the provider needs them to continue tool use within the turn.
|
|
1081
|
+
function dropReplayedReasoning(messages, keepFrom) {
|
|
1082
|
+
return messages.map((message, index) => {
|
|
1083
|
+
if (index >= keepFrom || message.role !== "assistant")
|
|
1084
|
+
return message;
|
|
1085
|
+
const record = message;
|
|
1086
|
+
if (!("_thinking_blocks" in record) && !("_reasoning_items" in record))
|
|
1087
|
+
return message;
|
|
1088
|
+
const { _thinking_blocks: _thinking, _reasoning_items: _reasoning, ...rest } = record;
|
|
1089
|
+
return rest;
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
const RETRY_LABELS = {
|
|
426
1093
|
"auth-failure": "auth error",
|
|
427
1094
|
"usage-limit": "usage limit",
|
|
428
1095
|
"rate-limit": "rate limited",
|
|
@@ -430,10 +1097,151 @@ const TRANSIENT_RETRY_LABELS = {
|
|
|
430
1097
|
"network-error": "network error",
|
|
431
1098
|
"unknown": "error",
|
|
432
1099
|
};
|
|
1100
|
+
function waitForProviderRetry(delayMs, signal) {
|
|
1101
|
+
if (!signal) {
|
|
1102
|
+
return new Promise((resolve) => {
|
|
1103
|
+
setTimeout(resolve, delayMs);
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
return new Promise((resolve, reject) => {
|
|
1107
|
+
let timer;
|
|
1108
|
+
const onAbort = () => {
|
|
1109
|
+
clearTimeout(timer);
|
|
1110
|
+
reject(new provider_attempt_1.ProviderAttemptAbortError());
|
|
1111
|
+
};
|
|
1112
|
+
timer = setTimeout(() => {
|
|
1113
|
+
signal.removeEventListener("abort", onAbort);
|
|
1114
|
+
resolve();
|
|
1115
|
+
}, delayMs);
|
|
1116
|
+
if (signal.aborted) {
|
|
1117
|
+
onAbort();
|
|
1118
|
+
return;
|
|
1119
|
+
}
|
|
1120
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
1123
|
+
function buildAuthFailureGuidance(provider, model, agentName, detail) {
|
|
1124
|
+
const mismatch = (0, provider_models_1.getProviderModelMismatchMessage)(provider, model);
|
|
1125
|
+
const modelLabel = model
|
|
1126
|
+
? mismatch
|
|
1127
|
+
? `${provider} [configured model: ${model}]`
|
|
1128
|
+
: `${provider} (${model})`
|
|
1129
|
+
: provider;
|
|
1130
|
+
const lines = [`${modelLabel} authentication failed.`];
|
|
1131
|
+
const cleanDetail = detail.replace(/\s+/g, " ").trim();
|
|
1132
|
+
if (cleanDetail)
|
|
1133
|
+
lines.push(`provider detail: ${cleanDetail.length > 300 ? `${cleanDetail.slice(0, 297)}...` : cleanDetail}`);
|
|
1134
|
+
lines.push("");
|
|
1135
|
+
lines.push("To keep using this provider:");
|
|
1136
|
+
lines.push(` 1. Run \`ouro auth --agent ${agentName} --provider ${provider}\``);
|
|
1137
|
+
if (mismatch) {
|
|
1138
|
+
const defaultModel = (0, provider_models_1.getDefaultModelForProvider)(provider);
|
|
1139
|
+
lines.push("");
|
|
1140
|
+
lines.push("Config warning:");
|
|
1141
|
+
lines.push(` - ${mismatch}`);
|
|
1142
|
+
lines.push(" - Repair the configured model with:");
|
|
1143
|
+
lines.push(` \`ouro use --agent ${agentName} --lane outward --provider ${provider} --model ${defaultModel}\``);
|
|
1144
|
+
lines.push(` \`ouro use --agent ${agentName} --lane inner --provider ${provider} --model ${defaultModel}\``);
|
|
1145
|
+
}
|
|
1146
|
+
lines.push("");
|
|
1147
|
+
lines.push(`To use another configured provider instead, run \`ouro use --agent ${agentName} --lane <outward|inner> --provider <provider> --model <model>\`.`);
|
|
1148
|
+
return lines.join("\n");
|
|
1149
|
+
}
|
|
433
1150
|
async function runAgent(messages, callbacks, channel, signal, options) {
|
|
434
|
-
|
|
1151
|
+
// engine.turn_summary (counts only; see turn-summary.ts) is emitted once however the turn ends, a throw included.
|
|
1152
|
+
const turnTally = new turn_summary_1.TurnTally();
|
|
1153
|
+
let result;
|
|
1154
|
+
try {
|
|
1155
|
+
result = await runCountedTurn(turnTally, messages, (0, turn_summary_1.tallyToolEnds)(callbacks, turnTally), channel, signal, options);
|
|
1156
|
+
return result;
|
|
1157
|
+
}
|
|
1158
|
+
finally {
|
|
1159
|
+
(0, turn_summary_1.emitTurnSummary)(turnTally, {
|
|
1160
|
+
channel,
|
|
1161
|
+
outcome: result?.outcome ?? "errored",
|
|
1162
|
+
errorClass: result ? result.errorClassification ?? "none" : "unknown",
|
|
1163
|
+
traceId: options?.traceId,
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
async function runCountedTurn(turnTally, messages, callbacks, channel, signal, options) {
|
|
1168
|
+
const generatedMessages = [];
|
|
1169
|
+
let nextAttemptControls = [];
|
|
1170
|
+
let rejectedAttempt = [];
|
|
1171
|
+
const pushGenerated = (...next) => {
|
|
1172
|
+
messages.push(...next);
|
|
1173
|
+
generatedMessages.push(...structuredClone(next));
|
|
1174
|
+
if (rejectedAttempt.length > 0) {
|
|
1175
|
+
rejectedAttempt = [];
|
|
1176
|
+
providerRuntime.resetTurnState(messages);
|
|
1177
|
+
}
|
|
1178
|
+
};
|
|
1179
|
+
const facing = (0, friends_1.channelToFacing)(channel);
|
|
1180
|
+
const owner = options?.toolContext?.agentName && options.toolContext.agentRoot
|
|
1181
|
+
? { agentName: options.toolContext.agentName, agentRoot: options.toolContext.agentRoot }
|
|
1182
|
+
: undefined;
|
|
1183
|
+
// Automatic fallback (opt-in via agent.json providerFallback): start on the first chain entry not cooling down.
|
|
1184
|
+
let providerRuntime = options?.providerRuntimeOverride ?? await getProviderRuntime(facing, owner);
|
|
1185
|
+
turnTally.route(providerRuntime.id, providerRuntime.model);
|
|
1186
|
+
const fallbackChain = options?.providerRuntimeOverride ? [] : resolveTurnFallbackChain(facing, owner);
|
|
1187
|
+
let chainIndex = 0;
|
|
1188
|
+
const switchToChainEntry = async (from, firstCandidate, reason) => {
|
|
1189
|
+
for (let candidate = firstCandidate; candidate !== null; candidate = (0, provider_fallback_1.nextReadyChainIndex)(fallbackChain, candidate)) {
|
|
1190
|
+
try {
|
|
1191
|
+
providerRuntime = await getChainEntryRuntime(fallbackChain[candidate], owner);
|
|
1192
|
+
turnTally.route(providerRuntime.id, providerRuntime.model);
|
|
1193
|
+
chainIndex = candidate;
|
|
1194
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1195
|
+
level: "warn",
|
|
1196
|
+
component: "engine",
|
|
1197
|
+
event: "engine.provider_fallback",
|
|
1198
|
+
message: reason ? "provider failed with an error the agent cannot fix; the turn carries on with the next provider" : "turn starts on a fallback provider while the primary cools down",
|
|
1199
|
+
meta: {
|
|
1200
|
+
lane: providerLaneForFacing(facing),
|
|
1201
|
+
fromProvider: fallbackChain[from].provider,
|
|
1202
|
+
fromModel: fallbackChain[from].model,
|
|
1203
|
+
toProvider: fallbackChain[candidate].provider,
|
|
1204
|
+
toModel: fallbackChain[candidate].model,
|
|
1205
|
+
classification: reason?.classification ?? "cooling-down",
|
|
1206
|
+
...(reason ? { error: reason.error.message.slice(0, 200) } : {}),
|
|
1207
|
+
},
|
|
1208
|
+
});
|
|
1209
|
+
return true;
|
|
1210
|
+
}
|
|
1211
|
+
catch (error) {
|
|
1212
|
+
(0, provider_fallback_1.coolDownProviderEntry)(fallbackChain[candidate], "auth-failure", error instanceof Error ? error : /* v8 ignore next @preserve */ new Error(String(error)));
|
|
1213
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1214
|
+
level: "warn",
|
|
1215
|
+
component: "engine",
|
|
1216
|
+
event: "engine.provider_fallback_unavailable",
|
|
1217
|
+
message: "fallback provider could not be built; trying the next one",
|
|
1218
|
+
meta: { provider: fallbackChain[candidate].provider, model: fallbackChain[candidate].model, error: error instanceof Error ? error.message : /* v8 ignore next @preserve */ String(error) },
|
|
1219
|
+
});
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
return false;
|
|
1223
|
+
};
|
|
1224
|
+
if (fallbackChain.length > 0) {
|
|
1225
|
+
const startIndex = (0, provider_fallback_1.firstReadyChainIndex)(fallbackChain);
|
|
1226
|
+
if (startIndex > 0)
|
|
1227
|
+
await switchToChainEntry(0, startIndex, null);
|
|
1228
|
+
}
|
|
1229
|
+
const rebuildCurrentRuntime = () => chainIndex === 0
|
|
1230
|
+
? getProviderRuntime(facing, owner)
|
|
1231
|
+
: getChainEntryRuntime(fallbackChain[chainIndex], owner);
|
|
1232
|
+
const fallBackAfterTerminalError = async (error, classification) => {
|
|
1233
|
+
if (fallbackChain.length === 0 || !(0, provider_fallback_1.fallsBackOn)(classification))
|
|
1234
|
+
return false;
|
|
1235
|
+
(0, provider_fallback_1.coolDownProviderEntry)(fallbackChain[chainIndex], classification, error);
|
|
1236
|
+
const from = chainIndex;
|
|
1237
|
+
if (!await switchToChainEntry(from, (0, provider_fallback_1.nextReadyChainIndex)(fallbackChain, from), { classification, error }))
|
|
1238
|
+
return false;
|
|
1239
|
+
providerRuntime.resetTurnState(messages);
|
|
1240
|
+
return true;
|
|
1241
|
+
};
|
|
1242
|
+
let servedByProvider = false;
|
|
435
1243
|
const provider = providerRuntime.id;
|
|
436
|
-
const toolChoiceRequired = options?.toolChoiceRequired ?? true;
|
|
1244
|
+
const toolChoiceRequired = options?.hardDisableTools ? false : options?.toolChoiceRequired ?? true;
|
|
437
1245
|
const traceId = options?.traceId;
|
|
438
1246
|
(0, runtime_1.emitNervesEvent)({
|
|
439
1247
|
event: "engine.turn_start",
|
|
@@ -452,24 +1260,88 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
452
1260
|
currentContext = { ...currentContext, friend: freshFriend };
|
|
453
1261
|
}
|
|
454
1262
|
}
|
|
1263
|
+
const turnOrientationFrame = options?.orientationFrame
|
|
1264
|
+
?? (channel ? (0, orientation_frame_1.buildOrientationFrame)({ channel, messages }) : undefined);
|
|
1265
|
+
if (options?.requiredPromptEvidence) {
|
|
1266
|
+
let structuralFloor;
|
|
1267
|
+
try {
|
|
1268
|
+
structuralFloor = (0, prompt_budget_1.assessRequiredPromptEvidenceBudget)({
|
|
1269
|
+
messages,
|
|
1270
|
+
requiredPromptEvidence: options.requiredPromptEvidence,
|
|
1271
|
+
provider: providerRuntime.id,
|
|
1272
|
+
model: providerRuntime.model,
|
|
1273
|
+
contextWindowTokens: (0, config_1.getContextConfig)(providerRuntime.model).maxTokens,
|
|
1274
|
+
});
|
|
1275
|
+
}
|
|
1276
|
+
catch (error) {
|
|
1277
|
+
const invalidEvidenceError = error instanceof Error ? error : new Error(String(error));
|
|
1278
|
+
callbacks.onError(invalidEvidenceError, "terminal");
|
|
1279
|
+
options.captureGeneratedMessages?.([]);
|
|
1280
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1281
|
+
event: "engine.turn_end",
|
|
1282
|
+
trace_id: traceId,
|
|
1283
|
+
component: "engine",
|
|
1284
|
+
message: "runAgent turn completed",
|
|
1285
|
+
meta: { done: true, sawPonder: false, sawQuerySession: false, sawBridgeManage: false },
|
|
1286
|
+
});
|
|
1287
|
+
return {
|
|
1288
|
+
outcome: "errored",
|
|
1289
|
+
error: invalidEvidenceError,
|
|
1290
|
+
errorClassification: "unknown",
|
|
1291
|
+
};
|
|
1292
|
+
}
|
|
1293
|
+
if (structuralFloor.status === "required_evidence_over_budget") {
|
|
1294
|
+
const budgetError = new Error(`required_evidence_over_budget: required current-turn evidence needs ${structuralFloor.estimatedTokens} tokens but the provider input limit is ${structuralFloor.budget.inputTokenLimit}`);
|
|
1295
|
+
callbacks.onError(budgetError, "terminal");
|
|
1296
|
+
options.captureGeneratedMessages?.([]);
|
|
1297
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1298
|
+
event: "engine.turn_end",
|
|
1299
|
+
trace_id: traceId,
|
|
1300
|
+
component: "engine",
|
|
1301
|
+
message: "runAgent turn completed",
|
|
1302
|
+
meta: { done: true, sawPonder: false, sawQuerySession: false, sawBridgeManage: false },
|
|
1303
|
+
});
|
|
1304
|
+
return {
|
|
1305
|
+
outcome: "errored",
|
|
1306
|
+
error: budgetError,
|
|
1307
|
+
errorClassification: "unknown",
|
|
1308
|
+
};
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
455
1311
|
// Refresh system prompt at start of each turn when channel is provided.
|
|
456
|
-
// If refresh fails,
|
|
457
|
-
// so
|
|
1312
|
+
// If refresh fails, retain only a recognised stable prefix (or inject a
|
|
1313
|
+
// minimal safe fallback) so stale dynamic state cannot regain authority.
|
|
1314
|
+
let structuredSystemPrompt;
|
|
458
1315
|
if (channel) {
|
|
459
1316
|
try {
|
|
460
1317
|
const buildSystemOptions = {
|
|
461
1318
|
...options,
|
|
1319
|
+
relationshipContextScopes: options?.toolContext?.relationshipAuthorization?.authorizedContextScopes,
|
|
1320
|
+
relationshipProfileId: options?.toolContext?.relationshipAuthorization?.profileId,
|
|
1321
|
+
orientationFrame: turnOrientationFrame,
|
|
1322
|
+
...(options?.toolContext?.delegatedCommand ? { delegatedCommand: options.toolContext.delegatedCommand } : {}),
|
|
1323
|
+
resumePriorWork: options?.resumePriorWork === true,
|
|
462
1324
|
providerCapabilities: providerRuntime.capabilities,
|
|
463
1325
|
supportedReasoningEfforts: providerRuntime.supportedReasoningEfforts,
|
|
464
1326
|
};
|
|
465
1327
|
const refreshed = await (0, prompt_1.buildSystem)(channel, buildSystemOptions, currentContext);
|
|
466
|
-
|
|
1328
|
+
structuredSystemPrompt = refreshed;
|
|
1329
|
+
upsertSystemPrompt(messages, (0, prompt_1.flattenSystemPrompt)(refreshed), [
|
|
1330
|
+
...(options?.promptOnlyEvidenceMessages ?? []),
|
|
1331
|
+
...(options?.requiredPromptEvidence?.verifiedPredecessorMessage
|
|
1332
|
+
? [options.requiredPromptEvidence.verifiedPredecessorMessage]
|
|
1333
|
+
: []),
|
|
1334
|
+
]);
|
|
467
1335
|
}
|
|
468
1336
|
catch (error) {
|
|
469
1337
|
const hadExistingSystemPrompt = messages[0]?.role === "system" && typeof messages[0].content === "string";
|
|
470
|
-
const
|
|
471
|
-
|
|
472
|
-
|
|
1338
|
+
const fallback = repairFallbackSystemPrompt(turnOrientationFrame);
|
|
1339
|
+
upsertSystemPrompt(messages, fallback, [
|
|
1340
|
+
...(options?.promptOnlyEvidenceMessages ?? []),
|
|
1341
|
+
...(options?.requiredPromptEvidence?.verifiedPredecessorMessage
|
|
1342
|
+
? [options.requiredPromptEvidence.verifiedPredecessorMessage]
|
|
1343
|
+
: []),
|
|
1344
|
+
]);
|
|
473
1345
|
(0, runtime_1.emitNervesEvent)({
|
|
474
1346
|
level: "warn",
|
|
475
1347
|
event: "mind.step_error",
|
|
@@ -484,13 +1356,23 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
484
1356
|
});
|
|
485
1357
|
}
|
|
486
1358
|
}
|
|
487
|
-
|
|
1359
|
+
if (channel && options?.skipKeptNotes !== true) {
|
|
1360
|
+
await (0, kept_notes_1.injectKeptNotes)(messages, {
|
|
1361
|
+
channel,
|
|
1362
|
+
friend: currentContext?.friend,
|
|
1363
|
+
judge: async (input) => (0, kept_notes_1.createKeptNotesJudge)(await getProviderRuntime("agent", owner), signal)(input),
|
|
1364
|
+
signal,
|
|
1365
|
+
traceId,
|
|
1366
|
+
});
|
|
1367
|
+
}
|
|
488
1368
|
let done = false;
|
|
489
1369
|
let lastUsage;
|
|
490
1370
|
let overflowRetried = false;
|
|
491
|
-
let
|
|
1371
|
+
let rejectedRequestRetried = false;
|
|
1372
|
+
let replayedReasoningDropped = false;
|
|
492
1373
|
let outcome = "settled";
|
|
493
1374
|
let completion;
|
|
1375
|
+
let suspension;
|
|
494
1376
|
let terminalError;
|
|
495
1377
|
let terminalErrorClassification;
|
|
496
1378
|
let sawSteeringFollowUp = false;
|
|
@@ -498,548 +1380,1749 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
498
1380
|
let currentReasoningEffort = "medium";
|
|
499
1381
|
let sawSendMessageSelf = false;
|
|
500
1382
|
let sawPonder = false;
|
|
1383
|
+
let sawSettleContentMismatch = false;
|
|
501
1384
|
let sawQuerySession = false;
|
|
502
1385
|
let sawBridgeManage = false;
|
|
503
1386
|
let sawExternalStateQuery = false;
|
|
504
|
-
const
|
|
505
|
-
//
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
const
|
|
512
|
-
//
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
//
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
outcome = "superseded";
|
|
552
|
-
break;
|
|
553
|
-
}
|
|
554
|
-
if (steeringFollowUps.some((followUp) => followUp.effect === "set_no_handoff")) {
|
|
555
|
-
mustResolveBeforeHandoffActive = true;
|
|
556
|
-
options?.setMustResolveBeforeHandoff?.(true);
|
|
557
|
-
}
|
|
558
|
-
sawSteeringFollowUp = true;
|
|
559
|
-
for (const followUp of steeringFollowUps) {
|
|
560
|
-
messages.push({ role: "user", content: followUp.text });
|
|
561
|
-
}
|
|
562
|
-
providerRuntime.resetTurnState(messages);
|
|
563
|
-
}
|
|
564
|
-
// Yield so pending I/O (stdin Ctrl-C) can be processed between iterations
|
|
565
|
-
await new Promise((r) => setImmediate(r));
|
|
566
|
-
if (signal?.aborted) {
|
|
567
|
-
outcome = "aborted";
|
|
568
|
-
break;
|
|
1387
|
+
const turnToolRecords = [];
|
|
1388
|
+
// The engine pushes its own user messages mid-turn (steering, retry nudges); the person's turn ends where this one began.
|
|
1389
|
+
const turnStartLength = messages.length;
|
|
1390
|
+
let groundingRejections = 0;
|
|
1391
|
+
let brevityRejections = 0;
|
|
1392
|
+
let shelfRejections = 0;
|
|
1393
|
+
let lastRealDraft = null;
|
|
1394
|
+
const privateReturnHeldTokens = new Set();
|
|
1395
|
+
// Once-per-turn flag for the fresh-work rest gate. Without this, an agent
|
|
1396
|
+
// that called rest, was told "fresh work arrived", processed the items,
|
|
1397
|
+
// and called rest again would get the same message forever — the gate
|
|
1398
|
+
// condition is read from the turn-start snapshot of pendingMessages,
|
|
1399
|
+
// which doesn't update mid-turn. The agent only needs to be told once;
|
|
1400
|
+
// after that, repeated rest attempts mean they've acknowledged.
|
|
1401
|
+
let freshWorkGateFired = false;
|
|
1402
|
+
// Once-per-turn flag for the unsent-surface rest gate: the agent is told once
|
|
1403
|
+
// that a person it meant to tell was not reached; a second rest is its answer.
|
|
1404
|
+
let surfaceNotSentGateFired = false;
|
|
1405
|
+
// Counter for no-tool-call violations. MiniMax reasoning models occasionally
|
|
1406
|
+
// emit only a <think>...</think> block and stop, without any tool call — even
|
|
1407
|
+
// when tool_choice is set to "required". Private-return requests also need
|
|
1408
|
+
// a hard no-tool guard: a text-only "queued" acknowledgement is false unless
|
|
1409
|
+
// a ponder packet created the return obligation in this turn.
|
|
1410
|
+
let noToolCallRetries = 0;
|
|
1411
|
+
const NO_TOOL_CALL_MAX_RETRIES = 2;
|
|
1412
|
+
let unresolvedHistoricalEffects = [];
|
|
1413
|
+
let historicalToolFailureRetries = 0;
|
|
1414
|
+
let providerIterations = 0;
|
|
1415
|
+
// Adaptive step budget: starts at the base, grows while tool calls make progress.
|
|
1416
|
+
let stepBudget = exports.MAX_PROVIDER_ITERATIONS;
|
|
1417
|
+
const stepBudgetCeiling = Math.max(exports.MAX_PROVIDER_ITERATIONS, (0, config_1.getContextConfig)().maxStepsPerTurn ?? exports.MAX_PROVIDER_ITERATIONS_CEILING);
|
|
1418
|
+
// The iteration whose tool calls last made progress. The budget grows when any of the last few iterations did, so one
|
|
1419
|
+
// step without progress at the boundary (a speak, a check that exits 1, a rejected call) does not end a working turn.
|
|
1420
|
+
let lastProgressIteration = 0;
|
|
1421
|
+
const progressedRecently = () => lastProgressIteration > 0 && lastProgressIteration >= providerIterations - exports.STEP_BUDGET_EXTENSION;
|
|
1422
|
+
let stepReportIteration = null;
|
|
1423
|
+
// The one tool a turn may call after its step budget is used up: settle for conversations, rest for private turns.
|
|
1424
|
+
let stepReportTool = "settle";
|
|
1425
|
+
// A pre-dispatch contract check may reject the same call twice in a turn; after that it is advisory, so a check no call can satisfy never traps the turn.
|
|
1426
|
+
const requiredDispatchRejectionCounts = new Map();
|
|
1427
|
+
const budgetExhausted = () => {
|
|
1428
|
+
if (providerIterations < stepBudget)
|
|
1429
|
+
return false;
|
|
1430
|
+
if (progressedRecently() && stepBudget < stepBudgetCeiling) {
|
|
1431
|
+
stepBudget = Math.min(stepBudgetCeiling, stepBudget + exports.STEP_BUDGET_EXTENSION);
|
|
1432
|
+
(0, runtime_1.emitNervesEvent)({ component: "engine", event: "engine.step_budget_extended", message: "tool progress extended the per-turn step budget", meta: { stepBudget } });
|
|
1433
|
+
return providerIterations >= stepBudget;
|
|
569
1434
|
}
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
1435
|
+
return true;
|
|
1436
|
+
};
|
|
1437
|
+
// After this iteration's calls: how many later steps will run tools if nothing more makes progress, told to the model
|
|
1438
|
+
// once that is STEP_BUDGET_NOTICE_AT or fewer, so a prepared change is not cut off by a stop it never saw coming.
|
|
1439
|
+
const nearBudgetNotice = (toolNames) => {
|
|
1440
|
+
// The next boundary is the first later step that reaches the budget; it extends only if this or an earlier step's
|
|
1441
|
+
// progress still falls in its window, and a second extension is never earned without new progress.
|
|
1442
|
+
const boundary = Math.max(providerIterations + 1, stepBudget);
|
|
1443
|
+
const grows = lastProgressIteration > 0 && lastProgressIteration >= boundary - exports.STEP_BUDGET_EXTENSION && stepBudget < stepBudgetCeiling;
|
|
1444
|
+
const budget = grows ? Math.min(stepBudgetCeiling, stepBudget + exports.STEP_BUDGET_EXTENSION) : stepBudget;
|
|
1445
|
+
const left = Math.max(0, budget - providerIterations - 1);
|
|
1446
|
+
if (left > exports.STEP_BUDGET_NOTICE_AT)
|
|
1447
|
+
return null;
|
|
1448
|
+
const wrapUpTool = toolNames.has("settle") ? "settle" : toolNames.has("rest") ? "rest" : null;
|
|
1449
|
+
if (!wrapUpTool)
|
|
1450
|
+
return null;
|
|
1451
|
+
return stepBudgetNotice(left, stepBudgetCeiling - providerIterations - 1, wrapUpTool);
|
|
1452
|
+
};
|
|
1453
|
+
// Adds the note, when there is one, to the last result the model gets for this step's batch.
|
|
1454
|
+
const withBudgetNote = (content, isLast, toolNames) => {
|
|
1455
|
+
const note = isLast && stepReportIteration === null ? nearBudgetNotice(toolNames) : null;
|
|
1456
|
+
return note ? `${content}\n\n${note}` : content;
|
|
1457
|
+
};
|
|
1458
|
+
const requiredToolCallNames = [...new Set(options?.requiredToolCalls?.names ?? [])];
|
|
1459
|
+
const dispatchedRequiredToolCalls = new Set();
|
|
1460
|
+
const rejectAttempt = (assistant, controls) => {
|
|
1461
|
+
rejectedAttempt = [structuredClone(assistant)];
|
|
1462
|
+
nextAttemptControls = controls;
|
|
1463
|
+
};
|
|
1464
|
+
// Answer gates run only for agents that opt in (ToolContext.answerGates), on every reply the person would receive: a settle answer
|
|
1465
|
+
// and a plain-text reply with no tool call alike (alpha.886 replay: a plain-text reply skipped them and an invented cast went out).
|
|
1466
|
+
// A request-specific contract (options.requiredToolCalls) already validates its own terminal answer. Each gate has its own bounded
|
|
1467
|
+
// retry, and none spends the last provider iteration.
|
|
1468
|
+
// A rejected reply never reaches the person, and neither does the runtime's note about it: the retry gets the reason as a private
|
|
1469
|
+
// note, and a retry that only talks about that note is replaced by the last real draft (2026-10-11: "got it. dummy bad, no markdown,
|
|
1470
|
+
// no question at the end. just plain answer, cap it." went to Sam).
|
|
1471
|
+
// `replacement` is the text to deliver instead of the answer, with any disclosure already applied; null delivers the answer as is.
|
|
1472
|
+
const answerGateVerdict = (answer, intent) => {
|
|
1473
|
+
if (lastRealDraft !== null && GATE_NOTE_ECHO.test(answer)) {
|
|
1474
|
+
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "engine", event: "engine.answer_gate_echo_replaced", message: "a retry talked about the runtime's note instead of answering; delivering the last real draft", meta: { length: answer.length } });
|
|
1475
|
+
return { error: null, replacement: disclosed(lastRealDraft, answerGateCheck(lastRealDraft, intent, true)) };
|
|
1476
|
+
}
|
|
1477
|
+
const verdict = answerGateCheck(answer, intent, false);
|
|
1478
|
+
if (verdict.error) {
|
|
1479
|
+
lastRealDraft = answer;
|
|
1480
|
+
return { error: privateGateNote(verdict.error), replacement: null };
|
|
1481
|
+
}
|
|
1482
|
+
const delivered = disclosed(answer, verdict);
|
|
1483
|
+
return { error: null, replacement: delivered === answer ? null : delivered };
|
|
1484
|
+
};
|
|
1485
|
+
const disclosed = (answer, verdict) => {
|
|
1486
|
+
const shelfChecked = verdict.shelfUnverified ? (0, shelf_claims_1.withShelfDisclosure)(answer, turnToolRecords) : answer;
|
|
1487
|
+
return verdict.unverifiedNames ? (0, source_grounding_1.withUnverifiedDisclosure)(shelfChecked, verdict.unverifiedNames) : shelfChecked;
|
|
1488
|
+
};
|
|
1489
|
+
// `final` grades a draft that is going out regardless: nothing is rejected, and what would have been is disclosed instead.
|
|
1490
|
+
const answerGateCheck = (answer, intent, final) => {
|
|
1491
|
+
const gates = options?.requiredToolCalls ? undefined : options?.toolContext?.answerGates;
|
|
1492
|
+
const retriesLeft = !final && providerIterations < stepBudget - 1;
|
|
1493
|
+
let groundingError = null;
|
|
1494
|
+
let unverifiedNames = null;
|
|
1495
|
+
const grounding = gates?.sourceGrounding ? (0, source_grounding_1.sourceGroundingFinding)({ answer, userText: userTexts(messages).join("\n"), latestUserText: latestUserMessageText(messages.slice(0, turnStartLength)), knownText: priorTurnsText(messages.slice(0, turnStartLength)), tools: turnToolRecords }) : null;
|
|
1496
|
+
if (grounding) {
|
|
1497
|
+
if (groundingRejections < ANSWER_GATE_MAX_REJECTIONS && retriesLeft) {
|
|
1498
|
+
groundingRejections += 1;
|
|
1499
|
+
groundingError = grounding.message;
|
|
1500
|
+
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "engine", event: "engine.answer_gate_rejected", message: "answer named things from a work that the turn did not look up; sending the model back", meta: { gate: "source_grounding", rejection: groundingRejections, cap: ANSWER_GATE_MAX_REJECTIONS, lookupsRun: grounding.lookups } });
|
|
1501
|
+
}
|
|
1502
|
+
else {
|
|
1503
|
+
unverifiedNames = grounding.names;
|
|
1504
|
+
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "engine", event: "engine.answer_gate_disclosed", message: "unsourced names survived the retries; delivering with a disclosure", meta: { gate: "source_grounding", names: grounding.names.length } });
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
let shelfError = null;
|
|
1508
|
+
let shelfUnverified = false;
|
|
1509
|
+
const shelfFinding = !groundingError && gates?.shelfClaims ? (0, shelf_claims_1.shelfClaimError)(answer, turnToolRecords) : null;
|
|
1510
|
+
if (shelfFinding && shelfRejections < ANSWER_STYLE_MAX_RETRIES && retriesLeft) {
|
|
1511
|
+
shelfRejections += 1;
|
|
1512
|
+
shelfError = shelfFinding;
|
|
1513
|
+
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "engine", event: "engine.answer_gate_rejected", message: "answer said something is on the shelf that no lookup this turn found there; sending the model back", meta: { gate: "shelf_claims", rejection: shelfRejections, cap: ANSWER_STYLE_MAX_RETRIES } });
|
|
1514
|
+
}
|
|
1515
|
+
else if (shelfFinding) {
|
|
1516
|
+
shelfUnverified = true;
|
|
1517
|
+
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "engine", event: "engine.answer_gate_disclosed", message: "an unbacked shelf claim survived the retry; delivering with a disclosure", meta: { gate: "shelf_claims" } });
|
|
1518
|
+
}
|
|
1519
|
+
let brevityError = null;
|
|
1520
|
+
if (!groundingError && !shelfError && gates?.brevity && !options?.toolContext?.context?.isGroupChat && brevityRejections < ANSWER_STYLE_MAX_RETRIES && retriesLeft
|
|
1521
|
+
&& (0, reply_style_1.briefStyleRequested)(userTexts(messages), (0, reply_style_1.savedCommunicationPreference)(options?.toolContext?.context?.friend))) {
|
|
1522
|
+
brevityError = (0, reply_style_1.briefStyleViolation)(answer, intent);
|
|
1523
|
+
if (brevityError) {
|
|
1524
|
+
brevityRejections += 1;
|
|
1525
|
+
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "engine", event: "engine.answer_gate_rejected", message: "answer broke the person's brevity request; sending the model back", meta: { gate: "brevity", rejection: brevityRejections, cap: ANSWER_STYLE_MAX_RETRIES } });
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
return { error: groundingError ?? shelfError ?? brevityError, unverifiedNames, shelfUnverified };
|
|
1529
|
+
};
|
|
1530
|
+
// The tools this step offered, so a whole-batch rejection can carry the step-budget note too.
|
|
1531
|
+
let budgetNoteToolNames = new Set();
|
|
1532
|
+
const rejectToolBatch = (assistant, reasons) => {
|
|
1533
|
+
const calls = assistant.tool_calls;
|
|
1534
|
+
rejectAttempt(assistant, calls.map((call, index) => ({
|
|
1535
|
+
role: "tool", tool_call_id: call.id, content: withBudgetNote(reasons[index], index === calls.length - 1, budgetNoteToolNames),
|
|
1536
|
+
})));
|
|
1537
|
+
};
|
|
1538
|
+
const pendingRequiredToolCalls = () => {
|
|
1539
|
+
const missing = requiredToolCallNames.filter((name) => !dispatchedRequiredToolCalls.has(name));
|
|
1540
|
+
return missing.length > 0
|
|
1541
|
+
? { missing, message: `${options.requiredToolCalls.retryMessage} Missing required tool calls: ${missing.join(", ")}.` }
|
|
1542
|
+
: null;
|
|
1543
|
+
};
|
|
1544
|
+
const queueRequiredCorrection = (assistant, message, limitContext) => {
|
|
1545
|
+
if (budgetExhausted())
|
|
1546
|
+
throw new Error(`provider iteration limit exhausted at response ${stepBudget} ${limitContext}`);
|
|
1547
|
+
// A rejected tool call (settle, a terminal tool) is answered by its own tool result, so the agent reads why and corrects course.
|
|
1548
|
+
if (assistant.tool_calls?.length)
|
|
1549
|
+
rejectToolBatch(assistant, assistant.tool_calls.map(() => message));
|
|
1550
|
+
else
|
|
1551
|
+
rejectAttempt(assistant, [{ role: "user", content: message }]);
|
|
1552
|
+
};
|
|
1553
|
+
const toolLoopState = (0, tool_loop_1.createToolLoopState)();
|
|
1554
|
+
const toolFrictionLedger = (0, tool_friction_1.createToolFrictionLedger)();
|
|
1555
|
+
const finishTerminalProviderError = (error, classification) => {
|
|
1556
|
+
terminalError = error;
|
|
1557
|
+
terminalErrorClassification = classification;
|
|
1558
|
+
/* v8 ignore start — auth-failure guidance: tested via provider error classification tests @preserve */
|
|
1559
|
+
if (terminalErrorClassification === "auth-failure") {
|
|
1560
|
+
const agentName = (0, identity_2.getAgentName)();
|
|
1561
|
+
const currentProvider = providerRuntime.id;
|
|
1562
|
+
callbacks.onError(new Error(buildAuthFailureGuidance(currentProvider, providerRuntime.model, agentName, terminalError.message)), "terminal");
|
|
1563
|
+
}
|
|
1564
|
+
else {
|
|
1565
|
+
callbacks.onError(terminalError, "terminal");
|
|
1566
|
+
}
|
|
1567
|
+
/* v8 ignore stop */
|
|
1568
|
+
const errorDetails = (0, error_classification_1.extractProviderErrorDetails)(terminalError);
|
|
1569
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1570
|
+
level: "error",
|
|
1571
|
+
event: "engine.error",
|
|
1572
|
+
trace_id: traceId,
|
|
1573
|
+
component: "engine",
|
|
1574
|
+
message: terminalError.message,
|
|
1575
|
+
meta: {
|
|
1576
|
+
provider: providerRuntime.id,
|
|
1577
|
+
model: providerRuntime.model,
|
|
1578
|
+
errorClassification: terminalErrorClassification,
|
|
1579
|
+
...(errorDetails.status !== undefined ? { httpStatus: errorDetails.status } : {}),
|
|
1580
|
+
...(errorDetails.bodyExcerpt ? { bodyExcerpt: errorDetails.bodyExcerpt } : {}),
|
|
1581
|
+
summary: (0, error_classification_1.summarizeProviderError)(terminalError, terminalErrorClassification, providerRuntime.id, providerRuntime.model),
|
|
1582
|
+
},
|
|
1583
|
+
});
|
|
1584
|
+
// Only legacy input can still contain unaccepted calls. Generated output
|
|
1585
|
+
// has crossed acceptance; a later provider failure cannot revoke effects.
|
|
1586
|
+
if (generatedMessages.length === 0)
|
|
1587
|
+
stripLastToolCalls(messages);
|
|
1588
|
+
outcome = "errored";
|
|
1589
|
+
done = true;
|
|
1590
|
+
};
|
|
1591
|
+
// Prevent MaxListenersExceeded warning — each iteration adds a listener
|
|
1592
|
+
try {
|
|
1593
|
+
require("events").setMaxListeners(50, signal);
|
|
1594
|
+
}
|
|
1595
|
+
catch { /* unsupported */ }
|
|
1596
|
+
try {
|
|
1597
|
+
const toolPreferences = currentContext?.friend?.toolPreferences;
|
|
1598
|
+
const filterTrustedTools = (tools, selected) => tools.filter((tool) => !selected.engine.some((engine) => engine.function.name === tool.function.name)
|
|
1599
|
+
&& (channel !== "inner" || options?.toolProfile === "sanctuary-health-private" || !["send_message", "surface"].includes(tool.function.name)
|
|
1600
|
+
|| selected.ordinary.some((definition) => definition.tool.function.name === tool.function.name)));
|
|
1601
|
+
const selectCurrentTools = () => {
|
|
1602
|
+
if (options?.hardDisableTools)
|
|
1603
|
+
return Object.freeze({ ordinary: Object.freeze([]), engine: Object.freeze([]) });
|
|
1604
|
+
const selected = (0, tools_1.selectToolsForChannel)(channel ? (0, friends_1.getChannelCapabilities)(channel) : undefined, toolPreferences, currentContext, providerRuntime.capabilities, options?.mcpManager, providerRuntime.model, { ...options?.toolContext, ...(options?.habitSession ? { habitSession: options.habitSession } : {}) });
|
|
1605
|
+
const ordinary = options?.tools !== undefined && !options.toolContext?.relationshipAuthorization
|
|
1606
|
+
? filterTrustedTools(options.tools, selected).flatMap((tool) => {
|
|
1607
|
+
const definition = (0, tools_1.resolveToolDefinition)(tool.function.name, selected) ?? (0, tools_1.resolveToolDefinition)(tool.function.name);
|
|
1608
|
+
return definition ? [{ ...definition, tool }] : [];
|
|
1609
|
+
})
|
|
1610
|
+
: selected.ordinary;
|
|
1611
|
+
const bound = bindCurrentIngressEvidenceLocator(ordinary.map((definition) => definition.tool), options?.toolContext?.currentIngressEvidence);
|
|
1612
|
+
return Object.freeze({
|
|
1613
|
+
ordinary: Object.freeze(ordinary.map((definition, index) => definition.tool === bound[index]
|
|
1614
|
+
? definition : Object.freeze({ ...definition, tool: bound[index] }))),
|
|
1615
|
+
engine: selected.engine,
|
|
581
1616
|
});
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
role: "assistant",
|
|
589
|
-
};
|
|
590
|
-
if (result.content)
|
|
591
|
-
msg.content = result.content;
|
|
592
|
-
if (result.toolCalls.length)
|
|
593
|
-
msg.tool_calls = result.toolCalls.map((tc) => ({
|
|
594
|
-
id: tc.id,
|
|
595
|
-
type: "function",
|
|
596
|
-
function: { name: tc.name, arguments: tc.arguments },
|
|
597
|
-
}));
|
|
598
|
-
// Store reasoning items from the API response on the assistant message
|
|
599
|
-
// so they persist through session save/load and can be restored in toResponsesInput
|
|
600
|
-
const reasoningItems = result.outputItems.filter((item) => "type" in item && item.type === "reasoning");
|
|
601
|
-
if (reasoningItems.length > 0) {
|
|
602
|
-
msg._reasoning_items = reasoningItems;
|
|
1617
|
+
};
|
|
1618
|
+
let toolSelection = selectCurrentTools();
|
|
1619
|
+
const relationship = options?.toolContext?.relationshipAuthorization;
|
|
1620
|
+
if (!options?.hardDisableTools && options?.tools !== undefined) {
|
|
1621
|
+
if (relationship) {
|
|
1622
|
+
toolSelection = (0, tools_1.reduceToolSelection)(toolSelection, options.tools);
|
|
603
1623
|
}
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
1624
|
+
}
|
|
1625
|
+
const unboundBaseTools = !options?.hardDisableTools && !relationship && options?.tools
|
|
1626
|
+
? filterTrustedTools(options.tools, toolSelection)
|
|
1627
|
+
: toolSelection.ordinary.map((definition) => definition.tool);
|
|
1628
|
+
const relationshipToolNames = options?.toolContext?.relationshipAuthorization?.advertisedToolNames;
|
|
1629
|
+
const relationshipScopedTools = relationshipToolNames
|
|
1630
|
+
? unboundBaseTools.filter((tool) => relationshipToolNames.includes(tool.function.name))
|
|
1631
|
+
: unboundBaseTools;
|
|
1632
|
+
const baseTools = bindCurrentIngressEvidenceLocator(relationshipScopedTools, options?.toolContext?.currentIngressEvidence);
|
|
1633
|
+
// Augment tool context with reasoning effort controls from provider
|
|
1634
|
+
const baseToolContext = options?.toolContext
|
|
1635
|
+
?? { signin: async () => undefined, ...(turnOrientationFrame ? { orientationFrame: turnOrientationFrame } : {}) };
|
|
1636
|
+
const habitSession = options?.habitSession ?? baseToolContext?.habitSession;
|
|
1637
|
+
const augmentedToolContext = {
|
|
1638
|
+
...baseToolContext,
|
|
1639
|
+
supportedReasoningEfforts: providerRuntime.supportedReasoningEfforts,
|
|
1640
|
+
setReasoningEffort: (level) => { currentReasoningEffort = level; },
|
|
1641
|
+
activeWorkFrame: options?.activeWorkFrame,
|
|
1642
|
+
orientationFrame: turnOrientationFrame ?? baseToolContext.orientationFrame,
|
|
1643
|
+
...(habitSession ? { habitSession } : {}),
|
|
1644
|
+
toolSelection,
|
|
1645
|
+
selectCurrentTools,
|
|
1646
|
+
};
|
|
1647
|
+
const trustedToolContext = options?.toolContext || turnOrientationFrame || habitSession ? augmentedToolContext : undefined;
|
|
1648
|
+
// For one call: executeTool calls beforeHandler only once its guards pass, just before the handler runs.
|
|
1649
|
+
const withDispatchNotice = (context, name) => ({
|
|
1650
|
+
...context,
|
|
1651
|
+
beforeHandler: () => callbacks.onToolDispatch?.(name),
|
|
1652
|
+
});
|
|
1653
|
+
unresolvedHistoricalEffects = historicalFailedEffectsForExactRepeatedRequest(messages, toolSelection);
|
|
1654
|
+
// Rebase provider-owned turn state from canonical messages at user-turn start.
|
|
1655
|
+
// This prevents stale provider caches from replaying prior-turn context.
|
|
1656
|
+
providerRuntime.resetTurnState(messages);
|
|
1657
|
+
const loadedDeferredTools = [];
|
|
1658
|
+
const ordinaryDefinitionsByName = new Map(toolSelection.ordinary.map((definition) => [definition.tool.function.name, definition]));
|
|
1659
|
+
while (!done) {
|
|
1660
|
+
// Channel-based tool filtering:
|
|
1661
|
+
// - Private runtime: exclude send_message (delivery via surface), observe (no one to observe)
|
|
1662
|
+
// - All outward channels (1:1, group, reaction): observe available
|
|
1663
|
+
//
|
|
1664
|
+
// ponder, settle/rest, surface, and observe are always assembled based on channel context.
|
|
1665
|
+
// ponder is available in ALL channels (outer: think privately, inner: keep turning).
|
|
1666
|
+
// Private runtime gets restTool instead of settleTool (rest = end turn, gated by attention queue).
|
|
1667
|
+
// toolChoiceRequired only controls whether tool_choice: "required" is set in the API call.
|
|
1668
|
+
const isPrivateRuntimeChannel = channel === "inner";
|
|
1669
|
+
const unscopedOrdinaryActiveTools = [
|
|
1670
|
+
...baseTools,
|
|
1671
|
+
...toolSelection.engine,
|
|
1672
|
+
];
|
|
1673
|
+
const scopedOrdinaryActiveTools = relationshipToolNames
|
|
1674
|
+
? unscopedOrdinaryActiveTools.filter((tool) => relationshipToolNames.includes(tool.function.name))
|
|
1675
|
+
: unscopedOrdinaryActiveTools;
|
|
1676
|
+
// The catalog narrows only what is advertised; the scoped list above is still the authority on what may exist.
|
|
1677
|
+
// Doors whose card isn't eager wait for find_tools (or a skill that declares them).
|
|
1678
|
+
// A caller that hands the turn its own tool list has already chosen the menu, so only the default selection defers.
|
|
1679
|
+
const deferralPossible = !options?.hardDisableTools && options?.tools === undefined && options?.toolProfile !== "sanctuary-health-private";
|
|
1680
|
+
const deferralKeep = new Set(requiredToolCallNames);
|
|
1681
|
+
for (const effect of unresolvedHistoricalEffects)
|
|
1682
|
+
deferralKeep.add(effect.name);
|
|
1683
|
+
const toolCatalog = (0, tool_catalog_1.buildToolCatalog)(scopedOrdinaryActiveTools.map((tool) => {
|
|
1684
|
+
const definition = ordinaryDefinitionsByName.get(tool.function.name);
|
|
1685
|
+
return { tool, ax: definition?.ax, mcpServer: definition?.mcpServer };
|
|
1686
|
+
}));
|
|
1687
|
+
const deferralPool = deferralPossible ? (0, tool_catalog_1.partitionCatalog)(scopedOrdinaryActiveTools, toolCatalog, [], deferralKeep).deferred : [];
|
|
1688
|
+
const deferralHistory = deferralPossible ? (0, tool_catalog_1.namesLoadedInHistory)(messages, new Set(deferralPool.map((tool) => tool.function.name))) : [];
|
|
1689
|
+
const ordinaryActiveTools = deferralPossible
|
|
1690
|
+
? (0, tool_catalog_1.partitionCatalog)(scopedOrdinaryActiveTools, toolCatalog, [...new Set([...loadedDeferredTools, ...deferralHistory])], deferralKeep).active
|
|
1691
|
+
: scopedOrdinaryActiveTools;
|
|
1692
|
+
const candidateActiveTools = options?.hardDisableTools
|
|
1693
|
+
? []
|
|
1694
|
+
: options?.toolProfile === "sanctuary-health-private"
|
|
1695
|
+
? (() => {
|
|
1696
|
+
const sendTools = baseTools.filter((tool) => tool.function.name === "send_message");
|
|
1697
|
+
if (channel !== "inner" || sendTools.length !== 1 || baseTools.length !== 1) {
|
|
1698
|
+
throw new Error("sanctuary-health-private requires inner channel with exactly one canonical send_message definition");
|
|
1699
|
+
}
|
|
1700
|
+
return [sendTools[0], tools_1.restTool];
|
|
1701
|
+
})()
|
|
1702
|
+
: ordinaryActiveTools;
|
|
1703
|
+
const candidateToolNames = new Set(candidateActiveTools.map((tool) => tool.function.name));
|
|
1704
|
+
turnTally.offer(candidateActiveTools, deferralPool, ordinaryDefinitionsByName);
|
|
1705
|
+
budgetNoteToolNames = candidateToolNames;
|
|
1706
|
+
const unadvertisedRequiredTool = requiredToolCallNames.find((name) => !candidateToolNames.has(name));
|
|
1707
|
+
if (unadvertisedRequiredTool) {
|
|
1708
|
+
(0, runtime_1.emitNervesEvent)({ level: "error", component: "engine", event: "engine.required_tool_unadvertised", message: "required tool is not advertised for the active channel", meta: { toolName: unadvertisedRequiredTool, channel: String(channel) } });
|
|
1709
|
+
throw new Error(`required tool is not advertised for this channel: ${unadvertisedRequiredTool}`);
|
|
608
1710
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
1711
|
+
const forcedHistoricalToolNames = new Set(unresolvedHistoricalEffects
|
|
1712
|
+
.map((effect) => effect.name)
|
|
1713
|
+
.filter((name) => candidateToolNames.has(name)));
|
|
1714
|
+
const forcingHistoricalEffect = forcedHistoricalToolNames.size > 0;
|
|
1715
|
+
const activeTools = stepReportIteration !== null
|
|
1716
|
+
? candidateActiveTools.filter((tool) => tool.function.name === stepReportTool)
|
|
1717
|
+
: forcingHistoricalEffect
|
|
1718
|
+
? candidateActiveTools.filter((tool) => forcedHistoricalToolNames.has(tool.function.name))
|
|
1719
|
+
: candidateActiveTools;
|
|
1720
|
+
const activeToolNames = new Set(activeTools.map((tool) => tool.function.name));
|
|
1721
|
+
const steeringFollowUps = options?.drainSteeringFollowUps?.() ?? [];
|
|
1722
|
+
if (steeringFollowUps.length > 0) {
|
|
1723
|
+
const hasSupersedingFollowUp = steeringFollowUps.some((followUp) => followUp.effect === "clear_and_supersede");
|
|
1724
|
+
if (hasSupersedingFollowUp) {
|
|
1725
|
+
mustResolveBeforeHandoffActive = false;
|
|
1726
|
+
options?.setMustResolveBeforeHandoff?.(false);
|
|
1727
|
+
outcome = "superseded";
|
|
1728
|
+
break;
|
|
1729
|
+
}
|
|
1730
|
+
if (steeringFollowUps.some((followUp) => followUp.effect === "set_no_handoff")) {
|
|
1731
|
+
mustResolveBeforeHandoffActive = true;
|
|
1732
|
+
options?.setMustResolveBeforeHandoff?.(true);
|
|
1733
|
+
}
|
|
1734
|
+
sawSteeringFollowUp = true;
|
|
1735
|
+
for (const followUp of steeringFollowUps) {
|
|
1736
|
+
messages.push({ role: "user", content: followUp.text });
|
|
1737
|
+
}
|
|
1738
|
+
providerRuntime.resetTurnState(messages);
|
|
614
1739
|
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
done = true;
|
|
1740
|
+
// Yield so pending I/O (stdin Ctrl-C) can be processed between iterations
|
|
1741
|
+
await new Promise((r) => setImmediate(r));
|
|
1742
|
+
if (signal?.aborted) {
|
|
1743
|
+
outcome = "aborted";
|
|
1744
|
+
break;
|
|
621
1745
|
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
1746
|
+
try {
|
|
1747
|
+
const budgetOptions = {
|
|
1748
|
+
requiredPromptEvidence: options?.requiredPromptEvidence,
|
|
1749
|
+
provider: providerRuntime.id,
|
|
1750
|
+
model: providerRuntime.model,
|
|
1751
|
+
contextWindowTokens: (0, config_1.getContextConfig)(providerRuntime.model).maxTokens,
|
|
1752
|
+
};
|
|
1753
|
+
const canonicalBudget = (0, prompt_budget_1.applyPromptBudget)({ ...budgetOptions, messages });
|
|
1754
|
+
const currentUserMessage = budgetOptions.requiredPromptEvidence?.currentUserMessage
|
|
1755
|
+
?? canonicalBudget.messages.findLast((message) => message.role === "user");
|
|
1756
|
+
// Keep retry controls attached to the genuine request, not to canonical history.
|
|
1757
|
+
let attemptMessages = rejectedAttempt.length > 0
|
|
1758
|
+
? [...(0, prompt_budget_1.applyPromptBudget)({
|
|
1759
|
+
...budgetOptions,
|
|
1760
|
+
requiredPromptEvidence: budgetOptions.requiredPromptEvidence ?? (currentUserMessage ? { currentUserMessage } : undefined),
|
|
1761
|
+
messages: [...canonicalBudget.messages, ...rejectedAttempt, ...nextAttemptControls],
|
|
1762
|
+
}).messages]
|
|
1763
|
+
: [...canonicalBudget.messages];
|
|
1764
|
+
// Whatever path built this request, every tool call reaches the provider with a result: a gap the runtime left must
|
|
1765
|
+
// never 400 the turn and leave the agent unable to answer.
|
|
1766
|
+
repairOrphanedToolCalls(attemptMessages);
|
|
1767
|
+
const currentTurnStart = () => currentUserMessage ? Math.max(0, attemptMessages.indexOf(currentUserMessage)) : 0;
|
|
1768
|
+
if (replayedReasoningDropped)
|
|
1769
|
+
attemptMessages = dropReplayedReasoning(attemptMessages, currentTurnStart());
|
|
1770
|
+
if (rejectedAttempt.length > 0 || canonicalBudget.status !== "within_budget" || replayedReasoningDropped)
|
|
1771
|
+
providerRuntime.resetTurnState(attemptMessages);
|
|
1772
|
+
const turnCallbackBufferRef = { current: null };
|
|
1773
|
+
const callProviderTurn = async () => {
|
|
1774
|
+
callbacks.onModelStart();
|
|
1775
|
+
turnCallbackBufferRef.current = habitSession
|
|
1776
|
+
? createHabitCallbackBuffer(callbacks)
|
|
1777
|
+
: callbacks.settleOutputMode === "final_only" || relationship !== undefined
|
|
1778
|
+
? createFinalOnlyTextBuffer(callbacks)
|
|
1779
|
+
: null;
|
|
1780
|
+
try {
|
|
1781
|
+
return await providerRuntime.streamTurn({
|
|
1782
|
+
messages: attemptMessages,
|
|
1783
|
+
activeTools,
|
|
1784
|
+
// A step narrowed to one tool (a step report, a forced repeat) sends no held-back doors either.
|
|
1785
|
+
...(deferralPool.length > 0 && activeTools === candidateActiveTools ? { deferredTools: deferralPool } : {}),
|
|
1786
|
+
callbacks: turnCallbackBufferRef.current?.callbacks ?? callbacks,
|
|
1787
|
+
signal,
|
|
1788
|
+
traceId,
|
|
1789
|
+
toolChoiceRequired: options?.hardDisableTools ? false : forcingHistoricalEffect || toolChoiceRequired,
|
|
1790
|
+
reasoningEffort: currentReasoningEffort,
|
|
1791
|
+
eagerSettleStreaming: true,
|
|
1792
|
+
systemPrompt: structuredSystemPrompt,
|
|
1793
|
+
});
|
|
628
1794
|
}
|
|
629
|
-
catch {
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
if (isInnerDialog && attentionQueue && attentionQueue.length > 0) {
|
|
636
|
-
callbacks.onToolEnd("settle", (0, tools_1.summarizeArgs)("settle", settleArgs), false);
|
|
637
|
-
callbacks.onClearText?.();
|
|
638
|
-
messages.push(msg);
|
|
639
|
-
const gateMessage = "you're holding thoughts someone is waiting for — surface them before you settle.";
|
|
640
|
-
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: gateMessage });
|
|
641
|
-
providerRuntime.appendToolOutput(result.toolCalls[0].id, gateMessage);
|
|
642
|
-
continue;
|
|
1795
|
+
catch (error) {
|
|
1796
|
+
turnCallbackBufferRef.current?.discard();
|
|
1797
|
+
turnCallbackBufferRef.current = null;
|
|
1798
|
+
if (signal?.aborted)
|
|
1799
|
+
throw new provider_attempt_1.ProviderAttemptAbortError();
|
|
1800
|
+
throw error;
|
|
643
1801
|
}
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
if (isInnerDialog) {
|
|
649
|
-
callbacks.onToolEnd("settle", (0, tools_1.summarizeArgs)("settle", settleArgs), true);
|
|
650
|
-
messages.push(msg);
|
|
651
|
-
const settled = "(settled)";
|
|
652
|
-
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: settled });
|
|
653
|
-
providerRuntime.appendToolOutput(result.toolCalls[0].id, settled);
|
|
654
|
-
outcome = "settled";
|
|
655
|
-
done = true;
|
|
656
|
-
continue;
|
|
1802
|
+
};
|
|
1803
|
+
const callProviderTurnWithOverflowRecovery = async () => {
|
|
1804
|
+
try {
|
|
1805
|
+
return await callProviderTurn();
|
|
657
1806
|
}
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
1807
|
+
catch (error) {
|
|
1808
|
+
if (error instanceof provider_attempt_1.ProviderAttemptAbortError)
|
|
1809
|
+
throw error;
|
|
1810
|
+
if (isContextOverflow(error) && !overflowRetried) {
|
|
1811
|
+
overflowRetried = true;
|
|
1812
|
+
const protectedStart = currentUserMessage ? Math.max(0, attemptMessages.indexOf(currentUserMessage)) : 0;
|
|
1813
|
+
const currentAttempt = attemptMessages.slice(protectedStart);
|
|
1814
|
+
const overflowMessages = attemptMessages.slice(0, protectedStart).map((message) => message.role === "assistant" ? { ...message } : message);
|
|
1815
|
+
stripLastToolCalls(overflowMessages);
|
|
1816
|
+
overflowMessages.push(...currentAttempt);
|
|
1817
|
+
const { maxTokens, contextMargin } = (0, config_1.getContextConfig)(providerRuntime.model);
|
|
1818
|
+
const trimmed = (0, context_1.trimMessages)(overflowMessages, maxTokens, contextMargin, maxTokens * 2);
|
|
1819
|
+
const requiredEvidence = options?.requiredPromptEvidence;
|
|
1820
|
+
const requiredMessages = new Set([
|
|
1821
|
+
...(requiredEvidence?.verifiedPredecessorMessage ? [requiredEvidence.verifiedPredecessorMessage] : []),
|
|
1822
|
+
...currentAttempt,
|
|
1823
|
+
]);
|
|
1824
|
+
const trimmedMessages = new Set(trimmed);
|
|
1825
|
+
attemptMessages = requiredMessages.size === 0
|
|
1826
|
+
? trimmed
|
|
1827
|
+
: overflowMessages.filter((message) => trimmedMessages.has(message) || requiredMessages.has(message));
|
|
1828
|
+
providerRuntime.resetTurnState(attemptMessages);
|
|
1829
|
+
callbacks.onError(new Error("context trimmed, retrying..."), "transient");
|
|
1830
|
+
return callProviderTurn();
|
|
675
1831
|
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
1832
|
+
// A 400 for spent credit is not a malformed request: correcting history cannot fix it.
|
|
1833
|
+
if (isRejectedRequest(error) && !rejectedRequestRetried && providerRuntime.classifyError(error) !== "usage-limit") {
|
|
1834
|
+
// Never leave the agent unable to answer: correct what the runtime sent, tell the agent why, and let it carry on.
|
|
1835
|
+
rejectedRequestRetried = true;
|
|
1836
|
+
replayedReasoningDropped = true;
|
|
1837
|
+
const detail = error.message;
|
|
1838
|
+
attemptMessages = dropReplayedReasoning(attemptMessages, currentTurnStart());
|
|
1839
|
+
repairOrphanedToolCalls(attemptMessages);
|
|
1840
|
+
attemptMessages = [...attemptMessages, {
|
|
1841
|
+
role: "user",
|
|
1842
|
+
content: `[runtime] The provider refused my last request (${detail}). The runtime dropped reasoning replayed from earlier turns and closed any tool call left without a result. I carry on with the turn from here.`,
|
|
1843
|
+
}];
|
|
1844
|
+
providerRuntime.resetTurnState(attemptMessages);
|
|
1845
|
+
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "engine", event: "engine.rejected_request_recovered", message: "provider refused the request; retrying once with corrected history", meta: { provider: providerRuntime.id, model: providerRuntime.model, detail: String(detail).slice(0, 300) } });
|
|
1846
|
+
callbacks.onError(new Error("provider refused the request, correcting and retrying..."), "transient");
|
|
1847
|
+
return callProviderTurn();
|
|
682
1848
|
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
1849
|
+
throw error;
|
|
1850
|
+
}
|
|
1851
|
+
};
|
|
1852
|
+
const attempt = await (0, provider_attempt_1.runProviderAttempt)({
|
|
1853
|
+
operation: "turn",
|
|
1854
|
+
provider: providerRuntime.id,
|
|
1855
|
+
model: providerRuntime.model,
|
|
1856
|
+
run: callProviderTurnWithOverflowRecovery,
|
|
1857
|
+
classifyError: (error) => providerRuntime.classifyError(error),
|
|
1858
|
+
// Spent credit will not come back in seconds: move straight to the next provider when one is ready.
|
|
1859
|
+
shouldRetry: (classification) => classification !== "usage-limit" || (0, provider_fallback_1.nextReadyChainIndex)(fallbackChain, chainIndex) === null,
|
|
1860
|
+
onRetry: async (record, maxAttempts) => {
|
|
1861
|
+
const delayMs = record.delayMs;
|
|
1862
|
+
const seconds = delayMs / 1000;
|
|
1863
|
+
const cause = RETRY_LABELS[record.classification];
|
|
1864
|
+
try {
|
|
1865
|
+
const agentName = owner?.agentName ?? (0, identity_2.getAgentName)();
|
|
1866
|
+
if (record.provider === "openai-codex" && record.classification === "auth-failure") {
|
|
1867
|
+
await (0, openai_codex_token_1.refreshOpenAICodexProviderCredentials)(agentName, {
|
|
1868
|
+
force: true,
|
|
1869
|
+
reason: "turn-auth-failure",
|
|
1870
|
+
});
|
|
1871
|
+
}
|
|
1872
|
+
await (0, provider_credentials_1.refreshProviderCredentialPool)(agentName, {
|
|
1873
|
+
preserveCachedOnFailure: true,
|
|
1874
|
+
providers: [record.provider],
|
|
1875
|
+
});
|
|
1876
|
+
_providerRuntimeFactories[facing] = null;
|
|
1877
|
+
providerRuntime = await rebuildCurrentRuntime();
|
|
1878
|
+
providerRuntime.resetTurnState(attemptMessages);
|
|
688
1879
|
}
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
1880
|
+
catch (refreshError) {
|
|
1881
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1882
|
+
level: "warn",
|
|
1883
|
+
component: "engine",
|
|
1884
|
+
event: "engine.provider_retry_refresh_failed",
|
|
1885
|
+
message: "provider credential refresh failed during retry",
|
|
1886
|
+
meta: { provider: record.provider, model: record.model, reason: refreshError instanceof Error ? refreshError.message : String(refreshError) },
|
|
1887
|
+
});
|
|
695
1888
|
}
|
|
1889
|
+
callbacks.onError(new Error(`${cause}, retrying in ${seconds}s (${record.attempt}/${maxAttempts})...`), "transient");
|
|
1890
|
+
},
|
|
1891
|
+
sleep: async (delayMs) => {
|
|
1892
|
+
await waitForProviderRetry(delayMs, signal);
|
|
1893
|
+
providerRuntime.resetTurnState(attemptMessages);
|
|
1894
|
+
},
|
|
1895
|
+
});
|
|
1896
|
+
if (!attempt.ok) {
|
|
1897
|
+
if (await fallBackAfterTerminalError(attempt.error, attempt.classification))
|
|
1898
|
+
continue;
|
|
1899
|
+
finishTerminalProviderError(attempt.error, attempt.classification);
|
|
1900
|
+
continue;
|
|
1901
|
+
}
|
|
1902
|
+
const result = attempt.value;
|
|
1903
|
+
servedByProvider = true;
|
|
1904
|
+
nextAttemptControls = [];
|
|
1905
|
+
providerIterations += 1;
|
|
1906
|
+
turnTally.step(result.usage, providerRuntime.id, providerRuntime.model);
|
|
1907
|
+
if (stepReportIteration !== null) {
|
|
1908
|
+
// The progress-report call is the last one: it must settle (or rest), or the turn errors.
|
|
1909
|
+
const settledReport = result.toolCalls.length === 1 && result.toolCalls[0].name === stepReportTool;
|
|
1910
|
+
if (providerIterations > stepReportIteration || (result.toolCalls.length > 0 && !settledReport)) {
|
|
1911
|
+
throw new Error(`provider iteration limit exhausted at response ${providerIterations} before the progress report settled`);
|
|
696
1912
|
}
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
1913
|
+
}
|
|
1914
|
+
const streamCallbackBuffer = turnCallbackBufferRef.current;
|
|
1915
|
+
turnCallbackBufferRef.current = null;
|
|
1916
|
+
// Track usage from the latest API call
|
|
1917
|
+
if (result.usage)
|
|
1918
|
+
lastUsage = result.usage;
|
|
1919
|
+
// SHARED: build CC-format assistant message from TurnResult
|
|
1920
|
+
const msg = {
|
|
1921
|
+
role: "assistant",
|
|
1922
|
+
};
|
|
1923
|
+
// Persist assistant content WITHOUT inline <think>...</think> blocks.
|
|
1924
|
+
// Reasoning content already routed through onReasoningChunk for live
|
|
1925
|
+
// surfacing and persisted separately as `_reasoning_items` for
|
|
1926
|
+
// providers that support a reasoning channel; saving it inline AND
|
|
1927
|
+
// alongside tool_calls causes MiniMax to reject the replayed turn
|
|
1928
|
+
// with "tool result's tool id not found" (error code 2013) because
|
|
1929
|
+
// it can't reconcile reasoning-with-tools in the same assistant
|
|
1930
|
+
// message. Strip aggressively at persist so the next replay is
|
|
1931
|
+
// clean; preserve the original reasoning trace on the message via
|
|
1932
|
+
// `_inline_reasoning` so debug/audit paths can still see it.
|
|
1933
|
+
if (result.content) {
|
|
1934
|
+
const stripped = stripThinkBlocksForViolationCheck(result.content);
|
|
1935
|
+
if (stripped.length > 0)
|
|
1936
|
+
msg.content = stripped;
|
|
1937
|
+
if (stripped.length !== result.content.length) {
|
|
1938
|
+
msg._inline_reasoning = result.content;
|
|
1939
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1940
|
+
level: "info",
|
|
1941
|
+
component: "engine",
|
|
1942
|
+
event: "engine.inline_reasoning_stripped",
|
|
1943
|
+
message: "stripped inline <think> blocks from persisted assistant message; preserved on _inline_reasoning",
|
|
1944
|
+
meta: {
|
|
1945
|
+
provider: providerRuntime.id,
|
|
1946
|
+
model: providerRuntime.model,
|
|
1947
|
+
originalLength: result.content.length,
|
|
1948
|
+
strippedLength: stripped.length,
|
|
1949
|
+
},
|
|
1950
|
+
});
|
|
708
1951
|
}
|
|
1952
|
+
}
|
|
1953
|
+
if (result.toolCalls.length)
|
|
1954
|
+
msg.tool_calls = result.toolCalls.map((tc) => ({
|
|
1955
|
+
id: tc.id,
|
|
1956
|
+
type: "function",
|
|
1957
|
+
function: { name: tc.name, arguments: tc.arguments },
|
|
1958
|
+
}));
|
|
1959
|
+
// Store reasoning items from the API response on the assistant message
|
|
1960
|
+
// so they persist through session save/load and can be restored in toResponsesInput
|
|
1961
|
+
const reasoningItems = result.outputItems.filter((item) => "type" in item && item.type === "reasoning");
|
|
1962
|
+
if (reasoningItems.length > 0) {
|
|
1963
|
+
msg._reasoning_items = reasoningItems;
|
|
1964
|
+
}
|
|
1965
|
+
// Store thinking blocks (Anthropic) on the assistant message for round-tripping
|
|
1966
|
+
const thinkingItems = result.outputItems.filter((item) => "type" in item && (item.type === "thinking" || item.type === "redacted_thinking"));
|
|
1967
|
+
if (thinkingItems.length > 0) {
|
|
1968
|
+
msg._thinking_blocks = thinkingItems;
|
|
1969
|
+
}
|
|
1970
|
+
if (result.settleFinalization && !result.settleFinalization.ok) {
|
|
1971
|
+
// An unparseable settle is the agent's own output: nothing reached anyone, so the agent reads why and settles again.
|
|
1972
|
+
// Retractable callbacks have already cleared; core-owned callback buffers are discarded with the attempt.
|
|
1973
|
+
streamCallbackBuffer?.discard();
|
|
1974
|
+
queueRequiredCorrection(msg, `settle was not delivered: its arguments did not parse (${result.settleFinalization.errorCode}). Call settle again with valid JSON arguments.`, "after an unparseable settle");
|
|
709
1975
|
continue;
|
|
710
1976
|
}
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
return JSON.parse(result.toolCalls[0].arguments);
|
|
1977
|
+
const settlingNow = result.toolCalls.length === 1 && (result.toolCalls[0].name === "settle" || result.toolCalls[0].name === "rest");
|
|
1978
|
+
if (stepReportIteration === null && result.toolCalls.length > 0 && !settlingNow && budgetExhausted()) {
|
|
1979
|
+
const wrapUpTool = candidateToolNames.has("settle") ? "settle" : candidateToolNames.has("rest") ? "rest" : null;
|
|
1980
|
+
if (!wrapUpTool) {
|
|
1981
|
+
throw new Error(`provider iteration limit exhausted at response ${stepBudget} before tool execution`);
|
|
717
1982
|
}
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
meta: { ...(reason ? { reason } : {}) },
|
|
730
|
-
});
|
|
731
|
-
callbacks.onToolEnd("observe", (0, tools_1.summarizeArgs)("observe", observeArgs), true);
|
|
732
|
-
messages.push(msg);
|
|
733
|
-
const silenced = "(silenced)";
|
|
734
|
-
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: silenced });
|
|
735
|
-
providerRuntime.appendToolOutput(result.toolCalls[0].id, silenced);
|
|
736
|
-
outcome = "observed";
|
|
737
|
-
done = true;
|
|
1983
|
+
// Do not error into the reply: give the model one settle-only (or rest-only) call to report progress.
|
|
1984
|
+
streamCallbackBuffer?.discard();
|
|
1985
|
+
stepReportIteration = providerIterations + 1;
|
|
1986
|
+
stepReportTool = wrapUpTool;
|
|
1987
|
+
rejectAttempt(msg, [
|
|
1988
|
+
...result.toolCalls.map((tc) => ({ role: "tool", tool_call_id: tc.id, content: "not executed: the step budget for this turn is used up." })),
|
|
1989
|
+
{ role: "user", content: wrapUpTool === "settle" ? STEP_BUDGET_REPORT_INSTRUCTION : STEP_BUDGET_REST_INSTRUCTION },
|
|
1990
|
+
]);
|
|
1991
|
+
callbacks.onClearText?.();
|
|
1992
|
+
turnTally.stepBudgetExhausted();
|
|
1993
|
+
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "engine", event: "engine.step_budget_exhausted", message: `step budget used up; requesting a ${wrapUpTool}-only progress report`, meta: { stepBudget, providerIterations } });
|
|
738
1994
|
continue;
|
|
739
1995
|
}
|
|
740
|
-
//
|
|
741
|
-
const
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
1996
|
+
// Phase annotation for Codex provider
|
|
1997
|
+
const hasPhaseAnnotation = providerRuntime.capabilities.has("phase-annotation");
|
|
1998
|
+
const isSoleSettle = result.toolCalls.length === 1 && result.toolCalls[0].name === "settle";
|
|
1999
|
+
if (hasPhaseAnnotation) {
|
|
2000
|
+
msg.phase = isSoleSettle ? "settle" : "commentary";
|
|
2001
|
+
}
|
|
2002
|
+
// Detect the MiniMax "only-thinking, no tool call" violation: no tool
|
|
2003
|
+
// calls returned, and the content is empty after stripping
|
|
2004
|
+
// <think>...</think> blocks. This is a narrow check — legitimate
|
|
2005
|
+
// content-only responses (text without think tags, or text outside
|
|
2006
|
+
// think tags) still flow through the original "no tool calls →
|
|
2007
|
+
// accept as-is" path so existing channels and tests are unaffected.
|
|
2008
|
+
const onlyThinkContent = !result.toolCalls.length
|
|
2009
|
+
&& typeof result.content === "string"
|
|
2010
|
+
&& stripThinkBlocksForViolationCheck(result.content).length === 0
|
|
2011
|
+
&& result.content.length > 0;
|
|
2012
|
+
const privateReturnTextAckRetryError = !result.toolCalls.length
|
|
2013
|
+
? privateReturnMissingPonderError({
|
|
2014
|
+
latestUserRequest: latestUserMessageText(messages),
|
|
2015
|
+
answer: stripThinkBlocksForViolationCheck(result.content),
|
|
2016
|
+
sawPonder,
|
|
2017
|
+
})
|
|
2018
|
+
: null;
|
|
2019
|
+
if (!result.toolCalls.length) {
|
|
2020
|
+
if (forcingHistoricalEffect) {
|
|
2021
|
+
streamCallbackBuffer?.discard();
|
|
2022
|
+
callbacks.onClearText?.();
|
|
2023
|
+
const retryableHistoricalTools = [...forcedHistoricalToolNames];
|
|
2024
|
+
if (historicalToolFailureRetries >= NO_TOOL_CALL_MAX_RETRIES) {
|
|
2025
|
+
const blockedAnswer = "I could not finish the change that failed earlier: I didn't manage to try it again this time, so it is not done.";
|
|
2026
|
+
(0, runtime_1.emitNervesEvent)({
|
|
2027
|
+
level: "warn",
|
|
2028
|
+
component: "engine",
|
|
2029
|
+
event: "engine.historical_tool_failure_retry",
|
|
2030
|
+
message: "unresolved historical effect exhausted deterministic tool-call retries; failing closed",
|
|
2031
|
+
meta: { provider: providerRuntime.id, model: providerRuntime.model, toolNames: retryableHistoricalTools, cap: NO_TOOL_CALL_MAX_RETRIES },
|
|
2032
|
+
});
|
|
2033
|
+
pushGenerated({ role: "assistant", content: blockedAnswer });
|
|
2034
|
+
callbacks.onTextChunk(blockedAnswer);
|
|
2035
|
+
completion = { answer: blockedAnswer, intent: "blocked" };
|
|
2036
|
+
outcome = "blocked";
|
|
2037
|
+
done = true;
|
|
761
2038
|
continue;
|
|
762
2039
|
}
|
|
763
|
-
|
|
2040
|
+
historicalToolFailureRetries += 1;
|
|
2041
|
+
(0, runtime_1.emitNervesEvent)({
|
|
2042
|
+
level: "warn",
|
|
2043
|
+
component: "engine",
|
|
2044
|
+
event: "engine.historical_tool_failure_retry",
|
|
2045
|
+
message: "unresolved historical effect returned no tool call; forcing another exact-effect attempt",
|
|
2046
|
+
meta: {
|
|
2047
|
+
provider: providerRuntime.id,
|
|
2048
|
+
model: providerRuntime.model,
|
|
2049
|
+
toolNames: retryableHistoricalTools,
|
|
2050
|
+
attempt: historicalToolFailureRetries,
|
|
2051
|
+
cap: NO_TOOL_CALL_MAX_RETRIES,
|
|
2052
|
+
},
|
|
2053
|
+
});
|
|
2054
|
+
rejectAttempt(msg, [{
|
|
2055
|
+
role: "user",
|
|
2056
|
+
content: `this exact request previously reached a tool that is advertised again now. Its unresolved historical effect is through ${retryableHistoricalTools.join(", ")}. Only that tool is available now. Read current state if needed, then retry the exact failed effect. Do not report completion until the effect succeeds.`,
|
|
2057
|
+
}]);
|
|
2058
|
+
continue;
|
|
2059
|
+
}
|
|
2060
|
+
const requiredToolCallsGate = pendingRequiredToolCalls();
|
|
2061
|
+
if (requiredToolCallsGate) {
|
|
2062
|
+
streamCallbackBuffer?.discard();
|
|
764
2063
|
callbacks.onClearText?.();
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
currentObligation: options?.currentObligation ?? null,
|
|
773
|
-
outwardClosureRequired: options?.delegationDecision?.outwardClosureRequired ?? false,
|
|
2064
|
+
queueRequiredCorrection(msg, requiredToolCallsGate.message, "before required tool calls completed");
|
|
2065
|
+
(0, runtime_1.emitNervesEvent)({
|
|
2066
|
+
level: "warn",
|
|
2067
|
+
component: "engine",
|
|
2068
|
+
event: "engine.required_tool_calls_pending",
|
|
2069
|
+
message: "terminal response rejected until required tool handlers dispatch",
|
|
2070
|
+
meta: { missingToolNames: requiredToolCallsGate.missing },
|
|
774
2071
|
});
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
delegatedFrom: {
|
|
803
|
-
friendId: currentSession.friendId,
|
|
804
|
-
channel: currentSession.channel,
|
|
805
|
-
key: currentSession.key,
|
|
2072
|
+
continue;
|
|
2073
|
+
}
|
|
2074
|
+
const requiredAnswerRejection = options?.requiredToolCalls?.validateTerminalAnswer?.(String(msg.content ?? ""));
|
|
2075
|
+
if (requiredAnswerRejection) {
|
|
2076
|
+
streamCallbackBuffer?.discard();
|
|
2077
|
+
callbacks.onClearText?.();
|
|
2078
|
+
queueRequiredCorrection(msg, requiredAnswerRejection, "before required terminal answer validation completed");
|
|
2079
|
+
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "engine", event: "engine.required_tool_answer_rejected", message: "unsupported terminal answer rejected after required reads", meta: { answerLength: String(msg.content ?? "").length } });
|
|
2080
|
+
continue;
|
|
2081
|
+
}
|
|
2082
|
+
if (privateReturnTextAckRetryError) {
|
|
2083
|
+
streamCallbackBuffer?.discard();
|
|
2084
|
+
callbacks.onClearText?.();
|
|
2085
|
+
if (noToolCallRetries < NO_TOOL_CALL_MAX_RETRIES) {
|
|
2086
|
+
noToolCallRetries++;
|
|
2087
|
+
(0, runtime_1.emitNervesEvent)({
|
|
2088
|
+
level: "warn",
|
|
2089
|
+
component: "engine",
|
|
2090
|
+
event: "engine.no_tool_call_retry",
|
|
2091
|
+
message: "model returned a text-only private-return acknowledgement without ponder; retrying with corrective nudge",
|
|
2092
|
+
meta: {
|
|
2093
|
+
attempt: noToolCallRetries,
|
|
2094
|
+
cap: NO_TOOL_CALL_MAX_RETRIES,
|
|
2095
|
+
provider: providerRuntime.id,
|
|
2096
|
+
model: providerRuntime.model,
|
|
2097
|
+
reason: "private_return_missing_ponder",
|
|
2098
|
+
contentLength: result.content.length,
|
|
806
2099
|
},
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
try {
|
|
814
|
-
await (0, socket_client_1.requestInnerWake)((0, identity_2.getAgentName)());
|
|
2100
|
+
});
|
|
2101
|
+
rejectAttempt(msg, [{
|
|
2102
|
+
role: "user",
|
|
2103
|
+
content: `${privateReturnTextAckRetryError} Emit the ponder(action=create, ...) tool call now, or ask a blocking clarification without saying the private work is queued.`,
|
|
2104
|
+
}]);
|
|
2105
|
+
continue;
|
|
815
2106
|
}
|
|
816
|
-
|
|
817
|
-
callbacks.onToolEnd("ponder", (0, tools_1.summarizeArgs)("ponder", parsedArgs), true);
|
|
818
|
-
sawPonder = true;
|
|
819
|
-
messages.push(msg);
|
|
820
|
-
const ack = "(pondering)";
|
|
821
|
-
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: ack });
|
|
822
|
-
providerRuntime.appendToolOutput(result.toolCalls[0].id, ack);
|
|
2107
|
+
const blockedAnswer = "I could not start the private pass. No private-attention packet was created, so no return work was queued.";
|
|
823
2108
|
(0, runtime_1.emitNervesEvent)({
|
|
2109
|
+
level: "error",
|
|
824
2110
|
component: "engine",
|
|
825
|
-
event: "engine.
|
|
826
|
-
message: "
|
|
827
|
-
meta: {
|
|
2111
|
+
event: "engine.private_return_missing_ponder_blocked",
|
|
2112
|
+
message: "private-return text acknowledgement skipped ponder through the retry cap; failing closed",
|
|
2113
|
+
meta: {
|
|
2114
|
+
cap: NO_TOOL_CALL_MAX_RETRIES,
|
|
2115
|
+
provider: providerRuntime.id,
|
|
2116
|
+
model: providerRuntime.model,
|
|
2117
|
+
contentLength: result.content.length,
|
|
2118
|
+
},
|
|
828
2119
|
});
|
|
2120
|
+
pushGenerated({ role: "assistant", content: blockedAnswer });
|
|
2121
|
+
callbacks.onTextChunk(blockedAnswer);
|
|
2122
|
+
completion = { answer: blockedAnswer, intent: "blocked" };
|
|
2123
|
+
outcome = "blocked";
|
|
2124
|
+
done = true;
|
|
2125
|
+
continue;
|
|
829
2126
|
}
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
content: "continuing to think...",
|
|
839
|
-
timestamp: Date.now(),
|
|
840
|
-
};
|
|
841
|
-
(0, pending_1.queuePendingMessage)(pendingDir, envelope);
|
|
842
|
-
callbacks.onToolEnd("ponder", (0, tools_1.summarizeArgs)("ponder", parsedArgs), true);
|
|
843
|
-
sawPonder = true;
|
|
844
|
-
messages.push(msg);
|
|
845
|
-
const ack = "(pondering)";
|
|
846
|
-
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: ack });
|
|
847
|
-
providerRuntime.appendToolOutput(result.toolCalls[0].id, ack);
|
|
2127
|
+
if (onlyThinkContent && toolChoiceRequired && noToolCallRetries < NO_TOOL_CALL_MAX_RETRIES) {
|
|
2128
|
+
streamCallbackBuffer?.discard();
|
|
2129
|
+
// Provider-level violation: tool_choice was required, model emitted
|
|
2130
|
+
// only a <think>...</think> block (or empty content) with no tool
|
|
2131
|
+
// call. Retry with a corrective nudge up to NO_TOOL_CALL_MAX_RETRIES
|
|
2132
|
+
// times. After cap, accept as-is (the readback path strips think
|
|
2133
|
+
// tags and surfaces a clear diagnostic).
|
|
2134
|
+
noToolCallRetries++;
|
|
848
2135
|
(0, runtime_1.emitNervesEvent)({
|
|
2136
|
+
level: "warn",
|
|
849
2137
|
component: "engine",
|
|
850
|
-
event: "engine.
|
|
851
|
-
message: "
|
|
852
|
-
meta: {
|
|
2138
|
+
event: "engine.no_tool_call_retry",
|
|
2139
|
+
message: "model returned only <think> content with no tool call despite tool_choice=required; retrying with corrective nudge",
|
|
2140
|
+
meta: {
|
|
2141
|
+
attempt: noToolCallRetries,
|
|
2142
|
+
cap: NO_TOOL_CALL_MAX_RETRIES,
|
|
2143
|
+
provider: providerRuntime.id,
|
|
2144
|
+
model: providerRuntime.model,
|
|
2145
|
+
contentLength: result.content.length,
|
|
2146
|
+
},
|
|
853
2147
|
});
|
|
2148
|
+
rejectAttempt(msg, [{
|
|
2149
|
+
role: "user",
|
|
2150
|
+
content: isPrivateRuntimeChannel
|
|
2151
|
+
? augmentedToolContext?.noSend === true
|
|
2152
|
+
? "no tool was called this turn. this is an immutable no-send turn; call rest now without creating a continuation."
|
|
2153
|
+
: "no tool was called this turn. you must end every turn by calling rest (or surface, ponder, observe). emit the tool call now."
|
|
2154
|
+
: "no tool was called this turn. you must end every turn by calling settle with your answer (or ponder/observe). emit the tool call now.",
|
|
2155
|
+
}]);
|
|
2156
|
+
continue;
|
|
854
2157
|
}
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
return JSON.parse(result.toolCalls[0].arguments);
|
|
2158
|
+
// A plain-text reply reaches the person just as a settle answer does, so the answer gates hold it too.
|
|
2159
|
+
const textAnswer = isPrivateRuntimeChannel ? "" : stripThinkBlocksForViolationCheck(result.content).trim();
|
|
2160
|
+
const textVerdict = textAnswer ? answerGateVerdict(textAnswer) : null;
|
|
2161
|
+
if (textVerdict?.error) {
|
|
2162
|
+
streamCallbackBuffer?.discard();
|
|
2163
|
+
callbacks.onClearText?.();
|
|
2164
|
+
rejectAttempt(msg, [{ role: "user", content: textVerdict.error }]);
|
|
2165
|
+
continue;
|
|
864
2166
|
}
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
if (attentionQueue && attentionQueue.length > 0) {
|
|
872
|
-
callbacks.onToolEnd("rest", (0, tools_1.summarizeArgs)("rest", restArgs), false);
|
|
873
|
-
messages.push(msg);
|
|
874
|
-
const gateMessage = "you're holding thoughts someone is waiting for — surface them before you rest.";
|
|
875
|
-
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: gateMessage });
|
|
876
|
-
providerRuntime.appendToolOutput(result.toolCalls[0].id, gateMessage);
|
|
2167
|
+
if (textVerdict?.replacement) {
|
|
2168
|
+
streamCallbackBuffer?.discard();
|
|
2169
|
+
callbacks.onClearText?.();
|
|
2170
|
+
callbacks.onTextChunk(textVerdict.replacement);
|
|
2171
|
+
pushGenerated({ ...msg, content: textVerdict.replacement });
|
|
2172
|
+
done = true;
|
|
877
2173
|
continue;
|
|
878
2174
|
}
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: ack });
|
|
883
|
-
providerRuntime.appendToolOutput(result.toolCalls[0].id, ack);
|
|
884
|
-
(0, runtime_1.emitNervesEvent)({
|
|
885
|
-
component: "engine",
|
|
886
|
-
event: "engine.rested",
|
|
887
|
-
message: "resting until next heartbeat",
|
|
888
|
-
meta: {},
|
|
889
|
-
});
|
|
890
|
-
outcome = "rested";
|
|
2175
|
+
// Legitimate text-only response, or cap reached — accept as-is.
|
|
2176
|
+
await streamCallbackBuffer?.flush();
|
|
2177
|
+
pushGenerated(msg);
|
|
891
2178
|
done = true;
|
|
892
|
-
continue;
|
|
893
2179
|
}
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
//
|
|
900
|
-
const
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
2180
|
+
else {
|
|
2181
|
+
// Reset the retry counter on any successful tool call.
|
|
2182
|
+
noToolCallRetries = 0;
|
|
2183
|
+
const preCallMessages = structuredClone(messages.filter((message) => message.role !== "system"));
|
|
2184
|
+
// A held-back door called by name (find_tools's description lists every one) counts as found: it is checked
|
|
2185
|
+
// against its own schema, runs, and stays loaded. A step narrowed to one tool admits none.
|
|
2186
|
+
const calledHeldBack = activeTools === candidateActiveTools
|
|
2187
|
+
? deferralPool.filter((tool) => !activeToolNames.has(tool.function.name) && result.toolCalls.some((call) => call.name === tool.function.name))
|
|
2188
|
+
: [];
|
|
2189
|
+
// Not advertised means not yet loaded, so each is new to the loaded list.
|
|
2190
|
+
for (const tool of calledHeldBack)
|
|
2191
|
+
loadedDeferredTools.push(tool.function.name);
|
|
2192
|
+
const callableTools = [...activeTools, ...calledHeldBack];
|
|
2193
|
+
const callableToolNames = new Set(callableTools.map((tool) => tool.function.name));
|
|
2194
|
+
const validatedCalls = validateToolCallBatchAtProductionBoundary(result.toolCalls, callableTools);
|
|
2195
|
+
const invalidCall = validatedCalls.find((entry) => "error" in entry);
|
|
2196
|
+
if (invalidCall) {
|
|
2197
|
+
streamCallbackBuffer?.discard();
|
|
2198
|
+
const unadvertisedCall = validatedCalls.find((entry) => !callableToolNames.has(entry.call.name));
|
|
2199
|
+
const rejections = [];
|
|
2200
|
+
for (const entry of validatedCalls) {
|
|
2201
|
+
const detail = "error" in entry ? entry.error : "another call in this batch had invalid arguments";
|
|
2202
|
+
const rejection = unadvertisedCall
|
|
2203
|
+
? (0, tools_base_1.withCode)(`rejected: ${entry.call.name} was not advertised for this channel; no handler was executed.`, "unknown-tool")
|
|
2204
|
+
: (0, tools_base_1.withCode)(`invalid tool arguments: ${detail}`, "invalid-arguments");
|
|
2205
|
+
rejections.push(rejection);
|
|
2206
|
+
// A rejected call never reaches onToolEnd; count it as a failed call (a name the turn never offered is "unknown").
|
|
2207
|
+
turnTally.rejected(entry.call.name);
|
|
2208
|
+
options?.toolBoundaryObserver?.({
|
|
2209
|
+
name: entry.call.name,
|
|
2210
|
+
reason: callableToolNames.has(entry.call.name) ? "invalid_arguments" : "profile_excluded",
|
|
2211
|
+
globallyResolvable: typeof (0, tools_1.resolveToolDefinition)(entry.call.name)?.handler === "function",
|
|
2212
|
+
invoked: false,
|
|
2213
|
+
sideEffect: false,
|
|
2214
|
+
});
|
|
2215
|
+
}
|
|
2216
|
+
rejectToolBatch(msg, rejections);
|
|
2217
|
+
if (unadvertisedCall) {
|
|
2218
|
+
(0, runtime_1.emitNervesEvent)({
|
|
2219
|
+
level: "warn",
|
|
2220
|
+
component: "engine",
|
|
2221
|
+
event: "engine.unadvertised_tool_blocked",
|
|
2222
|
+
message: "blocked an unadvertised tool call before batch execution",
|
|
2223
|
+
meta: { channel: String(channel), toolName: unadvertisedCall.call.name },
|
|
2224
|
+
});
|
|
2225
|
+
}
|
|
2226
|
+
else {
|
|
2227
|
+
(0, runtime_1.emitNervesEvent)({
|
|
2228
|
+
level: "warn",
|
|
2229
|
+
component: "engine",
|
|
2230
|
+
event: "engine.tool_arguments_rejected",
|
|
2231
|
+
message: "tool batch rejected before execution because arguments were invalid",
|
|
2232
|
+
meta: { toolCallId: invalidCall.call.id, toolName: invalidCall.call.name },
|
|
2233
|
+
});
|
|
2234
|
+
}
|
|
904
2235
|
continue;
|
|
905
2236
|
}
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
2237
|
+
const validCalls = validatedCalls;
|
|
2238
|
+
const validatedCallArguments = new Map(validCalls.map((entry) => [
|
|
2239
|
+
entry.call,
|
|
2240
|
+
entry.validated.arguments,
|
|
2241
|
+
]));
|
|
2242
|
+
const preflightRejections = new Map();
|
|
2243
|
+
for (const entry of validCalls) {
|
|
2244
|
+
if (entry.call.name === tool_catalog_1.FIND_TOOLS_NAME)
|
|
2245
|
+
continue;
|
|
2246
|
+
if (!relationship && !toolSelection.engine.some((tool) => tool.function.name === entry.call.name))
|
|
2247
|
+
continue;
|
|
2248
|
+
const prepared = await (0, tools_1.preflightToolCall)(entry.call.name, validatedCallArguments.get(entry.call), augmentedToolContext);
|
|
2249
|
+
if (prepared.kind !== "ready")
|
|
2250
|
+
preflightRejections.set(entry.call.id, prepared.text);
|
|
2251
|
+
}
|
|
2252
|
+
if (preflightRejections.size > 0) {
|
|
2253
|
+
streamCallbackBuffer?.discard();
|
|
2254
|
+
rejectToolBatch(msg, result.toolCalls.map((call) => preflightRejections.get(call.id)
|
|
2255
|
+
?? "rejected: another call in this batch failed current authorization; no handler was executed."));
|
|
2256
|
+
continue;
|
|
909
2257
|
}
|
|
910
|
-
|
|
911
|
-
|
|
2258
|
+
const habitBlockReason = await habitToolBatchBlockReason(habitSession, result.toolCalls, augmentedToolContext?.delegatedOrigins, toolSelection);
|
|
2259
|
+
if (habitBlockReason) {
|
|
2260
|
+
streamCallbackBuffer?.discard();
|
|
2261
|
+
recordBlockedHabitSurfaceAttempts(habitSession, result.toolCalls, habitBlockReason);
|
|
2262
|
+
const blockedOutput = `blocked: ${habitBlockReason}. No tool side effects from this assistant message were executed.`;
|
|
2263
|
+
rejectToolBatch(msg, result.toolCalls.map(() => blockedOutput));
|
|
2264
|
+
(0, runtime_1.emitNervesEvent)({
|
|
2265
|
+
level: "warn",
|
|
2266
|
+
component: "engine",
|
|
2267
|
+
event: "engine.habit_tool_batch_blocked",
|
|
2268
|
+
message: "habit tool batch blocked before side effects",
|
|
2269
|
+
meta: { reason: habitBlockReason, toolCalls: result.toolCalls.map((call) => call.name) },
|
|
2270
|
+
});
|
|
2271
|
+
continue;
|
|
912
2272
|
}
|
|
913
|
-
|
|
914
|
-
|
|
2273
|
+
const soleViolation = result.toolCalls.length > 1
|
|
2274
|
+
? result.toolCalls.find((call) => SOLE_CALL_REJECTION[call.name] !== undefined || (0, tools_1.resolveToolDefinition)(call.name, toolSelection)?.terminalProjection?.requiresSoleCall === true)
|
|
2275
|
+
: undefined;
|
|
2276
|
+
if (soleViolation) {
|
|
2277
|
+
streamCallbackBuffer?.discard();
|
|
2278
|
+
const reason = SOLE_CALL_REJECTION[soleViolation.name] ?? `rejected: ${soleViolation.name} must be the only tool call.`;
|
|
2279
|
+
rejectToolBatch(msg, result.toolCalls.map(() => reason));
|
|
2280
|
+
continue;
|
|
915
2281
|
}
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
2282
|
+
const soleTerminalCall = result.toolCalls.length === 1
|
|
2283
|
+
? result.toolCalls[0]
|
|
2284
|
+
: null;
|
|
2285
|
+
const soleTerminalProjection = soleTerminalCall
|
|
2286
|
+
? (0, tools_1.resolveToolDefinition)(soleTerminalCall.name, toolSelection)?.terminalProjection
|
|
2287
|
+
: undefined;
|
|
2288
|
+
if (soleTerminalCall && soleTerminalProjection?.mode === "verbatim") {
|
|
2289
|
+
const terminalArgs = validatedCallArguments.get(soleTerminalCall);
|
|
2290
|
+
if (soleTerminalProjection.clearBufferedText
|
|
2291
|
+
|| callbacks.settleOutputMode === "final_only") {
|
|
2292
|
+
streamCallbackBuffer?.discard();
|
|
2293
|
+
}
|
|
2294
|
+
else {
|
|
2295
|
+
await streamCallbackBuffer?.flush();
|
|
2296
|
+
}
|
|
2297
|
+
if (soleTerminalProjection.clearBufferedText)
|
|
2298
|
+
callbacks.onClearText?.();
|
|
2299
|
+
callbacks.onToolStart(soleTerminalCall.name, terminalArgs);
|
|
2300
|
+
let terminalResult;
|
|
2301
|
+
let terminalSucceeded = false;
|
|
2302
|
+
try {
|
|
2303
|
+
if (options?.execTool && !relationship) {
|
|
2304
|
+
callbacks.onToolDispatch?.(soleTerminalCall.name);
|
|
2305
|
+
terminalResult = await options.execTool(soleTerminalCall.name, terminalArgs, trustedToolContext);
|
|
2306
|
+
terminalSucceeded = true;
|
|
2307
|
+
}
|
|
2308
|
+
else {
|
|
2309
|
+
const execution = await (0, tools_1.executeTool)(soleTerminalCall.name, terminalArgs, withDispatchNotice(augmentedToolContext, soleTerminalCall.name), options?.execTool);
|
|
2310
|
+
terminalResult = "error" in execution
|
|
2311
|
+
? `error: ${execution.error instanceof Error ? execution.error.message : String(execution.error)}`
|
|
2312
|
+
: execution.text;
|
|
2313
|
+
terminalSucceeded = execution.kind === "handler_succeeded";
|
|
2314
|
+
}
|
|
2315
|
+
}
|
|
2316
|
+
catch (error) {
|
|
2317
|
+
terminalResult = error instanceof Error ? `error: ${error.message}` : `error: ${String(error)}`;
|
|
2318
|
+
}
|
|
2319
|
+
callbacks.onToolEnd(soleTerminalCall.name, (0, tools_1.summarizeArgs)(soleTerminalCall.name, terminalArgs, toolSelection), terminalSucceeded);
|
|
2320
|
+
pushGenerated(msg);
|
|
2321
|
+
const shieldedTerminalResult = (0, delegated_command_1.shieldDelegatedBanner)(terminalResult);
|
|
2322
|
+
pushGenerated({ role: "tool", tool_call_id: soleTerminalCall.id, content: shieldedTerminalResult });
|
|
2323
|
+
providerRuntime.appendToolOutput(soleTerminalCall.id, shieldedTerminalResult);
|
|
2324
|
+
callbacks.onTextChunk(terminalResult);
|
|
2325
|
+
completion = { answer: terminalResult, intent: terminalSucceeded ? "complete" : "blocked" };
|
|
2326
|
+
outcome = terminalSucceeded ? "settled" : "blocked";
|
|
2327
|
+
done = true;
|
|
933
2328
|
continue;
|
|
934
2329
|
}
|
|
935
|
-
//
|
|
936
|
-
if (
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
2330
|
+
// Check for settle sole call: intercept before tool execution
|
|
2331
|
+
if (isSoleSettle) {
|
|
2332
|
+
const settleArgs = validatedCallArguments.get(result.toolCalls[0]);
|
|
2333
|
+
callbacks.onToolStart("settle", settleArgs);
|
|
2334
|
+
const requiredToolCallsGate = pendingRequiredToolCalls();
|
|
2335
|
+
if (requiredToolCallsGate) {
|
|
2336
|
+
streamCallbackBuffer?.discard();
|
|
2337
|
+
callbacks.onToolEnd("settle", (0, tools_1.summarizeArgs)("settle", settleArgs, toolSelection), false);
|
|
2338
|
+
callbacks.onClearText?.();
|
|
2339
|
+
queueRequiredCorrection(msg, requiredToolCallsGate.message, "before required tool calls completed");
|
|
2340
|
+
(0, runtime_1.emitNervesEvent)({
|
|
2341
|
+
level: "warn",
|
|
2342
|
+
component: "engine",
|
|
2343
|
+
event: "engine.required_tool_calls_pending",
|
|
2344
|
+
message: "settle rejected until required tool handlers dispatch",
|
|
2345
|
+
meta: { missingToolNames: requiredToolCallsGate.missing },
|
|
2346
|
+
});
|
|
2347
|
+
continue;
|
|
940
2348
|
}
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
2349
|
+
// Private-runtime attention queue gate: reject settle if items remain
|
|
2350
|
+
const attentionQueue = augmentedToolContext?.delegatedOrigins;
|
|
2351
|
+
if (isPrivateRuntimeChannel && attentionQueue && attentionQueue.length > 0) {
|
|
2352
|
+
streamCallbackBuffer?.discard();
|
|
2353
|
+
callbacks.onToolEnd("settle", (0, tools_1.summarizeArgs)("settle", settleArgs, toolSelection), false);
|
|
2354
|
+
callbacks.onClearText?.();
|
|
2355
|
+
const gateMessage = tools_flow_1.FLOW_TOOL_REFUSALS.settleHeldWork;
|
|
2356
|
+
rejectToolBatch(msg, [gateMessage]);
|
|
947
2357
|
continue;
|
|
948
2358
|
}
|
|
2359
|
+
// Extract answer from the tool call arguments.
|
|
2360
|
+
// Supports: {"answer":"text","intent":"..."} or "text" (JSON string).
|
|
2361
|
+
const { answer, intent } = parseSettlePayload(result.toolCalls[0].arguments);
|
|
2362
|
+
const requiredAnswerRejection = options?.requiredToolCalls?.validateTerminalAnswer?.(answer);
|
|
2363
|
+
if (requiredAnswerRejection) {
|
|
2364
|
+
streamCallbackBuffer?.discard();
|
|
2365
|
+
callbacks.onToolEnd("settle", (0, tools_1.summarizeArgs)("settle", settleArgs, toolSelection), false);
|
|
2366
|
+
callbacks.onClearText?.();
|
|
2367
|
+
queueRequiredCorrection(msg, requiredAnswerRejection, "before required terminal answer validation completed");
|
|
2368
|
+
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "engine", event: "engine.required_tool_answer_rejected", message: "unsupported settle answer rejected after required reads", meta: { answerLength: answer.length } });
|
|
2369
|
+
continue;
|
|
2370
|
+
}
|
|
2371
|
+
// Private-runtime settle: no CompletionMetadata, "(settled)" ack
|
|
2372
|
+
if (isPrivateRuntimeChannel) {
|
|
2373
|
+
streamCallbackBuffer?.discard();
|
|
2374
|
+
callbacks.onToolEnd("settle", (0, tools_1.summarizeArgs)("settle", settleArgs, toolSelection), true);
|
|
2375
|
+
pushGenerated(msg);
|
|
2376
|
+
const settled = "(settled)";
|
|
2377
|
+
pushGenerated({ role: "tool", tool_call_id: result.toolCalls[0].id, content: settled });
|
|
2378
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, settled);
|
|
2379
|
+
outcome = "settled";
|
|
2380
|
+
done = true;
|
|
2381
|
+
continue;
|
|
2382
|
+
}
|
|
2383
|
+
// The provider finalizer has already established a top-level string
|
|
2384
|
+
// answer before ordinary settle handling reaches this point.
|
|
2385
|
+
const deliveredAnswer = answer;
|
|
2386
|
+
// Never spend the last provider iteration on this optional retry: delivering the recap beats delivering nothing.
|
|
2387
|
+
const contentMismatch = sawSettleContentMismatch || providerIterations >= stepBudget - 1 ? null : settleContentMismatchError(msg.content, deliveredAnswer);
|
|
2388
|
+
if (contentMismatch) {
|
|
2389
|
+
sawSettleContentMismatch = true;
|
|
2390
|
+
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "engine", event: "engine.settle_content_mismatch", message: "settle answer differs from the reply text written beside it; asking once for the reply as the answer", meta: { answerLength: deliveredAnswer.length, contentLength: msg.content.length } });
|
|
2391
|
+
}
|
|
2392
|
+
const { error: answerGateError, replacement } = answerGateVerdict(deliveredAnswer, intent);
|
|
2393
|
+
const retryError = contentMismatch
|
|
2394
|
+
?? answerGateError
|
|
2395
|
+
?? privateReturnAckLeakError(deliveredAnswer, privateReturnHeldTokens)
|
|
2396
|
+
?? privateReturnMissingPonderError({
|
|
2397
|
+
latestUserRequest: latestUserMessageText(messages),
|
|
2398
|
+
answer: deliveredAnswer,
|
|
2399
|
+
sawPonder,
|
|
2400
|
+
})
|
|
2401
|
+
?? getSettleRetryError(mustResolveBeforeHandoffActive, intent, sawSteeringFollowUp, options?.delegationDecision, sawSendMessageSelf, sawPonder, sawQuerySession, options?.currentObligation ?? null, options?.activeWorkFrame?.inner?.job, sawExternalStateQuery);
|
|
2402
|
+
const validDirectReply = mustResolveBeforeHandoffActive && intent === "direct_reply" && sawSteeringFollowUp;
|
|
2403
|
+
// A check-back is filed only once every gate has passed, through await_condition itself, so it is bound and
|
|
2404
|
+
// permitted exactly as that tool would be. If it can't be filed, nothing is sent and the model is told why.
|
|
2405
|
+
let checkBackError = null;
|
|
2406
|
+
let checkBackFiled = null;
|
|
2407
|
+
if (retryError === null && (settleArgs.check_back_at !== undefined || settleArgs.condition !== undefined)) {
|
|
2408
|
+
// The schema gate has already made both strings when present.
|
|
2409
|
+
const at = (settleArgs.check_back_at ?? "").trim();
|
|
2410
|
+
const condition = (settleArgs.condition ?? "").trim();
|
|
2411
|
+
if (!at || !condition) {
|
|
2412
|
+
checkBackError = tools_flow_1.FLOW_TOOL_REFUSALS.settleCheckBackIncomplete;
|
|
2413
|
+
}
|
|
2414
|
+
else {
|
|
2415
|
+
const awaitArgs = { name: `check-back-${Date.now().toString(36)}`, condition, cadence: tools_flow_1.SETTLE_CHECK_BACK_CADENCE, wake_at: at };
|
|
2416
|
+
let filedText;
|
|
2417
|
+
try {
|
|
2418
|
+
if (options?.execTool && !relationship) {
|
|
2419
|
+
filedText = await options.execTool("await_condition", awaitArgs, trustedToolContext);
|
|
2420
|
+
}
|
|
2421
|
+
else {
|
|
2422
|
+
// A failed execution's text is its error, which reads below as the reason.
|
|
2423
|
+
filedText = (await (0, tools_1.executeTool)("await_condition", awaitArgs, augmentedToolContext, options?.execTool)).text;
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2426
|
+
catch (error) {
|
|
2427
|
+
filedText = JSON.stringify({ error: error instanceof Error ? error.message : String(error) });
|
|
2428
|
+
}
|
|
2429
|
+
let parsed = {};
|
|
2430
|
+
try {
|
|
2431
|
+
parsed = JSON.parse(filedText);
|
|
2432
|
+
}
|
|
2433
|
+
catch {
|
|
2434
|
+
parsed = { error: filedText };
|
|
2435
|
+
}
|
|
2436
|
+
if (parsed.filed === awaitArgs.name) {
|
|
2437
|
+
checkBackFiled = { name: awaitArgs.name, at };
|
|
2438
|
+
}
|
|
2439
|
+
else {
|
|
2440
|
+
checkBackError = tools_flow_1.FLOW_TOOL_REFUSALS.settleCheckBackNotFiled(typeof parsed.error === "string" ? parsed.error : "await_condition gave no receipt");
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
(0, runtime_1.emitNervesEvent)({
|
|
2444
|
+
level: checkBackError ? "warn" : "info",
|
|
2445
|
+
component: "engine",
|
|
2446
|
+
event: "engine.settle_check_back",
|
|
2447
|
+
message: "settle asked to leave a check-back",
|
|
2448
|
+
meta: { filed: checkBackFiled !== null },
|
|
2449
|
+
});
|
|
2450
|
+
}
|
|
2451
|
+
if (retryError === null && checkBackError === null) {
|
|
2452
|
+
const finalAnswer = replacement ?? deliveredAnswer;
|
|
2453
|
+
const rewritten = replacement !== null;
|
|
2454
|
+
try {
|
|
2455
|
+
if (rewritten && result.settleStreamed)
|
|
2456
|
+
callbacks.onClearText?.();
|
|
2457
|
+
if (rewritten || !result.settleStreamed) {
|
|
2458
|
+
const acceptedOutputCallbacks = streamCallbackBuffer?.callbacks ?? callbacks;
|
|
2459
|
+
acceptedOutputCallbacks.onTextChunk(finalAnswer);
|
|
2460
|
+
}
|
|
2461
|
+
await streamCallbackBuffer?.flush();
|
|
2462
|
+
}
|
|
2463
|
+
catch (error) {
|
|
2464
|
+
callbacks.onToolEnd("settle", (0, tools_1.summarizeArgs)("settle", settleArgs, toolSelection), false);
|
|
2465
|
+
streamCallbackBuffer?.discard();
|
|
2466
|
+
finishTerminalProviderError(new streaming_1.SettleFinalizationCallbackError(error), "unknown");
|
|
2467
|
+
continue;
|
|
2468
|
+
}
|
|
2469
|
+
callbacks.onToolEnd("settle", (0, tools_1.summarizeArgs)("settle", settleArgs, toolSelection), true);
|
|
2470
|
+
completion = {
|
|
2471
|
+
answer: finalAnswer,
|
|
2472
|
+
intent: validDirectReply ? "direct_reply" : intent === "blocked" ? "blocked" : "complete",
|
|
2473
|
+
};
|
|
2474
|
+
// Retractable owners already hold the validated answer. Final-only
|
|
2475
|
+
// owners receive it here, after every semantic continuation gate.
|
|
2476
|
+
pushGenerated(rewritten ? withSettleAnswer(msg, settleArgs, finalAnswer) : msg);
|
|
2477
|
+
if (validDirectReply) {
|
|
2478
|
+
const resumeWork = "direct reply delivered. resume the unresolved obligation now and keep working until you can finish or clearly report that you are blocked.";
|
|
2479
|
+
pushGenerated({ role: "tool", tool_call_id: result.toolCalls[0].id, content: resumeWork });
|
|
2480
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, resumeWork);
|
|
2481
|
+
}
|
|
2482
|
+
else {
|
|
2483
|
+
const delivered = checkBackFiled ? `(delivered; check-back ${checkBackFiled.name} filed for ${checkBackFiled.at})` : "(delivered)";
|
|
2484
|
+
pushGenerated({ role: "tool", tool_call_id: result.toolCalls[0].id, content: delivered });
|
|
2485
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, delivered);
|
|
2486
|
+
outcome = intent === "blocked" ? "blocked" : "settled";
|
|
2487
|
+
done = true;
|
|
2488
|
+
}
|
|
2489
|
+
}
|
|
2490
|
+
else {
|
|
2491
|
+
// The payload is structurally final, but a semantic continuation
|
|
2492
|
+
// gate rejected it. Return that exact gate reason to the model.
|
|
2493
|
+
streamCallbackBuffer?.discard();
|
|
2494
|
+
callbacks.onToolEnd("settle", (0, tools_1.summarizeArgs)("settle", settleArgs, toolSelection), false);
|
|
2495
|
+
callbacks.onClearText?.();
|
|
2496
|
+
rejectToolBatch(msg, [(retryError ?? checkBackError)]);
|
|
2497
|
+
}
|
|
2498
|
+
continue;
|
|
949
2499
|
}
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
const
|
|
955
|
-
|
|
956
|
-
|
|
2500
|
+
// Check for observe sole call: intercept before tool execution
|
|
2501
|
+
const isSoleObserve = result.toolCalls.length === 1 && result.toolCalls[0].name === "observe";
|
|
2502
|
+
if (isSoleObserve) {
|
|
2503
|
+
streamCallbackBuffer?.discard();
|
|
2504
|
+
const observeArgs = validatedCallArguments.get(result.toolCalls[0]);
|
|
2505
|
+
let reason;
|
|
2506
|
+
if (typeof observeArgs?.reason === "string")
|
|
2507
|
+
reason = observeArgs.reason;
|
|
2508
|
+
callbacks.onToolStart("observe", observeArgs);
|
|
2509
|
+
(0, runtime_1.emitNervesEvent)({
|
|
2510
|
+
component: "engine",
|
|
2511
|
+
event: "engine.observe",
|
|
2512
|
+
message: "agent observed without responding",
|
|
2513
|
+
meta: { ...(reason ? { reason } : {}) },
|
|
2514
|
+
});
|
|
2515
|
+
callbacks.onToolEnd("observe", (0, tools_1.summarizeArgs)("observe", observeArgs, toolSelection), true);
|
|
2516
|
+
pushGenerated(msg);
|
|
2517
|
+
const silenced = "(silenced)";
|
|
2518
|
+
pushGenerated({ role: "tool", tool_call_id: result.toolCalls[0].id, content: silenced });
|
|
2519
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, silenced);
|
|
2520
|
+
outcome = "observed";
|
|
2521
|
+
done = true;
|
|
2522
|
+
continue;
|
|
2523
|
+
}
|
|
2524
|
+
// Check for rest sole call: intercept before tool execution
|
|
2525
|
+
const isSoleRest = result.toolCalls.length === 1 && result.toolCalls[0].name === "rest";
|
|
2526
|
+
if (isSoleRest) {
|
|
2527
|
+
streamCallbackBuffer?.discard();
|
|
2528
|
+
const restArgs = validatedCallArguments.get(result.toolCalls[0]);
|
|
2529
|
+
callbacks.onToolStart("rest", restArgs);
|
|
2530
|
+
// Attention queue gate: reject rest if items remain
|
|
2531
|
+
// A budget wrap-up rest is final: held work and fresh messages wait for the next turn.
|
|
2532
|
+
const wrappingUp = stepReportIteration !== null;
|
|
2533
|
+
const attentionQueue = augmentedToolContext?.delegatedOrigins;
|
|
2534
|
+
if (!wrappingUp && attentionQueue && attentionQueue.length > 0) {
|
|
2535
|
+
callbacks.onToolEnd("rest", (0, tools_1.summarizeArgs)("rest", restArgs, toolSelection), false);
|
|
2536
|
+
const gateMessage = tools_flow_1.FLOW_TOOL_REFUSALS.restHeldWork;
|
|
2537
|
+
rejectToolBatch(msg, [gateMessage]);
|
|
2538
|
+
continue;
|
|
2539
|
+
}
|
|
2540
|
+
if (!wrappingUp && hasFreshPendingWork(options) && !freshWorkGateFired) {
|
|
2541
|
+
freshWorkGateFired = true;
|
|
2542
|
+
callbacks.onToolEnd("rest", (0, tools_1.summarizeArgs)("rest", restArgs, toolSelection), false);
|
|
2543
|
+
const gateMessage = tools_flow_1.FLOW_TOOL_REFUSALS.restFreshWork;
|
|
2544
|
+
rejectToolBatch(msg, [gateMessage]);
|
|
2545
|
+
(0, runtime_1.emitNervesEvent)({
|
|
2546
|
+
level: "info",
|
|
2547
|
+
component: "engine",
|
|
2548
|
+
event: "engine.fresh_work_gate_fired",
|
|
2549
|
+
message: "rest deferred once because pending work arrived this turn; agent has been notified",
|
|
2550
|
+
meta: { pendingCount: options.pendingMessages.length },
|
|
2551
|
+
});
|
|
2552
|
+
continue;
|
|
2553
|
+
}
|
|
2554
|
+
const unsentSurface = !wrappingUp && !surfaceNotSentGateFired ? unsentSurfaceResult(turnToolRecords) : null;
|
|
2555
|
+
if (unsentSurface) {
|
|
2556
|
+
surfaceNotSentGateFired = true;
|
|
2557
|
+
callbacks.onToolEnd("rest", (0, tools_1.summarizeArgs)("rest", restArgs, toolSelection), false);
|
|
2558
|
+
rejectToolBatch(msg, [tools_flow_1.FLOW_TOOL_REFUSALS.restSurfaceNotSent(unsentSurface)]);
|
|
2559
|
+
(0, runtime_1.emitNervesEvent)({
|
|
2560
|
+
level: "info",
|
|
2561
|
+
component: "engine",
|
|
2562
|
+
event: "engine.surface_not_sent_gate_fired",
|
|
2563
|
+
message: "rest deferred once because a surface this turn was not sent; agent has been notified",
|
|
2564
|
+
meta: {},
|
|
2565
|
+
});
|
|
2566
|
+
continue;
|
|
2567
|
+
}
|
|
2568
|
+
callbacks.onToolEnd("rest", (0, tools_1.summarizeArgs)("rest", restArgs, toolSelection), true);
|
|
2569
|
+
pushGenerated(msg);
|
|
2570
|
+
const ack = "(resting)";
|
|
2571
|
+
pushGenerated({ role: "tool", tool_call_id: result.toolCalls[0].id, content: ack });
|
|
2572
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, ack);
|
|
2573
|
+
(0, runtime_1.emitNervesEvent)({
|
|
2574
|
+
component: "engine",
|
|
2575
|
+
event: "engine.rested",
|
|
2576
|
+
message: "resting until next heartbeat",
|
|
2577
|
+
meta: { ...(typeof restArgs?.status === "string" ? { status: restArgs.status } : {}) },
|
|
2578
|
+
});
|
|
2579
|
+
outcome = "rested";
|
|
2580
|
+
done = true;
|
|
2581
|
+
continue;
|
|
957
2582
|
}
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
2583
|
+
const requiredDispatchRejections = new Map();
|
|
2584
|
+
for (const entry of validCalls) {
|
|
2585
|
+
const requiredArgs = entry.validated.arguments;
|
|
2586
|
+
const rejection = options?.requiredToolCalls?.validateToolCallBeforeDispatch?.(entry.call.name, requiredArgs);
|
|
2587
|
+
if (!rejection)
|
|
2588
|
+
continue;
|
|
2589
|
+
const rejectionKey = `${entry.call.name}\0${rejection}`;
|
|
2590
|
+
const priorRejections = requiredDispatchRejectionCounts.get(rejectionKey) ?? 0;
|
|
2591
|
+
if (priorRejections >= 2) {
|
|
2592
|
+
(0, runtime_1.emitNervesEvent)({
|
|
2593
|
+
level: "warn", component: "engine", event: "engine.required_tool_dispatch_advisory",
|
|
2594
|
+
message: "required tool dependency rejected twice this turn; letting the call through",
|
|
2595
|
+
meta: { toolName: entry.call.name },
|
|
2596
|
+
});
|
|
2597
|
+
continue;
|
|
2598
|
+
}
|
|
2599
|
+
requiredDispatchRejectionCounts.set(rejectionKey, priorRejections + 1);
|
|
2600
|
+
requiredDispatchRejections.set(entry.call.id, { name: entry.call.name, args: requiredArgs, message: rejection });
|
|
2601
|
+
}
|
|
2602
|
+
if (requiredDispatchRejections.size > 0) {
|
|
2603
|
+
streamCallbackBuffer?.discard();
|
|
2604
|
+
for (const rejection of requiredDispatchRejections.values()) {
|
|
2605
|
+
callbacks.onToolStart(rejection.name, rejection.args);
|
|
2606
|
+
callbacks.onToolEnd(rejection.name, (0, tools_1.summarizeArgs)(rejection.name, rejection.args, toolSelection), false);
|
|
2607
|
+
options?.toolBoundaryObserver?.({
|
|
2608
|
+
name: rejection.name, reason: "dependency_rejected",
|
|
2609
|
+
globallyResolvable: typeof (0, tools_1.resolveToolDefinition)(rejection.name)?.handler === "function",
|
|
2610
|
+
invoked: false, sideEffect: false,
|
|
2611
|
+
});
|
|
2612
|
+
(0, runtime_1.emitNervesEvent)({
|
|
2613
|
+
level: "warn", component: "engine", event: "engine.required_tool_dispatch_rejected",
|
|
2614
|
+
message: "required tool dependency rejected before approval and handler dispatch",
|
|
2615
|
+
meta: { toolName: rejection.name },
|
|
2616
|
+
});
|
|
2617
|
+
}
|
|
2618
|
+
rejectToolBatch(msg, result.toolCalls.map((call) => requiredDispatchRejections.get(call.id)?.message
|
|
2619
|
+
?? "rejected: another call in this batch has an unsatisfied required dependency; no handler was executed."));
|
|
2620
|
+
continue;
|
|
2621
|
+
}
|
|
2622
|
+
const executionRejections = new Map();
|
|
2623
|
+
for (const entry of validCalls) {
|
|
2624
|
+
const args = validatedCallArguments.get(entry.call);
|
|
2625
|
+
const fingerprint = effectFingerprint(entry.call.name, entry.call.arguments, toolSelection);
|
|
2626
|
+
if (forcingHistoricalEffect && fingerprint && !unresolvedHistoricalEffects.some((effect) => effect.fingerprint === fingerprint)) {
|
|
2627
|
+
executionRejections.set(entry.call.id, "rejected: this turn is retrying an unresolved historical effect, and these mutation arguments do not match it. Read current state or retry the exact failed effect.");
|
|
2628
|
+
}
|
|
2629
|
+
else if (entry.call.name === "send_message" && args.friendId === "self" && !isPrivateRuntimeChannel && looksLikePrivateReturnRequest(latestUserMessageText(messages))) {
|
|
2630
|
+
executionRejections.set(entry.call.id, "private-return requests must use ponder, not send_message(friendId=self). Create a typed ponder packet with the marker/source request preserved, then only acknowledge that the private pass is queued.");
|
|
2631
|
+
}
|
|
2632
|
+
else if (entry.call.name !== "speak" && entry.call.name !== "ponder") {
|
|
2633
|
+
const loop = (0, tool_loop_1.detectToolLoop)(toolLoopState, entry.call.name, args);
|
|
2634
|
+
if (loop.stuck)
|
|
2635
|
+
executionRejections.set(entry.call.id, `loop guard: ${loop.message}`);
|
|
2636
|
+
}
|
|
2637
|
+
}
|
|
2638
|
+
if (executionRejections.size > 0) {
|
|
2639
|
+
streamCallbackBuffer?.discard();
|
|
2640
|
+
for (const entry of validCalls) {
|
|
2641
|
+
if (!executionRejections.has(entry.call.id))
|
|
2642
|
+
continue;
|
|
2643
|
+
const args = validatedCallArguments.get(entry.call);
|
|
2644
|
+
callbacks.onToolStart(entry.call.name, args);
|
|
2645
|
+
callbacks.onToolEnd(entry.call.name, (0, tools_1.summarizeArgs)(entry.call.name, args, toolSelection), false);
|
|
2646
|
+
}
|
|
2647
|
+
rejectToolBatch(msg, result.toolCalls.map((call) => executionRejections.get(call.id)
|
|
2648
|
+
?? "rejected: another call in this batch was inadmissible; no handler was executed."));
|
|
2649
|
+
continue;
|
|
2650
|
+
}
|
|
2651
|
+
const approvalCalls = await Promise.all(validCalls.map(async (entry) => {
|
|
2652
|
+
const classification = await (0, tools_1.classifyApprovalForInvocation)(entry.call.name, entry.validated.arguments, augmentedToolContext);
|
|
2653
|
+
return {
|
|
2654
|
+
...entry,
|
|
2655
|
+
...classification,
|
|
2656
|
+
};
|
|
2657
|
+
}));
|
|
2658
|
+
const protectedCall = approvalCalls.find((entry) => entry.policy.kind === "required");
|
|
2659
|
+
if (protectedCall && result.toolCalls.length !== 1) {
|
|
2660
|
+
streamCallbackBuffer?.discard();
|
|
2661
|
+
rejectToolBatch(msg, result.toolCalls.map(() => "rejected: approval-eligible tool must be the sole call; no call in this batch was executed."));
|
|
2662
|
+
(0, runtime_1.emitNervesEvent)({
|
|
2663
|
+
level: "warn",
|
|
2664
|
+
component: "engine",
|
|
2665
|
+
event: "engine.approval_mixed_batch_rejected",
|
|
2666
|
+
message: "protected tool batch rejected before every handler",
|
|
2667
|
+
meta: { toolCallCount: result.toolCalls.length, protectedToolName: protectedCall.call.name },
|
|
2668
|
+
});
|
|
2669
|
+
continue;
|
|
2670
|
+
}
|
|
2671
|
+
if (protectedCall && protectedCall.policy.kind === "required") {
|
|
2672
|
+
if (!options?.approvalCoordinator) {
|
|
2673
|
+
streamCallbackBuffer?.discard();
|
|
2674
|
+
const rejection = tools_1.APPROVAL_UNAVAILABLE_REJECTION;
|
|
2675
|
+
rejectToolBatch(msg, [rejection]);
|
|
2676
|
+
(0, runtime_1.emitNervesEvent)({
|
|
2677
|
+
level: "warn",
|
|
2678
|
+
component: "engine",
|
|
2679
|
+
event: "engine.approval_coordinator_unavailable",
|
|
2680
|
+
message: "protected tool failed closed before handler execution",
|
|
2681
|
+
meta: { toolName: protectedCall.call.name, toolCallId: protectedCall.call.id },
|
|
2682
|
+
});
|
|
2683
|
+
continue;
|
|
2684
|
+
}
|
|
2685
|
+
streamCallbackBuffer?.discard();
|
|
2686
|
+
const toolDigest = (0, tool_approval_1.digestApprovalToolDefinition)((0, tools_1.resolveToolDefinition)(protectedCall.call.name, toolSelection), protectedCall.validated.schemaDigest, protectedCall.policy.policyId);
|
|
2687
|
+
const policyDigest = (0, tool_arguments_1.digestJson)({
|
|
2688
|
+
policyId: protectedCall.policy.policyId,
|
|
2689
|
+
actionClass: protectedCall.policy.actionClass,
|
|
2690
|
+
classification: "required",
|
|
2691
|
+
});
|
|
2692
|
+
const committed = await options.approvalCoordinator.propose({
|
|
2693
|
+
toolCall: structuredClone(msg.tool_calls[0]),
|
|
2694
|
+
arguments: structuredClone(protectedCall.validated.arguments),
|
|
2695
|
+
preCallMessages,
|
|
2696
|
+
frozenAssistantMessage: structuredClone(msg),
|
|
2697
|
+
schemaDigest: protectedCall.validated.schemaDigest,
|
|
2698
|
+
toolDigest,
|
|
2699
|
+
policyDigest,
|
|
2700
|
+
policyId: protectedCall.policy.policyId,
|
|
2701
|
+
actionClass: protectedCall.policy.actionClass,
|
|
2702
|
+
liveToolContext: augmentedToolContext,
|
|
2703
|
+
});
|
|
2704
|
+
pushGenerated(msg);
|
|
2705
|
+
suspension = {
|
|
2706
|
+
approvalId: committed.approvalId,
|
|
2707
|
+
toolCallId: protectedCall.call.id,
|
|
2708
|
+
checkpointDigest: committed.checkpointDigest,
|
|
2709
|
+
suspendedSessionRevision: committed.suspendedSessionRevision,
|
|
2710
|
+
};
|
|
2711
|
+
outcome = "suspended";
|
|
2712
|
+
done = true;
|
|
2713
|
+
(0, runtime_1.emitNervesEvent)({
|
|
2714
|
+
component: "engine",
|
|
2715
|
+
event: "engine.approval_turn_suspended",
|
|
2716
|
+
message: "agent turn suspended before protected tool execution",
|
|
2717
|
+
meta: { approvalId: committed.approvalId, toolCallId: protectedCall.call.id },
|
|
2718
|
+
});
|
|
2719
|
+
continue;
|
|
2720
|
+
}
|
|
2721
|
+
await streamCallbackBuffer?.flush();
|
|
2722
|
+
pushGenerated(msg);
|
|
2723
|
+
const batchToolImages = [];
|
|
2724
|
+
// Every pre-dispatch gate accepted the complete batch.
|
|
2725
|
+
const isLastCall = (tc) => tc === result.toolCalls[result.toolCalls.length - 1];
|
|
2726
|
+
for (const tc of result.toolCalls) {
|
|
2727
|
+
if (signal?.aborted)
|
|
2728
|
+
break;
|
|
2729
|
+
const args = validatedCallArguments.get(tc);
|
|
2730
|
+
const currentEffectFingerprint = effectFingerprint(tc.name, tc.arguments, toolSelection);
|
|
2731
|
+
if (tc.name === "send_message" && args.friendId === "self") {
|
|
2732
|
+
sawSendMessageSelf = true;
|
|
2733
|
+
}
|
|
2734
|
+
if (tc.name === tool_catalog_1.FIND_TOOLS_NAME) {
|
|
2735
|
+
// The pre-batch schema gate guarantees a string query.
|
|
2736
|
+
const query = args.query;
|
|
2737
|
+
callbacks.onToolStart(tool_catalog_1.FIND_TOOLS_NAME, { query });
|
|
2738
|
+
const matchedNames = (0, tool_catalog_1.searchCatalog)(toolCatalog, deferralPool, query);
|
|
2739
|
+
const matched = deferralPool.filter((tool) => matchedNames.includes(tool.function.name))
|
|
2740
|
+
.sort((a, b) => matchedNames.indexOf(a.function.name) - matchedNames.indexOf(b.function.name));
|
|
2741
|
+
for (const name of matchedNames)
|
|
2742
|
+
if (!loadedDeferredTools.includes(name))
|
|
2743
|
+
loadedDeferredTools.push(name);
|
|
2744
|
+
turnTally.findTools(matched.map((tool) => tool.function.name));
|
|
2745
|
+
// A job a bundle does with a command its skill documents has no door to find; the skill's section answers.
|
|
2746
|
+
const skills = (0, skill_search_1.findToolsSkillNote)(query, activeToolNames);
|
|
2747
|
+
if (matched.length > 0 || skills.hits > 0)
|
|
2748
|
+
lastProgressIteration = providerIterations;
|
|
2749
|
+
const found = withBudgetNote((0, tool_catalog_1.formatFindToolsReply)(matched, skills.note), isLastCall(tc), candidateToolNames);
|
|
2750
|
+
pushGenerated({ role: "tool", tool_call_id: tc.id, content: found });
|
|
2751
|
+
providerRuntime.appendToolOutput(tc.id, found);
|
|
2752
|
+
// onToolEnd's success means a door was loaded; a skill-only reply loaded none, but is still progress.
|
|
2753
|
+
callbacks.onToolEnd(tool_catalog_1.FIND_TOOLS_NAME, query, matched.length > 0);
|
|
2754
|
+
(0, tool_catalog_1.recordFindTools)({ query, matched: matched.length, deferred: deferralPool.length, skills: skills.hits });
|
|
2755
|
+
continue;
|
|
2756
|
+
}
|
|
2757
|
+
if (tc.name === "speak") {
|
|
2758
|
+
// The canonical pre-batch schema gate guarantees a required string.
|
|
2759
|
+
const speakArgs = JSON.parse(tc.arguments);
|
|
2760
|
+
const speakMessage = speakArgs.message;
|
|
2761
|
+
const argSummary = (0, tools_1.summarizeArgs)("speak", { message: speakMessage }, toolSelection);
|
|
2762
|
+
callbacks.onToolStart("speak", { message: speakMessage });
|
|
2763
|
+
if (speakMessage.trim().length === 0) {
|
|
2764
|
+
const err = withBudgetNote(tools_flow_1.FLOW_TOOL_REFUSALS.speakEmpty, isLastCall(tc), candidateToolNames);
|
|
2765
|
+
callbacks.onToolEnd("speak", argSummary, false);
|
|
2766
|
+
pushGenerated({ role: "tool", tool_call_id: tc.id, content: err });
|
|
2767
|
+
providerRuntime.appendToolOutput(tc.id, err);
|
|
2768
|
+
(0, runtime_1.emitNervesEvent)({
|
|
2769
|
+
level: "warn",
|
|
2770
|
+
component: "engine",
|
|
2771
|
+
event: "engine.speak_invalid",
|
|
2772
|
+
message: "speak rejected: missing or empty message",
|
|
2773
|
+
meta: {},
|
|
2774
|
+
});
|
|
2775
|
+
continue;
|
|
2776
|
+
}
|
|
2777
|
+
callbacks.onToolDispatch?.("speak");
|
|
2778
|
+
callbacks.onTextChunk(speakMessage);
|
|
2779
|
+
let speakDeliveryError = null;
|
|
2780
|
+
try {
|
|
2781
|
+
await callbacks.flushNow?.();
|
|
2782
|
+
}
|
|
2783
|
+
catch (err) {
|
|
2784
|
+
speakDeliveryError = err instanceof Error ? err : new Error(String(err));
|
|
2785
|
+
}
|
|
2786
|
+
if (speakDeliveryError) {
|
|
2787
|
+
callbacks.onToolEnd("speak", argSummary, false);
|
|
2788
|
+
const failMsg = withBudgetNote(tools_flow_1.FLOW_TOOL_REFUSALS.speakNotDelivered(speakDeliveryError.message), isLastCall(tc), candidateToolNames);
|
|
2789
|
+
pushGenerated({ role: "tool", tool_call_id: tc.id, content: failMsg });
|
|
2790
|
+
providerRuntime.appendToolOutput(tc.id, failMsg);
|
|
2791
|
+
(0, runtime_1.emitNervesEvent)({
|
|
2792
|
+
level: "error",
|
|
2793
|
+
component: "engine",
|
|
2794
|
+
event: "engine.speak_delivery_failed",
|
|
2795
|
+
message: "speak delivery failed",
|
|
2796
|
+
meta: { error: speakDeliveryError.message, messageLength: speakMessage.length },
|
|
2797
|
+
});
|
|
2798
|
+
continue;
|
|
2799
|
+
}
|
|
2800
|
+
callbacks.onToolEnd("speak", argSummary, true);
|
|
2801
|
+
const ack = withBudgetNote("(spoken)", isLastCall(tc), candidateToolNames);
|
|
2802
|
+
pushGenerated({ role: "tool", tool_call_id: tc.id, content: ack });
|
|
2803
|
+
providerRuntime.appendToolOutput(tc.id, ack);
|
|
2804
|
+
(0, runtime_1.emitNervesEvent)({
|
|
2805
|
+
component: "engine",
|
|
2806
|
+
event: "engine.speak",
|
|
2807
|
+
message: "agent spoke mid-turn",
|
|
2808
|
+
meta: { messageLength: speakMessage.length },
|
|
2809
|
+
});
|
|
2810
|
+
continue;
|
|
2811
|
+
}
|
|
2812
|
+
if (tc.name === "ponder") {
|
|
2813
|
+
const parsedArgs = normalizeLegacyPonderArgs(parsePonderPayload(tc.arguments));
|
|
2814
|
+
const argSummary = (0, tools_1.summarizeArgs)(tc.name, parsedArgs, toolSelection);
|
|
2815
|
+
callbacks.onToolStart(tc.name, parsedArgs);
|
|
2816
|
+
callbacks.onToolDispatch?.(tc.name);
|
|
2817
|
+
let toolResult;
|
|
2818
|
+
let success = false;
|
|
2819
|
+
try {
|
|
2820
|
+
const action = parsedArgs.action ?? "create";
|
|
2821
|
+
const currentSession = augmentedToolContext?.currentSession;
|
|
2822
|
+
const currentOrigin = currentSession
|
|
2823
|
+
? { friendId: currentSession.friendId, channel: currentSession.channel, key: currentSession.key }
|
|
2824
|
+
: undefined;
|
|
2825
|
+
const isInnerChannel = currentOrigin?.friendId === "self" && currentOrigin?.channel === "inner";
|
|
2826
|
+
const shouldCreateReturnObligation = !!currentOrigin && !isInnerChannel;
|
|
2827
|
+
const attentionQueue = augmentedToolContext?.delegatedOrigins ?? [];
|
|
2828
|
+
const successCriteria = parseSuccessCriteria(parsedArgs.success_criteria);
|
|
2829
|
+
const payload = parsePacketPayload(parsedArgs.payload_json);
|
|
2830
|
+
let packet;
|
|
2831
|
+
let returnObligationId = null;
|
|
2832
|
+
let resultAction = "created";
|
|
2833
|
+
let privateReturnSourceRequest = "";
|
|
2834
|
+
if (action === "create") {
|
|
2835
|
+
if (isInnerChannel && attentionQueue.length > 0) {
|
|
2836
|
+
throw new Error(tools_flow_1.FLOW_TOOL_REFUSALS.ponderHeldWork);
|
|
2837
|
+
}
|
|
2838
|
+
const kind = parsedArgs.kind;
|
|
2839
|
+
const objective = typeof parsedArgs.objective === "string" ? parsedArgs.objective.trim() : "";
|
|
2840
|
+
const summary = typeof parsedArgs.summary === "string" ? parsedArgs.summary.trim() : "";
|
|
2841
|
+
const sourceRequest = currentOrigin && !isInnerChannel ? latestUserMessageText(messages) : "";
|
|
2842
|
+
privateReturnSourceRequest = sourceRequest;
|
|
2843
|
+
if (!kind || !objective || !successCriteria || !payload) {
|
|
2844
|
+
throw new Error(tools_flow_1.FLOW_TOOL_REFUSALS.ponderCreateIncomplete);
|
|
2845
|
+
}
|
|
2846
|
+
const packetPayload = sourceRequest
|
|
2847
|
+
? { ...payload, sourceRequest }
|
|
2848
|
+
: payload;
|
|
2849
|
+
const createLinkedReturnObligation = (id, packetId) => {
|
|
2850
|
+
(0, obligations_1.createReturnObligation)((0, identity_2.getAgentName)(), {
|
|
2851
|
+
id,
|
|
2852
|
+
origin: currentOrigin,
|
|
2853
|
+
status: "queued",
|
|
2854
|
+
delegatedContent: buildPonderDelegatedContent({ summary, objective, sourceRequest }),
|
|
2855
|
+
packetId,
|
|
2856
|
+
createdAt: Date.now(),
|
|
2857
|
+
});
|
|
2858
|
+
};
|
|
2859
|
+
const agentRoot = (0, identity_2.getAgentRoot)();
|
|
2860
|
+
let relatedObligationId;
|
|
2861
|
+
if (currentOrigin && !isInnerChannel) {
|
|
2862
|
+
try {
|
|
2863
|
+
const obligation = (0, obligations_1.createObligation)(agentRoot, {
|
|
2864
|
+
origin: currentOrigin,
|
|
2865
|
+
content: objective,
|
|
2866
|
+
});
|
|
2867
|
+
relatedObligationId = obligation.id;
|
|
2868
|
+
}
|
|
2869
|
+
catch {
|
|
2870
|
+
relatedObligationId = undefined;
|
|
2871
|
+
}
|
|
2872
|
+
}
|
|
2873
|
+
const frictionSignature = kind === "harness_friction" && typeof packetPayload.frictionSignature === "string"
|
|
2874
|
+
? packetPayload.frictionSignature
|
|
2875
|
+
: null;
|
|
2876
|
+
const existing = frictionSignature && currentOrigin
|
|
2877
|
+
? (0, packets_1.findHarnessFrictionPacket)(agentRoot, currentOrigin, frictionSignature)
|
|
2878
|
+
: null;
|
|
2879
|
+
if (existing) {
|
|
2880
|
+
resultAction = "revised";
|
|
2881
|
+
const existingActiveReturnId = shouldCreateReturnObligation
|
|
2882
|
+
? activeReturnObligationId((0, identity_2.getAgentName)(), existing.relatedReturnObligationId)
|
|
2883
|
+
: null;
|
|
2884
|
+
returnObligationId = existingActiveReturnId
|
|
2885
|
+
?? (shouldCreateReturnObligation ? (0, obligations_1.generateObligationId)(Date.now()) : null);
|
|
2886
|
+
packet = existing.status === "drafting"
|
|
2887
|
+
? (0, packets_1.revisePonderPacket)(agentRoot, existing.id, {
|
|
2888
|
+
kind,
|
|
2889
|
+
objective,
|
|
2890
|
+
summary,
|
|
2891
|
+
successCriteria,
|
|
2892
|
+
payload: packetPayload,
|
|
2893
|
+
})
|
|
2894
|
+
: existing;
|
|
2895
|
+
if (returnObligationId && returnObligationId !== existing.relatedReturnObligationId) {
|
|
2896
|
+
packet = (0, packets_1.advancePonderPacket)(agentRoot, packet.id, { relatedReturnObligationId: returnObligationId });
|
|
2897
|
+
createLinkedReturnObligation(returnObligationId, packet.id);
|
|
2898
|
+
}
|
|
2899
|
+
}
|
|
2900
|
+
else {
|
|
2901
|
+
returnObligationId = shouldCreateReturnObligation ? (0, obligations_1.generateObligationId)(Date.now()) : null;
|
|
2902
|
+
packet = (0, packets_1.createPonderPacket)(agentRoot, {
|
|
2903
|
+
kind,
|
|
2904
|
+
objective,
|
|
2905
|
+
summary,
|
|
2906
|
+
successCriteria,
|
|
2907
|
+
...(currentOrigin ? { origin: currentOrigin } : {}),
|
|
2908
|
+
...(relatedObligationId ? { relatedObligationId } : {}),
|
|
2909
|
+
...(returnObligationId ? { relatedReturnObligationId: returnObligationId } : {}),
|
|
2910
|
+
...(parsedArgs.follows_packet_id ? { followsPacketId: parsedArgs.follows_packet_id } : {}),
|
|
2911
|
+
payload: packetPayload,
|
|
2912
|
+
});
|
|
2913
|
+
if (returnObligationId) {
|
|
2914
|
+
createLinkedReturnObligation(returnObligationId, packet.id);
|
|
2915
|
+
}
|
|
2916
|
+
}
|
|
2917
|
+
}
|
|
2918
|
+
else {
|
|
2919
|
+
const packetId = typeof parsedArgs.packet_id === "string" ? parsedArgs.packet_id.trim() : "";
|
|
2920
|
+
const kind = parsedArgs.kind;
|
|
2921
|
+
const objective = typeof parsedArgs.objective === "string" ? parsedArgs.objective.trim() : "";
|
|
2922
|
+
const summary = typeof parsedArgs.summary === "string" ? parsedArgs.summary.trim() : "";
|
|
2923
|
+
if (!packetId || !kind || !objective || !successCriteria || !payload) {
|
|
2924
|
+
throw new Error(tools_flow_1.FLOW_TOOL_REFUSALS.ponderReviseIncomplete);
|
|
2925
|
+
}
|
|
2926
|
+
packet = (0, packets_1.revisePonderPacket)((0, identity_2.getAgentRoot)(), packetId, {
|
|
2927
|
+
kind,
|
|
2928
|
+
objective,
|
|
2929
|
+
summary,
|
|
2930
|
+
successCriteria,
|
|
2931
|
+
payload,
|
|
2932
|
+
});
|
|
2933
|
+
returnObligationId = packet.relatedReturnObligationId
|
|
2934
|
+
&& !(packet.origin?.friendId === "self" && packet.origin.channel === "inner")
|
|
2935
|
+
? packet.relatedReturnObligationId
|
|
2936
|
+
: null;
|
|
2937
|
+
resultAction = "revised";
|
|
2938
|
+
}
|
|
2939
|
+
if (returnObligationId) {
|
|
2940
|
+
for (const token of extractPrivateReturnHeldTokens(privateReturnSourceRequest)) {
|
|
2941
|
+
privateReturnHeldTokens.add(token);
|
|
2942
|
+
}
|
|
2943
|
+
const agentName = (0, identity_2.getAgentName)();
|
|
2944
|
+
await (0, socket_client_1.requestPrivateWake)(agentName, augmentedToolContext?.daemonSocketPath, buildPonderReturnPrivateWakeOptions({ agentName, packet, returnObligationId })).catch(() => undefined);
|
|
2945
|
+
}
|
|
2946
|
+
sawPonder = true;
|
|
2947
|
+
toolResult = buildPonderResult(packet, resultAction, returnObligationId);
|
|
2948
|
+
success = true;
|
|
2949
|
+
(0, runtime_1.emitNervesEvent)({
|
|
2950
|
+
component: "engine",
|
|
2951
|
+
event: "engine.ponder_packet",
|
|
2952
|
+
message: "ponder packet touched",
|
|
2953
|
+
meta: {
|
|
2954
|
+
action: resultAction,
|
|
2955
|
+
packetId: packet.id,
|
|
2956
|
+
kind: packet.kind,
|
|
2957
|
+
status: packet.status,
|
|
2958
|
+
},
|
|
2959
|
+
});
|
|
2960
|
+
}
|
|
2961
|
+
catch (error) {
|
|
2962
|
+
toolResult = error instanceof Error ? error.message : String(error);
|
|
2963
|
+
}
|
|
2964
|
+
callbacks.onToolEnd(tc.name, argSummary, success);
|
|
2965
|
+
const shieldedToolResult = withBudgetNote((0, delegated_command_1.shieldDelegatedBanner)(toolResult), isLastCall(tc), candidateToolNames);
|
|
2966
|
+
pushGenerated({ role: "tool", tool_call_id: tc.id, content: shieldedToolResult });
|
|
2967
|
+
providerRuntime.appendToolOutput(tc.id, shieldedToolResult);
|
|
2968
|
+
continue;
|
|
2969
|
+
}
|
|
2970
|
+
/* v8 ignore next -- flag tested via truth-check integration tests @preserve */
|
|
2971
|
+
if (tc.name === "query_session")
|
|
2972
|
+
sawQuerySession = true;
|
|
2973
|
+
/* v8 ignore next -- flag tested via truth-check integration tests @preserve */
|
|
2974
|
+
if (tc.name === "bridge_manage")
|
|
2975
|
+
sawBridgeManage = true;
|
|
2976
|
+
/* v8 ignore next -- flag tested via truth-check integration tests @preserve */
|
|
2977
|
+
if (isExternalStateQuery(tc.name, args))
|
|
2978
|
+
sawExternalStateQuery = true;
|
|
2979
|
+
callbacks.onToolStart(tc.name, args);
|
|
2980
|
+
let toolResult;
|
|
2981
|
+
let success;
|
|
2982
|
+
let invoked = false;
|
|
2983
|
+
const toolImages = [];
|
|
2984
|
+
const withToolImageSink = (context) => context
|
|
2985
|
+
? { ...context, attachToolImages: (images) => { toolImages.push(...images); } }
|
|
2986
|
+
: context;
|
|
2987
|
+
try {
|
|
2988
|
+
const routineActionSelection = approvalCalls.find((entry) => entry.call.id === tc.id)?.routineActionSelection;
|
|
2989
|
+
const executionToolContext = routineActionSelection && augmentedToolContext ? { ...augmentedToolContext, routineActionSelection } : augmentedToolContext;
|
|
2990
|
+
if (options?.execTool && !relationship) {
|
|
2991
|
+
invoked = true;
|
|
2992
|
+
callbacks.onToolDispatch?.(tc.name);
|
|
2993
|
+
toolResult = await options.execTool(tc.name, args, withToolImageSink(trustedToolContext));
|
|
2994
|
+
success = true;
|
|
2995
|
+
}
|
|
2996
|
+
else {
|
|
2997
|
+
const execution = await (0, tools_1.executeTool)(tc.name, args, withToolImageSink(withDispatchNotice(executionToolContext, tc.name)), options?.execTool);
|
|
2998
|
+
invoked = execution.kind !== "rejected_before_handler";
|
|
2999
|
+
success = execution.kind === "handler_succeeded";
|
|
3000
|
+
toolResult = "error" in execution ? `error: ${execution.error}` : execution.text;
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
catch (e) {
|
|
3004
|
+
toolResult = `error: ${e}`;
|
|
3005
|
+
success = false;
|
|
3006
|
+
}
|
|
3007
|
+
if (success && tc.name === "load_skill") {
|
|
3008
|
+
// A skill names the doors its steps use; they load with it so the agent needn't find them one by one.
|
|
3009
|
+
const declared = (0, skill_summaries_1.declaredTools)(toolResult);
|
|
3010
|
+
const skillDoors = deferralPool.filter((tool) => declared.includes(tool.function.name));
|
|
3011
|
+
for (const tool of skillDoors)
|
|
3012
|
+
if (!loadedDeferredTools.includes(tool.function.name))
|
|
3013
|
+
loadedDeferredTools.push(tool.function.name);
|
|
3014
|
+
if (skillDoors.length > 0)
|
|
3015
|
+
toolResult = `${toolResult}\n\n${(0, tool_catalog_1.formatLoadedDoors)(skillDoors)}`;
|
|
3016
|
+
}
|
|
3017
|
+
if (success && toolImages.length > 0) {
|
|
3018
|
+
const visible = (0, tool_images_1.canModelSeeToolImages)(providerRuntime.model);
|
|
3019
|
+
toolResult = `${toolResult}${toolResult ? "\n\n" : ""}${(0, tool_images_1.toolImagesNote)(toolImages.length, providerRuntime.model, visible)}`;
|
|
3020
|
+
if (visible)
|
|
3021
|
+
batchToolImages.push({ toolName: tc.name, callId: tc.id, images: toolImages });
|
|
3022
|
+
}
|
|
3023
|
+
if (invoked && requiredToolCallNames.includes(tc.name) && !options?.requiredToolCalls?.requireSuccessfulResults)
|
|
3024
|
+
dispatchedRequiredToolCalls.add(tc.name);
|
|
3025
|
+
turnToolRecords.push({ name: tc.name, args, result: toolResult });
|
|
3026
|
+
for (const saved of surfacesReachedLater(turnToolRecords)) {
|
|
3027
|
+
try {
|
|
3028
|
+
(0, pending_1.withdrawDeferredReturn)((0, identity_2.getAgentName)(), saved.friendId, saved.content);
|
|
3029
|
+
}
|
|
3030
|
+
catch { /* a stale saved copy only repeats the news */ }
|
|
3031
|
+
}
|
|
3032
|
+
if (success && !(0, tool_loop_1.hasRecordedToolCall)(toolLoopState, tc.name, args))
|
|
3033
|
+
lastProgressIteration = providerIterations;
|
|
3034
|
+
const fittedResult = (0, delegated_command_1.shieldDelegatedBanner)((0, tool_output_budget_1.fitToolOutputForModel)(tc.name, (0, tool_friction_1.rewriteToolResultForModel)(tc.name, toolResult, toolFrictionLedger)));
|
|
3035
|
+
const modelResult = withBudgetNote(fittedResult, isLastCall(tc), candidateToolNames);
|
|
3036
|
+
pushGenerated({ role: "tool", tool_call_id: tc.id, content: modelResult });
|
|
3037
|
+
providerRuntime.appendToolOutput(tc.id, modelResult);
|
|
3038
|
+
if (!success)
|
|
3039
|
+
augmentedToolContext?.habitSession?.recordError?.(toolResult);
|
|
3040
|
+
const validatedRequiredResult = success && requiredToolCallNames.includes(tc.name) && options?.requiredToolCalls?.requireSuccessfulResults
|
|
3041
|
+
? requiredToolResultSucceeded(tc.name, toolResult, args, options.requiredToolCalls.validateRequiredToolResult)
|
|
3042
|
+
: false;
|
|
3043
|
+
if (validatedRequiredResult) {
|
|
3044
|
+
dispatchedRequiredToolCalls.add(tc.name);
|
|
3045
|
+
for (const requiredName of options?.requiredToolCalls?.requiredToolCallsAfterResult?.(tc.name, args, toolResult) ?? []) {
|
|
3046
|
+
if (!candidateToolNames.has(requiredName)) {
|
|
3047
|
+
(0, runtime_1.emitNervesEvent)({ level: "error", component: "engine", event: "engine.required_tool_unadvertised", message: "dependent required tool is not advertised for the active channel", meta: { toolName: requiredName, channel: String(channel) } });
|
|
3048
|
+
throw new Error(`dependent required tool is not advertised for this channel: ${requiredName}`);
|
|
3049
|
+
}
|
|
3050
|
+
if (!requiredToolCallNames.includes(requiredName))
|
|
3051
|
+
requiredToolCallNames.push(requiredName);
|
|
3052
|
+
}
|
|
3053
|
+
}
|
|
3054
|
+
if (success && currentEffectFingerprint && !toolResultIndicatesFailure(toolResult)) {
|
|
3055
|
+
unresolvedHistoricalEffects = unresolvedHistoricalEffects.filter((effect) => effect.fingerprint !== currentEffectFingerprint);
|
|
3056
|
+
}
|
|
3057
|
+
const dispatchedDefinition = (0, tools_1.resolveToolDefinition)(tc.name, toolSelection);
|
|
3058
|
+
const resolvedRiskProfile = dispatchedDefinition?.riskProfile;
|
|
3059
|
+
const toolRiskProfile = typeof resolvedRiskProfile === "function" ? resolvedRiskProfile(args) : resolvedRiskProfile;
|
|
3060
|
+
// A low-risk profile can still change state; the card's effect says whether it does.
|
|
3061
|
+
const changesState = toolRiskProfile?.mutates !== "none" || (dispatchedDefinition?.ax !== undefined && dispatchedDefinition.ax.effect !== "read");
|
|
3062
|
+
options?.toolBoundaryObserver?.({
|
|
3063
|
+
name: tc.name,
|
|
3064
|
+
reason: "dispatched",
|
|
3065
|
+
globallyResolvable: typeof dispatchedDefinition?.handler === "function",
|
|
3066
|
+
invoked,
|
|
3067
|
+
sideEffect: success && changesState,
|
|
3068
|
+
});
|
|
3069
|
+
(0, tool_loop_1.recordToolOutcome)(toolLoopState, tc.name, args, fittedResult, success);
|
|
3070
|
+
callbacks.onToolEnd(tc.name, (0, tools_1.buildToolResultSummary)(tc.name, args, modelResult, success, toolSelection), success);
|
|
3071
|
+
callbacks.onToolResult?.(messages);
|
|
3072
|
+
}
|
|
3073
|
+
if (batchToolImages.length > 0 && !signal?.aborted) {
|
|
3074
|
+
pushGenerated((0, tool_images_1.buildToolImagesMessage)(batchToolImages));
|
|
3075
|
+
// Responses-API providers keep native input; rebuild it so the images reach the next call.
|
|
3076
|
+
providerRuntime.resetTurnState(messages);
|
|
961
3077
|
}
|
|
962
|
-
(0, tool_loop_1.recordToolOutcome)(toolLoopState, tc.name, args, toolResult, success);
|
|
963
|
-
callbacks.onToolEnd(tc.name, argSummary, success);
|
|
964
|
-
messages.push({ role: "tool", tool_call_id: tc.id, content: toolResult });
|
|
965
|
-
providerRuntime.appendToolOutput(tc.id, toolResult);
|
|
966
3078
|
}
|
|
967
3079
|
}
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
overflowRetried = true;
|
|
979
|
-
stripLastToolCalls(messages);
|
|
980
|
-
const { maxTokens, contextMargin } = (0, config_1.getContextConfig)();
|
|
981
|
-
const trimmed = (0, context_1.trimMessages)(messages, maxTokens, contextMargin, maxTokens * 2);
|
|
982
|
-
messages.splice(0, messages.length, ...trimmed);
|
|
983
|
-
providerRuntime.resetTurnState(messages);
|
|
984
|
-
callbacks.onError(new Error("context trimmed, retrying..."), "transient");
|
|
985
|
-
continue;
|
|
986
|
-
}
|
|
987
|
-
// Transient errors: retry with exponential backoff
|
|
988
|
-
if (isTransientError(e) && retryCount < MAX_RETRIES) {
|
|
989
|
-
retryCount++;
|
|
990
|
-
const delay = RETRY_BASE_MS * Math.pow(2, retryCount - 1);
|
|
991
|
-
let classification;
|
|
3080
|
+
catch (e) {
|
|
3081
|
+
// Abort is not an error — just stop cleanly
|
|
3082
|
+
if (e instanceof provider_attempt_1.ProviderAttemptAbortError || signal?.aborted) {
|
|
3083
|
+
if (generatedMessages.length === 0)
|
|
3084
|
+
stripLastToolCalls(messages);
|
|
3085
|
+
outcome = "aborted";
|
|
3086
|
+
break;
|
|
3087
|
+
}
|
|
3088
|
+
const errorForClassification = e instanceof Error ? e : /* v8 ignore next -- defensive @preserve */ new Error(String(e));
|
|
3089
|
+
let providerClassification;
|
|
992
3090
|
try {
|
|
993
|
-
|
|
3091
|
+
providerClassification = providerRuntime.classifyError(errorForClassification);
|
|
994
3092
|
}
|
|
995
3093
|
catch {
|
|
996
3094
|
/* v8 ignore next -- defensive: classifyError should not throw @preserve */
|
|
997
|
-
|
|
998
|
-
}
|
|
999
|
-
/* v8 ignore next -- defensive: all classifications have labels @preserve */
|
|
1000
|
-
const cause = TRANSIENT_RETRY_LABELS[classification] ?? classification;
|
|
1001
|
-
callbacks.onError(new Error(`${cause}, retrying in ${delay / 1000}s (${retryCount}/${MAX_RETRIES})...`), "transient");
|
|
1002
|
-
// Wait with abort support
|
|
1003
|
-
const aborted = await new Promise((resolve) => {
|
|
1004
|
-
const timer = setTimeout(() => resolve(false), delay);
|
|
1005
|
-
if (signal) {
|
|
1006
|
-
const onAbort = () => { clearTimeout(timer); resolve(true); };
|
|
1007
|
-
if (signal.aborted) {
|
|
1008
|
-
clearTimeout(timer);
|
|
1009
|
-
resolve(true);
|
|
1010
|
-
return;
|
|
1011
|
-
}
|
|
1012
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
1013
|
-
}
|
|
1014
|
-
});
|
|
1015
|
-
if (aborted) {
|
|
1016
|
-
stripLastToolCalls(messages);
|
|
1017
|
-
outcome = "aborted";
|
|
1018
|
-
break;
|
|
3095
|
+
providerClassification = "unknown";
|
|
1019
3096
|
}
|
|
1020
|
-
|
|
1021
|
-
continue;
|
|
1022
|
-
}
|
|
1023
|
-
terminalError = e instanceof Error ? e : new Error(String(e));
|
|
1024
|
-
try {
|
|
1025
|
-
terminalErrorClassification = providerRuntime.classifyError(terminalError);
|
|
1026
|
-
}
|
|
1027
|
-
catch {
|
|
1028
|
-
/* v8 ignore next -- defensive: classifyError should not throw @preserve */
|
|
1029
|
-
terminalErrorClassification = "unknown";
|
|
3097
|
+
finishTerminalProviderError(errorForClassification, providerClassification);
|
|
1030
3098
|
}
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
3099
|
+
}
|
|
3100
|
+
}
|
|
3101
|
+
catch (error) {
|
|
3102
|
+
if (!(error instanceof tools_1.ToolSelectionError))
|
|
3103
|
+
throw error;
|
|
3104
|
+
finishTerminalProviderError(error, "unknown");
|
|
3105
|
+
}
|
|
3106
|
+
finally {
|
|
3107
|
+
nextAttemptControls = [];
|
|
3108
|
+
rejectedAttempt = [];
|
|
3109
|
+
providerRuntime.resetTurnState(messages);
|
|
3110
|
+
}
|
|
3111
|
+
options?.captureGeneratedMessages?.(structuredClone(generatedMessages));
|
|
3112
|
+
if (servedByProvider && !terminalError) {
|
|
3113
|
+
const chain = fallbackChain.length > 0 ? fallbackChain : [{ provider: providerRuntime.id, model: providerRuntime.model }];
|
|
3114
|
+
try {
|
|
3115
|
+
(0, provider_fallback_1.noteProviderServed)({
|
|
3116
|
+
agentName: owner?.agentName ?? (0, identity_2.getAgentName)(),
|
|
3117
|
+
agentRoot: owner?.agentRoot ?? (0, identity_2.getAgentRoot)(),
|
|
3118
|
+
lane: providerLaneForFacing(facing),
|
|
3119
|
+
chain,
|
|
3120
|
+
index: fallbackChain.length > 0 ? chainIndex : 0,
|
|
1039
3121
|
});
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
3122
|
+
/* v8 ignore next 3 -- defensive: attribution must never fail a turn that already answered @preserve */
|
|
3123
|
+
}
|
|
3124
|
+
catch {
|
|
3125
|
+
// The answer stands; attribution is best effort.
|
|
1043
3126
|
}
|
|
1044
3127
|
}
|
|
1045
3128
|
(0, runtime_1.emitNervesEvent)({
|
|
@@ -1053,6 +3136,7 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
1053
3136
|
usage: lastUsage,
|
|
1054
3137
|
outcome,
|
|
1055
3138
|
completion,
|
|
3139
|
+
...(suspension ? { suspension } : {}),
|
|
1056
3140
|
...(terminalError ? { error: terminalError, errorClassification: terminalErrorClassification } : {}),
|
|
1057
3141
|
};
|
|
1058
3142
|
}
|