@ouro.bot/cli 0.1.0-alpha.62 → 0.1.0-alpha.637
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/README.md +127 -23
- 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/changelog.json +4087 -13
- package/dist/arc/attention-types.js +8 -0
- package/dist/arc/cares.js +144 -0
- package/dist/arc/episodes.js +118 -0
- package/dist/arc/evolution.js +487 -0
- package/dist/arc/intentions.js +134 -0
- package/dist/arc/json-store.js +117 -0
- package/dist/arc/obligations.js +270 -0
- package/dist/arc/packets.js +288 -0
- package/dist/arc/presence.js +185 -0
- package/dist/arc/task-lifecycle.js +57 -0
- package/dist/heart/active-work.js +860 -43
- package/dist/heart/agent-entry.js +69 -3
- package/dist/heart/attachments/image-normalize.js +194 -0
- package/dist/heart/attachments/materialize.js +97 -0
- package/dist/heart/attachments/originals.js +88 -0
- package/dist/heart/attachments/render.js +29 -0
- package/dist/heart/attachments/sources/bluebubbles.js +156 -0
- package/dist/heart/attachments/sources/cli-local-file.js +78 -0
- package/dist/heart/attachments/sources/index.js +16 -0
- package/dist/heart/attachments/store.js +103 -0
- package/dist/heart/attachments/types.js +93 -0
- package/dist/heart/auth/auth-flow.js +479 -0
- package/dist/heart/awaiting/await-alert.js +146 -0
- package/dist/heart/awaiting/await-expiry.js +108 -0
- package/dist/heart/awaiting/await-loader.js +91 -0
- package/dist/heart/awaiting/await-parser.js +141 -0
- package/dist/heart/awaiting/await-runtime-state.js +100 -0
- package/dist/heart/awaiting/await-scheduler.js +377 -0
- package/dist/heart/background-operations.js +281 -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/commitments.js +135 -0
- package/dist/heart/config-registry.js +322 -0
- package/dist/heart/config.js +114 -119
- package/dist/heart/core.js +1028 -248
- package/dist/heart/cross-chat-delivery.js +3 -18
- package/dist/heart/daemon/agent-config-check.js +419 -0
- package/dist/heart/daemon/agent-discovery.js +102 -3
- package/dist/heart/daemon/agent-service.js +522 -0
- package/dist/heart/daemon/agentic-repair.js +547 -0
- package/dist/heart/daemon/bluebubbles-health-diagnostics.js +122 -0
- package/dist/heart/daemon/boot-sync-probe.js +197 -0
- package/dist/heart/daemon/cadence.js +70 -0
- package/dist/heart/daemon/cli-defaults.js +776 -0
- package/dist/heart/daemon/cli-desk.js +322 -0
- package/dist/heart/daemon/cli-exec.js +7468 -0
- package/dist/heart/daemon/cli-help.js +505 -0
- package/dist/heart/daemon/cli-parse.js +1554 -0
- package/dist/heart/daemon/cli-render-doctor.js +57 -0
- package/dist/heart/daemon/cli-render.js +763 -0
- package/dist/heart/daemon/cli-types.js +8 -0
- package/dist/heart/daemon/connect-bay.js +323 -0
- package/dist/heart/daemon/daemon-cli.js +29 -1700
- package/dist/heart/daemon/daemon-entry.js +485 -2
- package/dist/heart/daemon/daemon-health.js +176 -0
- package/dist/heart/daemon/daemon-rollup.js +57 -0
- package/dist/heart/daemon/daemon-runtime-sync.js +88 -13
- package/dist/heart/daemon/daemon-tombstone.js +236 -0
- package/dist/heart/daemon/daemon.js +906 -71
- package/dist/heart/daemon/dns-workflow.js +394 -0
- package/dist/heart/daemon/doctor-types.js +8 -0
- package/dist/heart/daemon/doctor.js +873 -0
- package/dist/heart/daemon/health-monitor.js +122 -1
- package/dist/heart/daemon/hooks/agent-config-v2.js +33 -0
- package/dist/heart/daemon/hooks/bundle-meta.js +115 -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 +89 -0
- package/dist/heart/daemon/interactive-repair.js +394 -0
- package/dist/heart/daemon/launchd.js +37 -8
- package/dist/heart/daemon/log-tailer.js +79 -10
- package/dist/heart/daemon/logs-prune.js +110 -0
- package/dist/heart/daemon/mcp-canary.js +297 -0
- package/dist/heart/daemon/migrate-to-desk.js +848 -0
- package/dist/heart/daemon/os-cron-deps.js +135 -0
- package/dist/heart/daemon/os-cron.js +14 -12
- package/dist/heart/daemon/ouro-bot-entry.js +4 -2
- package/dist/heart/daemon/ouro-entry.js +3 -1
- package/dist/heart/daemon/plugin-cli.js +432 -0
- package/dist/heart/daemon/process-manager.js +501 -35
- package/dist/heart/daemon/provider-discovery.js +137 -0
- package/dist/heart/daemon/provider-ping-progress.js +83 -0
- package/dist/heart/daemon/pulse.js +475 -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 +11 -3
- package/dist/heart/daemon/runtime-metadata.js +2 -30
- package/dist/heart/daemon/safe-mode.js +161 -0
- package/dist/heart/daemon/sense-manager.js +493 -38
- package/dist/heart/daemon/session-id-resolver.js +131 -0
- package/dist/heart/daemon/skill-management-installer.js +22 -9
- package/dist/heart/daemon/socket-client.js +158 -11
- package/dist/heart/daemon/stale-bundle-prune.js +96 -0
- package/dist/heart/daemon/startup-tui.js +330 -0
- package/dist/heart/daemon/task-scheduler.js +117 -39
- package/dist/heart/daemon/terminal-ui.js +499 -0
- package/dist/heart/daemon/thoughts.js +229 -17
- package/dist/heart/daemon/up-progress.js +366 -0
- package/dist/heart/daemon/vault-items.js +56 -0
- package/dist/heart/delegation.js +1 -4
- package/dist/heart/habits/habit-migration.js +189 -0
- package/dist/heart/habits/habit-parser.js +140 -0
- package/dist/heart/habits/habit-runtime-state.js +100 -0
- package/dist/heart/habits/habit-scheduler.js +372 -0
- package/dist/heart/{daemon → hatch}/hatch-flow.js +32 -56
- package/dist/heart/{daemon → hatch}/hatch-specialist.js +6 -8
- package/dist/heart/{daemon → hatch}/specialist-prompt.js +12 -9
- package/dist/heart/{daemon → hatch}/specialist-tools.js +37 -14
- package/dist/heart/identity.js +168 -57
- package/dist/heart/kept-notes.js +357 -0
- package/dist/heart/kicks.js +1 -1
- package/dist/heart/machine-identity.js +161 -0
- package/dist/heart/mail-import-discovery.js +353 -0
- package/dist/heart/mailbox/mailbox-http-hooks.js +66 -0
- package/dist/heart/mailbox/mailbox-http-response.js +7 -0
- package/dist/heart/mailbox/mailbox-http-routes.js +246 -0
- package/dist/heart/mailbox/mailbox-http-static.js +103 -0
- package/dist/heart/mailbox/mailbox-http-transport.js +116 -0
- package/dist/heart/mailbox/mailbox-http.js +99 -0
- package/dist/heart/mailbox/mailbox-read.js +31 -0
- package/dist/heart/mailbox/mailbox-types.js +27 -0
- package/dist/heart/mailbox/mailbox-view.js +197 -0
- package/dist/heart/mailbox/readers/agent-machine.js +418 -0
- package/dist/heart/mailbox/readers/continuity-readers.js +319 -0
- package/dist/heart/mailbox/readers/mail.js +375 -0
- package/dist/heart/mailbox/readers/runtime-readers.js +756 -0
- package/dist/heart/mailbox/readers/sessions.js +232 -0
- package/dist/heart/mailbox/readers/shared.js +111 -0
- package/dist/heart/mcp/mcp-server.js +692 -0
- package/dist/heart/migrate-config.js +100 -0
- package/dist/heart/model-capabilities.js +19 -0
- package/dist/heart/orientation-frame.js +217 -0
- package/dist/heart/platform.js +81 -0
- package/dist/heart/provider-attempt.js +134 -0
- package/dist/heart/provider-binding-resolver.js +272 -0
- package/dist/heart/provider-credentials.js +425 -0
- package/dist/heart/provider-failover.js +301 -0
- package/dist/heart/provider-models.js +81 -0
- package/dist/heart/provider-ping.js +262 -0
- package/dist/heart/provider-readiness-cache.js +40 -0
- package/dist/heart/provider-visibility.js +188 -0
- package/dist/heart/providers/anthropic-token.js +131 -0
- package/dist/heart/providers/anthropic.js +139 -52
- package/dist/heart/providers/azure.js +23 -11
- package/dist/heart/providers/error-classification.js +127 -0
- package/dist/heart/providers/github-copilot.js +145 -0
- package/dist/heart/providers/minimax-vlm.js +189 -0
- package/dist/heart/providers/minimax.js +26 -8
- package/dist/heart/providers/openai-codex.js +55 -40
- package/dist/heart/runtime-capability-check.js +170 -0
- package/dist/heart/runtime-credentials.js +367 -0
- package/dist/heart/runtime-cwd.js +87 -0
- package/dist/heart/sense-truth.js +13 -4
- package/dist/heart/session-activity.js +48 -24
- package/dist/heart/session-events.js +1163 -0
- package/dist/heart/session-playback-cli-main.js +5 -0
- package/dist/heart/session-playback-cli.js +36 -0
- package/dist/heart/session-playback.js +231 -0
- package/dist/heart/session-stats-cli-main.js +5 -0
- package/dist/heart/session-stats.js +182 -0
- package/dist/heart/session-transcript.js +133 -0
- package/dist/heart/start-of-turn-packet.js +345 -0
- package/dist/heart/streaming.js +44 -27
- package/dist/heart/structured-output.js +196 -0
- package/dist/heart/sync-classification.js +176 -0
- package/dist/heart/sync.js +449 -0
- package/dist/heart/target-resolution.js +9 -5
- package/dist/heart/tempo.js +93 -0
- package/dist/heart/temporal-view.js +41 -0
- package/dist/heart/timeouts.js +101 -0
- package/dist/heart/tool-activity-callbacks.js +59 -0
- package/dist/heart/tool-description.js +143 -0
- package/dist/heart/tool-friction.js +55 -0
- package/dist/heart/tool-loop.js +200 -0
- package/dist/heart/turn-context.js +389 -0
- package/dist/heart/{daemon → versioning}/ouro-bot-global-installer.js +6 -5
- package/dist/heart/{daemon → versioning}/ouro-bot-wrapper.js +1 -1
- package/dist/heart/versioning/ouro-path-installer.js +426 -0
- package/dist/heart/versioning/ouro-version-manager.js +295 -0
- package/dist/heart/{daemon → versioning}/staged-restart.js +40 -8
- package/dist/heart/{daemon → versioning}/update-checker.js +6 -1
- package/dist/heart/{daemon → versioning}/update-hooks.js +63 -59
- package/dist/mailbox-ui/assets/index-9-AxCxuB.js +61 -0
- package/dist/mailbox-ui/assets/index-CWzt267f.css +1 -0
- package/dist/mailbox-ui/index.html +15 -0
- package/dist/mailroom/attention.js +167 -0
- package/dist/mailroom/autonomy.js +209 -0
- package/dist/mailroom/blob-store.js +715 -0
- package/dist/mailroom/body-cache.js +61 -0
- package/dist/mailroom/core.js +788 -0
- package/dist/mailroom/entry.js +160 -0
- package/dist/mailroom/file-store.js +568 -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 +233 -0
- package/dist/mailroom/search-cache.js +334 -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/thread.js +109 -0
- package/dist/mailroom/travel-extract.js +89 -0
- package/dist/mind/bundle-manifest.js +14 -1
- package/dist/mind/context.js +251 -101
- package/dist/mind/desk-section.js +310 -0
- package/dist/mind/diary-integrity.js +60 -0
- package/dist/mind/{memory.js → diary.js} +68 -76
- package/dist/mind/embedding-provider.js +60 -0
- package/dist/mind/file-state.js +179 -0
- package/dist/mind/friends/channel.js +39 -0
- package/dist/mind/friends/resolver.js +54 -2
- package/dist/mind/friends/store-file.js +48 -4
- package/dist/mind/friends/types.js +2 -2
- package/dist/mind/journal-index.js +162 -0
- package/dist/mind/note-search.js +268 -0
- package/dist/mind/obligation-steering.js +221 -0
- package/dist/mind/pending.js +6 -1
- package/dist/mind/prompt-refresh.js +3 -2
- package/dist/mind/prompt.js +1075 -146
- package/dist/mind/provenance-trust.js +26 -0
- package/dist/mind/scrutiny.js +173 -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.js +1 -1
- package/dist/nerves/coverage/contract.js +5 -5
- package/dist/nerves/coverage/file-completeness.js +139 -5
- package/dist/nerves/event-buffer.js +111 -0
- package/dist/nerves/index.js +224 -4
- package/dist/nerves/observation.js +20 -0
- package/dist/nerves/redact.js +79 -0
- package/dist/nerves/review/cli-main.js +5 -0
- package/dist/nerves/review/cli.js +156 -0
- package/dist/nerves/review/core.js +152 -0
- package/dist/nerves/runtime.js +5 -1
- package/dist/repertoire/ado-client.js +15 -56
- package/dist/repertoire/ado-semantic.js +16 -10
- package/dist/repertoire/api-client.js +97 -0
- package/dist/repertoire/bitwarden-store.js +1040 -0
- package/dist/repertoire/bundle-templates.js +72 -0
- package/dist/repertoire/bw-installer.js +180 -0
- package/dist/repertoire/coding/codex-jsonl.js +64 -0
- package/dist/repertoire/coding/context-pack.js +331 -0
- package/dist/repertoire/coding/feedback.js +197 -30
- package/dist/repertoire/coding/manager.js +166 -10
- package/dist/repertoire/coding/spawner.js +55 -9
- package/dist/repertoire/coding/tools.js +219 -7
- package/dist/repertoire/commerce-errors.js +109 -0
- package/dist/repertoire/commerce-self-test.js +156 -0
- package/dist/repertoire/credential-access.js +178 -0
- package/dist/repertoire/desk/classifier.js +362 -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 +385 -0
- package/dist/repertoire/mcp-client.js +295 -0
- package/dist/repertoire/mcp-manager.js +403 -0
- package/dist/repertoire/mcp-tools.js +83 -0
- package/dist/repertoire/plugin-mcp.js +175 -0
- package/dist/repertoire/plugins.js +253 -0
- package/dist/repertoire/shell-sessions.js +133 -0
- package/dist/repertoire/skills.js +48 -4
- package/dist/repertoire/stripe-client.js +131 -0
- package/dist/repertoire/tool-results.js +29 -0
- package/dist/repertoire/tools-attachments.js +317 -0
- package/dist/repertoire/tools-awaiting.js +372 -0
- package/dist/repertoire/tools-base.js +59 -1082
- package/dist/repertoire/tools-bluebubbles.js +2 -0
- package/dist/repertoire/tools-bridge.js +144 -0
- package/dist/repertoire/tools-bundle.js +993 -0
- package/dist/repertoire/tools-config.js +186 -0
- package/dist/repertoire/tools-continuity.js +252 -0
- package/dist/repertoire/tools-credential.js +383 -0
- package/dist/repertoire/tools-evolution.js +527 -0
- package/dist/repertoire/tools-files.js +344 -0
- package/dist/repertoire/tools-flight.js +227 -0
- package/dist/repertoire/tools-flow.js +119 -0
- package/dist/repertoire/tools-github.js +3 -8
- package/dist/repertoire/tools-mail.js +1975 -0
- package/dist/repertoire/tools-notes.js +438 -0
- package/dist/repertoire/tools-obligations.js +143 -0
- package/dist/repertoire/tools-orientation.js +31 -0
- package/dist/repertoire/tools-record.js +464 -0
- package/dist/repertoire/tools-runtime.js +150 -0
- package/dist/repertoire/tools-session.js +766 -0
- package/dist/repertoire/tools-shell.js +120 -0
- package/dist/repertoire/tools-stripe.js +182 -0
- package/dist/repertoire/tools-surface.js +344 -0
- package/dist/repertoire/tools-teams.js +12 -39
- package/dist/repertoire/tools-travel.js +125 -0
- package/dist/repertoire/tools-trip.js +982 -0
- package/dist/repertoire/tools-user-profile.js +146 -0
- package/dist/repertoire/tools-vault.js +40 -0
- package/dist/repertoire/tools-voice.js +145 -0
- package/dist/repertoire/tools.js +215 -103
- package/dist/repertoire/travel-api-client.js +360 -0
- package/dist/repertoire/user-profile.js +131 -0
- package/dist/repertoire/vault-setup.js +246 -0
- package/dist/repertoire/vault-unlock.js +594 -0
- package/dist/scripts/claude-code-hook.js +41 -0
- package/dist/scripts/claude-code-stop-hook.js +47 -0
- package/dist/senses/attention-queue.js +186 -0
- package/dist/senses/await-turn-message.js +58 -0
- package/dist/senses/bluebubbles/active-turns.js +216 -0
- package/dist/senses/bluebubbles/attachment-cache.js +53 -0
- package/dist/senses/bluebubbles/attachment-download.js +137 -0
- package/dist/senses/{bluebubbles-client.js → bluebubbles/client.js} +219 -18
- package/dist/senses/bluebubbles/entry.js +77 -0
- package/dist/senses/{bluebubbles-inbound-log.js → bluebubbles/inbound-log.js} +20 -3
- package/dist/senses/bluebubbles/index.js +2737 -0
- package/dist/senses/{bluebubbles-media.js → bluebubbles/media.js} +121 -71
- package/dist/senses/{bluebubbles-model.js → bluebubbles/model.js} +33 -12
- package/dist/senses/{bluebubbles-mutation-log.js → bluebubbles/mutation-log.js} +3 -3
- package/dist/senses/bluebubbles/processed-log.js +133 -0
- package/dist/senses/bluebubbles/replay.js +137 -0
- package/dist/senses/{bluebubbles-runtime-state.js → bluebubbles/runtime-state.js} +30 -2
- package/dist/senses/{bluebubbles-session-cleanup.js → bluebubbles/session-cleanup.js} +1 -1
- package/dist/senses/bluebubbles-meta-guard.js +40 -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 +174 -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 +607 -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 +240 -0
- package/dist/senses/cli/virtual-list.js +35 -0
- package/dist/senses/cli-entry.js +60 -8
- package/dist/senses/cli-layout.js +100 -0
- package/dist/senses/cli.js +517 -204
- package/dist/senses/commands.js +66 -3
- package/dist/senses/habit-turn-message.js +108 -0
- package/dist/senses/inner-dialog-worker.js +254 -22
- package/dist/senses/inner-dialog.js +505 -40
- package/dist/senses/mail-entry.js +66 -0
- package/dist/senses/mail.js +379 -0
- package/dist/senses/pipeline.js +666 -181
- package/dist/senses/proactive-content-guard.js +51 -0
- package/dist/senses/shared-turn.js +393 -0
- package/dist/senses/surface-tool.js +108 -0
- package/dist/senses/teams-entry.js +60 -8
- package/dist/senses/teams.js +388 -98
- package/dist/senses/trust-gate.js +100 -5
- package/dist/senses/voice/audio-playback.js +237 -0
- package/dist/senses/voice/audio-routing.js +119 -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/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/realtime-eval.js +496 -0
- package/dist/senses/voice/realtime-trace.js +531 -0
- package/dist/senses/voice/transcript.js +70 -0
- package/dist/senses/voice/turn.js +191 -0
- package/dist/senses/voice/twilio-phone-runtime.js +807 -0
- package/dist/senses/voice/twilio-phone.js +5079 -0
- package/dist/senses/voice/types.js +2 -0
- package/dist/senses/voice/whisper.js +161 -0
- package/dist/senses/voice-entry.js +81 -0
- package/dist/senses/voice-realtime-eval-command.js +99 -0
- package/dist/senses/voice-realtime-eval-entry.js +21 -0
- package/dist/senses/voice-twilio-entry.js +87 -0
- package/dist/trips/core.js +138 -0
- package/dist/trips/store.js +265 -0
- package/dist/util/frontmatter.js +53 -0
- package/package.json +48 -8
- package/skills/agent-commerce.md +106 -0
- package/skills/browser-navigation.md +117 -0
- package/skills/commerce-setup-guide.md +116 -0
- package/skills/commerce-setup.md +84 -0
- package/skills/configure-dev-tools.md +99 -0
- package/skills/travel-planning.md +138 -0
- package/dist/heart/daemon/auth-flow.js +0 -351
- package/dist/heart/daemon/ouro-path-installer.js +0 -178
- package/dist/heart/safe-workspace.js +0 -228
- package/dist/heart/session-recall.js +0 -116
- package/dist/mind/associative-recall.js +0 -209
- 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 -173
- package/dist/repertoire/tasks/scanner.js +0 -132
- package/dist/repertoire/tasks/transitions.js +0 -144
- package/dist/senses/bluebubbles-entry.js +0 -13
- package/dist/senses/bluebubbles.js +0 -1177
- package/dist/senses/debug-activity.js +0 -148
- 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/heart/core.js
CHANGED
|
@@ -1,71 +1,103 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hasToolIntent = exports.buildSystem = exports.toResponsesTools = exports.toResponsesInput = exports.streamResponsesApi = exports.streamChatCompletion = exports.getToolsForChannel = exports.summarizeArgs = exports.execTool = exports.tools = void 0;
|
|
4
3
|
exports.createProviderRegistry = createProviderRegistry;
|
|
5
4
|
exports.resetProviderRuntime = resetProviderRuntime;
|
|
6
5
|
exports.getModel = getModel;
|
|
7
6
|
exports.getProvider = getProvider;
|
|
8
7
|
exports.createSummarize = createSummarize;
|
|
9
8
|
exports.getProviderDisplayLabel = getProviderDisplayLabel;
|
|
9
|
+
exports.isChatStyleChannel = isChatStyleChannel;
|
|
10
|
+
exports.buildPonderResult = buildPonderResult;
|
|
11
|
+
exports.isExternalStateQuery = isExternalStateQuery;
|
|
12
|
+
exports.getSettleRetryError = getSettleRetryError;
|
|
10
13
|
exports.stripLastToolCalls = stripLastToolCalls;
|
|
11
14
|
exports.repairOrphanedToolCalls = repairOrphanedToolCalls;
|
|
12
|
-
exports.isTransientError = isTransientError;
|
|
13
|
-
exports.classifyTransientError = classifyTransientError;
|
|
14
15
|
exports.runAgent = runAgent;
|
|
15
16
|
const config_1 = require("./config");
|
|
16
17
|
const identity_1 = require("./identity");
|
|
17
18
|
const tools_1 = require("../repertoire/tools");
|
|
18
19
|
const channel_1 = require("../mind/friends/channel");
|
|
20
|
+
const tools_2 = require("../repertoire/tools");
|
|
19
21
|
const runtime_1 = require("../nerves/runtime");
|
|
20
22
|
const context_1 = require("../mind/context");
|
|
21
23
|
const prompt_1 = require("../mind/prompt");
|
|
22
|
-
const
|
|
24
|
+
const kept_notes_1 = require("./kept-notes");
|
|
25
|
+
const error_classification_1 = require("./providers/error-classification");
|
|
23
26
|
const anthropic_1 = require("./providers/anthropic");
|
|
24
27
|
const azure_1 = require("./providers/azure");
|
|
25
28
|
const minimax_1 = require("./providers/minimax");
|
|
26
29
|
const openai_codex_1 = require("./providers/openai-codex");
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
30
|
+
const github_copilot_1 = require("./providers/github-copilot");
|
|
31
|
+
const identity_2 = require("./identity");
|
|
32
|
+
const socket_client_1 = require("./daemon/socket-client");
|
|
33
|
+
const obligations_1 = require("../arc/obligations");
|
|
34
|
+
const tool_loop_1 = require("./tool-loop");
|
|
35
|
+
const packets_1 = require("../arc/packets");
|
|
36
|
+
const tool_friction_1 = require("./tool-friction");
|
|
37
|
+
const provider_models_1 = require("./provider-models");
|
|
38
|
+
const provider_credentials_1 = require("./provider-credentials");
|
|
39
|
+
const provider_attempt_1 = require("./provider-attempt");
|
|
40
|
+
const _providerRuntimes = {
|
|
41
|
+
human: null,
|
|
42
|
+
agent: null,
|
|
43
|
+
};
|
|
44
|
+
function providerLaneForFacing(facing) {
|
|
45
|
+
return facing === "human" ? "outward" : "inner";
|
|
46
|
+
}
|
|
47
|
+
function resolveRuntimeProviderBinding(facing) {
|
|
48
|
+
const lane = providerLaneForFacing(facing);
|
|
49
|
+
const config = (0, identity_1.loadAgentConfig)();
|
|
50
|
+
const facingConfig = facing === "human" ? config.humanFacing : config.agentFacing;
|
|
51
|
+
return { lane, provider: facingConfig.provider, model: facingConfig.model };
|
|
52
|
+
}
|
|
53
|
+
async function getProviderRuntimeFingerprint(facing) {
|
|
54
|
+
const agentName = (0, identity_2.getAgentName)();
|
|
55
|
+
const binding = resolveRuntimeProviderBinding(facing);
|
|
56
|
+
const credential = await (0, provider_credentials_1.readProviderCredentialRecord)(agentName, binding.provider);
|
|
57
|
+
if (!credential.ok) {
|
|
58
|
+
throw new Error([
|
|
59
|
+
`${binding.lane} provider ${binding.provider} (${binding.model}) has no credentials for ${agentName}.`,
|
|
60
|
+
credential.error,
|
|
61
|
+
`Run \`ouro auth --agent ${agentName} --provider ${binding.provider}\`.`,
|
|
62
|
+
].join("\n"));
|
|
47
63
|
}
|
|
64
|
+
return {
|
|
65
|
+
binding,
|
|
66
|
+
fingerprint: JSON.stringify({
|
|
67
|
+
lane: binding.lane,
|
|
68
|
+
provider: binding.provider,
|
|
69
|
+
model: binding.model,
|
|
70
|
+
credentialRevision: credential.record.revision,
|
|
71
|
+
}),
|
|
72
|
+
credential: credential.record,
|
|
73
|
+
};
|
|
48
74
|
}
|
|
49
75
|
function createProviderRegistry() {
|
|
50
|
-
const factories = {
|
|
51
|
-
azure: azure_1.createAzureProviderRuntime,
|
|
52
|
-
anthropic: anthropic_1.createAnthropicProviderRuntime,
|
|
53
|
-
minimax: minimax_1.createMinimaxProviderRuntime,
|
|
54
|
-
"openai-codex": openai_codex_1.createOpenAICodexProviderRuntime,
|
|
55
|
-
};
|
|
56
76
|
return {
|
|
57
|
-
resolve() {
|
|
58
|
-
const
|
|
59
|
-
|
|
77
|
+
resolve(provider, model, credential) {
|
|
78
|
+
const providerConfig = { ...credential.config, ...credential.credentials };
|
|
79
|
+
switch (provider) {
|
|
80
|
+
case "azure":
|
|
81
|
+
return (0, azure_1.createAzureProviderRuntime)(model, providerConfig);
|
|
82
|
+
case "anthropic":
|
|
83
|
+
return (0, anthropic_1.createAnthropicProviderRuntime)(model, providerConfig);
|
|
84
|
+
case "minimax":
|
|
85
|
+
return (0, minimax_1.createMinimaxProviderRuntime)(model, providerConfig);
|
|
86
|
+
case "openai-codex":
|
|
87
|
+
return (0, openai_codex_1.createOpenAICodexProviderRuntime)(model, providerConfig);
|
|
88
|
+
case "github-copilot":
|
|
89
|
+
return (0, github_copilot_1.createGithubCopilotProviderRuntime)(model, providerConfig);
|
|
90
|
+
}
|
|
60
91
|
},
|
|
61
92
|
};
|
|
62
93
|
}
|
|
63
|
-
function getProviderRuntime() {
|
|
94
|
+
async function getProviderRuntime(facing = "human") {
|
|
64
95
|
try {
|
|
65
|
-
const fingerprint = getProviderRuntimeFingerprint();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
96
|
+
const { binding, fingerprint, credential } = await getProviderRuntimeFingerprint(facing);
|
|
97
|
+
const cached = _providerRuntimes[facing];
|
|
98
|
+
if (!cached || cached.fingerprint !== fingerprint) {
|
|
99
|
+
const runtime = createProviderRegistry().resolve(binding.provider, binding.model, credential);
|
|
100
|
+
_providerRuntimes[facing] = runtime ? { fingerprint, runtime } : null;
|
|
69
101
|
}
|
|
70
102
|
}
|
|
71
103
|
catch (error) {
|
|
@@ -75,25 +107,26 @@ function getProviderRuntime() {
|
|
|
75
107
|
event: "engine.provider_init_error",
|
|
76
108
|
component: "engine",
|
|
77
109
|
message: msg,
|
|
78
|
-
meta: {},
|
|
110
|
+
meta: { facing },
|
|
79
111
|
});
|
|
80
112
|
// eslint-disable-next-line no-console -- pre-boot guard: provider init failure
|
|
81
113
|
console.error(`\n[fatal] ${msg}\n`);
|
|
82
|
-
|
|
83
|
-
throw new Error("unreachable");
|
|
114
|
+
throw error instanceof Error ? error : new Error(msg);
|
|
84
115
|
}
|
|
85
|
-
if (!
|
|
116
|
+
if (!_providerRuntimes[facing]) {
|
|
117
|
+
const msg = "provider runtime could not be initialized.";
|
|
86
118
|
(0, runtime_1.emitNervesEvent)({
|
|
87
119
|
level: "error",
|
|
88
120
|
event: "engine.provider_init_error",
|
|
89
121
|
component: "engine",
|
|
90
|
-
message:
|
|
91
|
-
meta: {},
|
|
122
|
+
message: msg,
|
|
123
|
+
meta: { facing },
|
|
92
124
|
});
|
|
93
|
-
|
|
94
|
-
|
|
125
|
+
// eslint-disable-next-line no-console -- pre-boot guard: provider init failure
|
|
126
|
+
console.error(`\n[fatal] ${msg}\n`);
|
|
127
|
+
throw new Error(msg);
|
|
95
128
|
}
|
|
96
|
-
return
|
|
129
|
+
return _providerRuntimes[facing].runtime;
|
|
97
130
|
}
|
|
98
131
|
/**
|
|
99
132
|
* Clear the cached provider runtime so the next access re-creates it from
|
|
@@ -101,17 +134,18 @@ function getProviderRuntime() {
|
|
|
101
134
|
* provider fingerprint changes on disk.
|
|
102
135
|
*/
|
|
103
136
|
function resetProviderRuntime() {
|
|
104
|
-
|
|
137
|
+
_providerRuntimes.human = null;
|
|
138
|
+
_providerRuntimes.agent = null;
|
|
105
139
|
}
|
|
106
|
-
function getModel() {
|
|
107
|
-
return
|
|
140
|
+
function getModel(facing = "human") {
|
|
141
|
+
return resolveRuntimeProviderBinding(facing).model;
|
|
108
142
|
}
|
|
109
|
-
function getProvider() {
|
|
110
|
-
return
|
|
143
|
+
function getProvider(facing = "human") {
|
|
144
|
+
return resolveRuntimeProviderBinding(facing).provider;
|
|
111
145
|
}
|
|
112
|
-
function createSummarize() {
|
|
146
|
+
function createSummarize(facing = "human") {
|
|
113
147
|
return async (transcript, instruction) => {
|
|
114
|
-
const runtime = getProviderRuntime();
|
|
148
|
+
const runtime = await getProviderRuntime(facing);
|
|
115
149
|
const client = runtime.client;
|
|
116
150
|
const response = await client.chat.completions.create({
|
|
117
151
|
model: runtime.model,
|
|
@@ -124,35 +158,66 @@ function createSummarize() {
|
|
|
124
158
|
return response.choices?.[0]?.message?.content ?? transcript;
|
|
125
159
|
};
|
|
126
160
|
}
|
|
127
|
-
function getProviderDisplayLabel() {
|
|
128
|
-
const
|
|
161
|
+
function getProviderDisplayLabel(facing = "human") {
|
|
162
|
+
const binding = resolveRuntimeProviderBinding(facing);
|
|
163
|
+
const provider = binding.provider;
|
|
164
|
+
const model = binding.model || "unknown";
|
|
129
165
|
const providerLabelBuilders = {
|
|
130
166
|
azure: () => {
|
|
131
|
-
|
|
132
|
-
return `azure openai (${config.deployment || "default"}, model: ${config.modelName || "unknown"})`;
|
|
167
|
+
return `azure openai (model: ${model})`;
|
|
133
168
|
},
|
|
134
|
-
anthropic: () => `anthropic (${
|
|
135
|
-
minimax: () => `minimax (${
|
|
136
|
-
"openai-codex": () => `openai codex (${
|
|
169
|
+
anthropic: () => `anthropic (${model})`,
|
|
170
|
+
minimax: () => `minimax (${model})`,
|
|
171
|
+
"openai-codex": () => `openai codex (${model})`,
|
|
172
|
+
/* v8 ignore next -- branch: tested via display label unit test @preserve */
|
|
173
|
+
"github-copilot": () => `github copilot (${model})`,
|
|
137
174
|
};
|
|
138
175
|
return providerLabelBuilders[provider]();
|
|
139
176
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
177
|
+
/**
|
|
178
|
+
* Strip <think>...</think> blocks for the violation-detection check at the
|
|
179
|
+
* end of a streaming turn. Used to tell legitimate text-only responses
|
|
180
|
+
* apart from the MiniMax-M2.7 "only thinking, no tool call" violation
|
|
181
|
+
* shape. Mirrors the more thorough stripThinkBlocks helper in
|
|
182
|
+
* senses/shared-turn.ts (which is for operator-facing output) — kept
|
|
183
|
+
* inline here to avoid pulling senses/ into the core module's import graph.
|
|
184
|
+
*/
|
|
185
|
+
function stripThinkBlocksForViolationCheck(input) {
|
|
186
|
+
let out = input;
|
|
187
|
+
for (;;) {
|
|
188
|
+
const open = out.indexOf("<think>");
|
|
189
|
+
if (open === -1)
|
|
190
|
+
break;
|
|
191
|
+
const close = out.indexOf("</think>", open + "<think>".length);
|
|
192
|
+
if (close === -1) {
|
|
193
|
+
out = out.slice(0, open);
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
out = out.slice(0, open) + out.slice(close + "</think>".length);
|
|
197
|
+
}
|
|
198
|
+
return out.trim();
|
|
199
|
+
}
|
|
200
|
+
function hasFreshPendingWork(options) {
|
|
201
|
+
const pendingMessages = options?.pendingMessages;
|
|
202
|
+
if (!Array.isArray(pendingMessages))
|
|
203
|
+
return false;
|
|
204
|
+
return pendingMessages.some((message) => typeof message?.content === "string"
|
|
205
|
+
&& message.content.trim().length > 0);
|
|
206
|
+
}
|
|
207
|
+
/** Chat-style channels expose the `speak` tool — outer human-conversation channels
|
|
208
|
+
* where mid-turn delivery is meaningful. Inner dialog has `ponder`. MCP returns
|
|
209
|
+
* synchronously. Mail is batch. Anything else (unknown channel) treats as non-chat. */
|
|
210
|
+
function isChatStyleChannel(channel) {
|
|
211
|
+
return channel === "cli" || channel === "teams" || channel === "bluebubbles" || channel === "voice";
|
|
212
|
+
}
|
|
213
|
+
// Sole-call tools must be the only tool call in a turn. When they appear
|
|
214
|
+
// alongside other tools, the sole-call tool is rejected with this message.
|
|
215
|
+
const SOLE_CALL_REJECTION = {
|
|
216
|
+
settle: "rejected: settle must be the only tool call. finish your work first, then call settle alone.",
|
|
217
|
+
observe: "rejected: observe must be the only tool call. call observe alone when you want to stay silent.",
|
|
218
|
+
rest: "rejected: rest must be the only tool call. finish your work first, then call rest alone.",
|
|
219
|
+
};
|
|
220
|
+
function parseSettlePayload(argumentsText) {
|
|
156
221
|
try {
|
|
157
222
|
const parsed = JSON.parse(argumentsText);
|
|
158
223
|
if (typeof parsed === "string") {
|
|
@@ -172,18 +237,161 @@ function parseFinalAnswerPayload(argumentsText) {
|
|
|
172
237
|
return {};
|
|
173
238
|
}
|
|
174
239
|
}
|
|
175
|
-
function
|
|
240
|
+
function parsePonderPayload(argumentsText) {
|
|
241
|
+
try {
|
|
242
|
+
const parsed = JSON.parse(argumentsText);
|
|
243
|
+
return parsed && typeof parsed === "object" ? parsed : {};
|
|
244
|
+
}
|
|
245
|
+
catch {
|
|
246
|
+
return {};
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
function parseSuccessCriteria(raw) {
|
|
250
|
+
if (typeof raw !== "string")
|
|
251
|
+
return null;
|
|
252
|
+
const criteria = raw
|
|
253
|
+
.split("\n")
|
|
254
|
+
.map((line) => line.replace(/^\s*[-*]\s*/, "").trim())
|
|
255
|
+
.filter((line) => line.length > 0);
|
|
256
|
+
return criteria.length > 0 ? criteria : null;
|
|
257
|
+
}
|
|
258
|
+
function parsePacketPayload(raw) {
|
|
259
|
+
if (typeof raw !== "string")
|
|
260
|
+
return null;
|
|
261
|
+
try {
|
|
262
|
+
const parsed = JSON.parse(raw);
|
|
263
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed)
|
|
264
|
+
? parsed
|
|
265
|
+
: null;
|
|
266
|
+
}
|
|
267
|
+
catch {
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
function normalizeLegacyPonderArgs(parsed) {
|
|
272
|
+
if (typeof parsed.thought !== "string" || parsed.thought.trim().length === 0) {
|
|
273
|
+
return parsed;
|
|
274
|
+
}
|
|
275
|
+
return {
|
|
276
|
+
action: "create",
|
|
277
|
+
kind: "reflection",
|
|
278
|
+
objective: parsed.thought.trim(),
|
|
279
|
+
summary: typeof parsed.say === "string" ? parsed.say.trim() : "",
|
|
280
|
+
success_criteria: "- preserve the thread for later work",
|
|
281
|
+
payload_json: "{}",
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
function messageContentText(content) {
|
|
285
|
+
if (typeof content === "string")
|
|
286
|
+
return content;
|
|
287
|
+
if (!Array.isArray(content))
|
|
288
|
+
return "";
|
|
289
|
+
return content
|
|
290
|
+
.map((part) => {
|
|
291
|
+
if (typeof part === "string")
|
|
292
|
+
return part;
|
|
293
|
+
if (!part || typeof part !== "object")
|
|
294
|
+
return "";
|
|
295
|
+
const maybeText = part.text;
|
|
296
|
+
return typeof maybeText === "string" ? maybeText : "";
|
|
297
|
+
})
|
|
298
|
+
.filter(Boolean)
|
|
299
|
+
.join("\n");
|
|
300
|
+
}
|
|
301
|
+
function latestUserMessageText(messages) {
|
|
302
|
+
for (let i = messages.length - 1; i >= 0; i -= 1) {
|
|
303
|
+
const message = messages[i];
|
|
304
|
+
if (message?.role !== "user")
|
|
305
|
+
continue;
|
|
306
|
+
const text = messageContentText(message.content).trim();
|
|
307
|
+
if (text.length > 0)
|
|
308
|
+
return text;
|
|
309
|
+
}
|
|
310
|
+
return "";
|
|
311
|
+
}
|
|
312
|
+
function truncatePonderDelegatedContent(value) {
|
|
313
|
+
return value.length > 120 ? `${value.slice(0, 117)}...` : value;
|
|
314
|
+
}
|
|
315
|
+
function buildPonderDelegatedContent(input) {
|
|
316
|
+
const primary = (input.summary || input.objective).trim();
|
|
317
|
+
const sourceRequest = input.sourceRequest.trim();
|
|
318
|
+
if (!sourceRequest || sourceRequest === primary || sourceRequest === input.objective.trim()) {
|
|
319
|
+
return truncatePonderDelegatedContent(primary);
|
|
320
|
+
}
|
|
321
|
+
return truncatePonderDelegatedContent(`${primary}\nsource request: ${sourceRequest}`);
|
|
322
|
+
}
|
|
323
|
+
function looksLikePrivateReturnRequest(text) {
|
|
324
|
+
const normalized = text.toLowerCase();
|
|
325
|
+
return /\b(private|privately|private-attention|think|reflect|reflection)\b/.test(normalized)
|
|
326
|
+
&& /\b(return|bring back|come back|surface|report back)\b/.test(normalized);
|
|
327
|
+
}
|
|
328
|
+
function extractPrivateReturnHeldTokens(text) {
|
|
329
|
+
const tokens = new Set();
|
|
330
|
+
for (const match of text.matchAll(/\b[A-Z][A-Z0-9]*(?:_[A-Z0-9]+){2,}\b/g)) {
|
|
331
|
+
const token = match[0];
|
|
332
|
+
if (token.length >= 8)
|
|
333
|
+
tokens.add(token);
|
|
334
|
+
}
|
|
335
|
+
return [...tokens];
|
|
336
|
+
}
|
|
337
|
+
function privateReturnAckLeakError(answer, heldTokens) {
|
|
338
|
+
if (!answer || heldTokens.size === 0)
|
|
339
|
+
return null;
|
|
340
|
+
for (const token of heldTokens) {
|
|
341
|
+
if (answer.includes(token)) {
|
|
342
|
+
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.";
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
347
|
+
function activeReturnObligationId(agentName, obligationId) {
|
|
348
|
+
if (!obligationId)
|
|
349
|
+
return null;
|
|
350
|
+
const obligation = (0, obligations_1.readReturnObligation)(agentName, obligationId);
|
|
351
|
+
return obligation?.status === "queued" || obligation?.status === "running" ? obligationId : null;
|
|
352
|
+
}
|
|
353
|
+
function buildPonderResult(packet, action, returnObligationId) {
|
|
354
|
+
return JSON.stringify({
|
|
355
|
+
ok: true,
|
|
356
|
+
packet_id: packet.id,
|
|
357
|
+
action,
|
|
358
|
+
status: packet.status,
|
|
359
|
+
return_obligation_id: returnObligationId,
|
|
360
|
+
private_return_contract: returnObligationId
|
|
361
|
+
? "queued for inner 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."
|
|
362
|
+
: null,
|
|
363
|
+
}, null, 2);
|
|
364
|
+
}
|
|
365
|
+
/** Returns true when a tool call queries external state (GitHub, npm registry). */
|
|
366
|
+
function isExternalStateQuery(toolName, args) {
|
|
367
|
+
if (toolName !== "shell")
|
|
368
|
+
return false;
|
|
369
|
+
const cmd = String(args.command ?? "");
|
|
370
|
+
return /\bgh\s+(pr|run|api|issue)\b/.test(cmd) || /\bnpm\s+(view|info|show)\b/.test(cmd);
|
|
371
|
+
}
|
|
372
|
+
function getSettleRetryError(mustResolveBeforeHandoff, intent, sawSteeringFollowUp, _delegationDecision, sawSendMessageSelf, sawPonder, _sawQuerySession, currentObligation, innerJob, _sawExternalStateQuery) {
|
|
373
|
+
// Delegation adherence removed: the delegation decision is surfaced in the
|
|
374
|
+
// system prompt as a suggestion. Hard-gating settle caused infinite
|
|
375
|
+
// rejection loops where the agent couldn't respond to the user at all.
|
|
376
|
+
// The agent is free to follow or ignore the delegation hint.
|
|
377
|
+
// 2. Pending obligation not addressed
|
|
378
|
+
if (innerJob?.obligationStatus === "pending" && !sawSendMessageSelf && !sawPonder) {
|
|
379
|
+
return "you're still holding something from an earlier conversation -- someone is waiting for your answer. finish the thought first, or ponder to keep working on it privately.";
|
|
380
|
+
}
|
|
381
|
+
// 3. mustResolveBeforeHandoff + missing intent
|
|
176
382
|
if (mustResolveBeforeHandoff && !intent) {
|
|
177
|
-
return "your
|
|
383
|
+
return "your settle is missing required intent. when you must keep going until done or blocked, call settle again with answer plus intent=complete, blocked, or direct_reply.";
|
|
178
384
|
}
|
|
385
|
+
// 4. mustResolveBeforeHandoff + direct_reply without follow-up
|
|
179
386
|
if (mustResolveBeforeHandoff && intent === "direct_reply" && !sawSteeringFollowUp) {
|
|
180
|
-
return "your
|
|
387
|
+
return "your settle used intent=direct_reply without a newer steering follow-up. continue the unresolved work, or call settle again with intent=complete or blocked when appropriate.";
|
|
181
388
|
}
|
|
182
|
-
|
|
389
|
+
// 5. mustResolveBeforeHandoff + complete while a live return loop is still active
|
|
390
|
+
if (mustResolveBeforeHandoff && intent === "complete" && currentObligation && !sawSteeringFollowUp) {
|
|
391
|
+
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.";
|
|
392
|
+
}
|
|
393
|
+
return null;
|
|
183
394
|
}
|
|
184
|
-
// Re-export kick utilities for backward compat
|
|
185
|
-
var kicks_1 = require("./kicks");
|
|
186
|
-
Object.defineProperty(exports, "hasToolIntent", { enumerable: true, get: function () { return kicks_1.hasToolIntent; } });
|
|
187
395
|
function upsertSystemPrompt(messages, systemText) {
|
|
188
396
|
const systemMessage = { role: "system", content: systemText };
|
|
189
397
|
if (messages[0]?.role === "system") {
|
|
@@ -221,27 +429,39 @@ const TOOL_SCAN_BOUNDARY_ROLES = new Set(["assistant", "user"]);
|
|
|
221
429
|
// 1. If an assistant message has tool_calls but missing tool results, inject synthetic error results.
|
|
222
430
|
// 2. If a tool result's tool_call_id doesn't match any tool_calls in a preceding assistant message, remove it.
|
|
223
431
|
// This prevents 400 errors from the API after an aborted turn.
|
|
432
|
+
//
|
|
433
|
+
// Position-aware: a tool result is orphaned when its tool_call_id hasn't been
|
|
434
|
+
// defined by an assistant message AT THIS POSITION yet. MiniMax-M2.7 reuses
|
|
435
|
+
// canonical tool_call_ids across turns, so the global-set check that this
|
|
436
|
+
// function used previously kept misordered tool results that MiniMax then
|
|
437
|
+
// rejected with error 2013 ("tool result's tool id not found"). Walking
|
|
438
|
+
// in order matches what MiniMax actually enforces.
|
|
224
439
|
function repairOrphanedToolCalls(messages) {
|
|
225
|
-
// Pass 1:
|
|
226
|
-
|
|
227
|
-
|
|
440
|
+
// Pass 1: walk in order, accumulate seen tool_call_ids per-position, and
|
|
441
|
+
// mark tool results for removal if their id hasn't been defined yet.
|
|
442
|
+
const seenCallIds = new Set();
|
|
443
|
+
const removeIndices = [];
|
|
444
|
+
for (let i = 0; i < messages.length; i++) {
|
|
445
|
+
const msg = messages[i];
|
|
228
446
|
if (msg.role === "assistant") {
|
|
229
447
|
const asst = msg;
|
|
230
448
|
if (asst.tool_calls) {
|
|
231
449
|
for (const tc of asst.tool_calls)
|
|
232
|
-
|
|
450
|
+
seenCallIds.add(tc.id);
|
|
233
451
|
}
|
|
452
|
+
continue;
|
|
234
453
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
const toolMsg = messages[i];
|
|
240
|
-
if (!validCallIds.has(toolMsg.tool_call_id)) {
|
|
241
|
-
messages.splice(i, 1);
|
|
454
|
+
if (msg.role === "tool") {
|
|
455
|
+
const toolMsg = msg;
|
|
456
|
+
if (!seenCallIds.has(toolMsg.tool_call_id)) {
|
|
457
|
+
removeIndices.push(i);
|
|
242
458
|
}
|
|
243
459
|
}
|
|
244
460
|
}
|
|
461
|
+
// Splice from the end so earlier indices stay valid.
|
|
462
|
+
for (let i = removeIndices.length - 1; i >= 0; i--) {
|
|
463
|
+
messages.splice(removeIndices[i], 1);
|
|
464
|
+
}
|
|
245
465
|
// Pass 3: inject synthetic results for tool_calls missing their tool results
|
|
246
466
|
for (let i = 0; i < messages.length; i++) {
|
|
247
467
|
const msg = messages[i];
|
|
@@ -263,10 +483,13 @@ function repairOrphanedToolCalls(messages) {
|
|
|
263
483
|
}
|
|
264
484
|
const missing = asst.tool_calls.filter((tc) => !resultIds.has(tc.id));
|
|
265
485
|
if (missing.length > 0) {
|
|
486
|
+
// AX rule: the agent must see what happened. Don't say "interrupted"
|
|
487
|
+
// — that's vague. Tell them the result was lost, possible causes,
|
|
488
|
+
// and what to do next.
|
|
266
489
|
const syntheticResults = missing.map((tc) => ({
|
|
267
490
|
role: "tool",
|
|
268
491
|
tool_call_id: tc.id,
|
|
269
|
-
content: "error: tool call was
|
|
492
|
+
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.",
|
|
270
493
|
}));
|
|
271
494
|
let insertAt = i + 1;
|
|
272
495
|
while (insertAt < messages.length && messages[insertAt].role === "tool")
|
|
@@ -289,49 +512,67 @@ function isContextOverflow(err) {
|
|
|
289
512
|
return true;
|
|
290
513
|
return false;
|
|
291
514
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
515
|
+
const RETRY_LABELS = {
|
|
516
|
+
"auth-failure": "auth error",
|
|
517
|
+
"usage-limit": "usage limit",
|
|
518
|
+
"rate-limit": "rate limited",
|
|
519
|
+
"server-error": "server error",
|
|
520
|
+
"network-error": "network error",
|
|
521
|
+
"unknown": "error",
|
|
522
|
+
};
|
|
523
|
+
function waitForProviderRetry(delayMs, signal) {
|
|
524
|
+
if (!signal) {
|
|
525
|
+
return new Promise((resolve) => {
|
|
526
|
+
setTimeout(resolve, delayMs);
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
return new Promise((resolve, reject) => {
|
|
530
|
+
let timer;
|
|
531
|
+
const onAbort = () => {
|
|
532
|
+
clearTimeout(timer);
|
|
533
|
+
reject(new provider_attempt_1.ProviderAttemptAbortError());
|
|
534
|
+
};
|
|
535
|
+
timer = setTimeout(() => {
|
|
536
|
+
signal.removeEventListener("abort", onAbort);
|
|
537
|
+
resolve();
|
|
538
|
+
}, delayMs);
|
|
539
|
+
if (signal.aborted) {
|
|
540
|
+
onAbort();
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
function buildAuthFailureGuidance(provider, model, agentName, detail) {
|
|
547
|
+
const mismatch = (0, provider_models_1.getProviderModelMismatchMessage)(provider, model);
|
|
548
|
+
const modelLabel = model
|
|
549
|
+
? mismatch
|
|
550
|
+
? `${provider} [configured model: ${model}]`
|
|
551
|
+
: `${provider} (${model})`
|
|
552
|
+
: provider;
|
|
553
|
+
const lines = [`${modelLabel} authentication failed.`];
|
|
554
|
+
const cleanDetail = detail.replace(/\s+/g, " ").trim();
|
|
555
|
+
if (cleanDetail)
|
|
556
|
+
lines.push(`provider detail: ${cleanDetail.length > 300 ? `${cleanDetail.slice(0, 297)}...` : cleanDetail}`);
|
|
557
|
+
lines.push("");
|
|
558
|
+
lines.push("To keep using this provider:");
|
|
559
|
+
lines.push(` 1. Run \`ouro auth --agent ${agentName} --provider ${provider}\``);
|
|
560
|
+
if (mismatch) {
|
|
561
|
+
const defaultModel = (0, provider_models_1.getDefaultModelForProvider)(provider);
|
|
562
|
+
lines.push("");
|
|
563
|
+
lines.push("Config warning:");
|
|
564
|
+
lines.push(` - ${mismatch}`);
|
|
565
|
+
lines.push(" - Repair the configured model with:");
|
|
566
|
+
lines.push(` \`ouro use --agent ${agentName} --lane outward --provider ${provider} --model ${defaultModel}\``);
|
|
567
|
+
lines.push(` \`ouro use --agent ${agentName} --lane inner --provider ${provider} --model ${defaultModel}\``);
|
|
568
|
+
}
|
|
569
|
+
lines.push("");
|
|
570
|
+
lines.push(`To use another configured provider instead, run \`ouro use --agent ${agentName} --lane <outward|inner> --provider <provider> --model <model>\`.`);
|
|
571
|
+
return lines.join("\n");
|
|
318
572
|
}
|
|
319
|
-
function classifyTransientError(err) {
|
|
320
|
-
if (!(err instanceof Error))
|
|
321
|
-
return "unknown error";
|
|
322
|
-
const status = err.status;
|
|
323
|
-
if (status === 429)
|
|
324
|
-
return "rate limited";
|
|
325
|
-
if (status === 401 || status === 403)
|
|
326
|
-
return "auth error";
|
|
327
|
-
if (status && status >= 500)
|
|
328
|
-
return "server error";
|
|
329
|
-
return "network error";
|
|
330
|
-
}
|
|
331
|
-
const MAX_RETRIES = 3;
|
|
332
|
-
const RETRY_BASE_MS = 2000;
|
|
333
573
|
async function runAgent(messages, callbacks, channel, signal, options) {
|
|
334
|
-
const
|
|
574
|
+
const facing = (0, channel_1.channelToFacing)(channel);
|
|
575
|
+
let providerRuntime = await getProviderRuntime(facing);
|
|
335
576
|
const provider = providerRuntime.id;
|
|
336
577
|
const toolChoiceRequired = options?.toolChoiceRequired ?? true;
|
|
337
578
|
const traceId = options?.traceId;
|
|
@@ -355,6 +596,7 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
355
596
|
// Refresh system prompt at start of each turn when channel is provided.
|
|
356
597
|
// If refresh fails, keep existing system prompt (or inject a minimal safe fallback)
|
|
357
598
|
// so turn execution remains consistent and non-fatal.
|
|
599
|
+
let structuredSystemPrompt;
|
|
358
600
|
if (channel) {
|
|
359
601
|
try {
|
|
360
602
|
const buildSystemOptions = {
|
|
@@ -363,7 +605,8 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
363
605
|
supportedReasoningEfforts: providerRuntime.supportedReasoningEfforts,
|
|
364
606
|
};
|
|
365
607
|
const refreshed = await (0, prompt_1.buildSystem)(channel, buildSystemOptions, currentContext);
|
|
366
|
-
|
|
608
|
+
structuredSystemPrompt = refreshed;
|
|
609
|
+
upsertSystemPrompt(messages, (0, prompt_1.flattenSystemPrompt)(refreshed));
|
|
367
610
|
}
|
|
368
611
|
catch (error) {
|
|
369
612
|
const hadExistingSystemPrompt = messages[0]?.role === "system" && typeof messages[0].content === "string";
|
|
@@ -384,40 +627,124 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
384
627
|
});
|
|
385
628
|
}
|
|
386
629
|
}
|
|
387
|
-
|
|
630
|
+
if (channel && options?.skipKeptNotes !== true) {
|
|
631
|
+
await (0, kept_notes_1.injectKeptNotes)(messages, {
|
|
632
|
+
channel,
|
|
633
|
+
friend: currentContext?.friend,
|
|
634
|
+
judge: async (input) => (0, kept_notes_1.createKeptNotesJudge)(await getProviderRuntime("agent"), signal)(input),
|
|
635
|
+
signal,
|
|
636
|
+
traceId,
|
|
637
|
+
});
|
|
638
|
+
}
|
|
388
639
|
let done = false;
|
|
389
640
|
let lastUsage;
|
|
390
641
|
let overflowRetried = false;
|
|
391
|
-
let
|
|
392
|
-
let outcome = "complete";
|
|
642
|
+
let outcome = "settled";
|
|
393
643
|
let completion;
|
|
644
|
+
let terminalError;
|
|
645
|
+
let terminalErrorClassification;
|
|
394
646
|
let sawSteeringFollowUp = false;
|
|
395
647
|
let mustResolveBeforeHandoffActive = options?.mustResolveBeforeHandoff === true;
|
|
396
648
|
let currentReasoningEffort = "medium";
|
|
649
|
+
let sawSendMessageSelf = false;
|
|
650
|
+
let sawPonder = false;
|
|
651
|
+
let sawQuerySession = false;
|
|
652
|
+
let sawBridgeManage = false;
|
|
653
|
+
let sawExternalStateQuery = false;
|
|
654
|
+
const privateReturnHeldTokens = new Set();
|
|
655
|
+
// Once-per-turn flag for the fresh-work rest gate. Without this, an agent
|
|
656
|
+
// that called rest, was told "fresh work arrived", processed the items,
|
|
657
|
+
// and called rest again would get the same message forever — the gate
|
|
658
|
+
// condition is read from the turn-start snapshot of pendingMessages,
|
|
659
|
+
// which doesn't update mid-turn. The agent only needs to be told once;
|
|
660
|
+
// after that, repeated rest attempts mean they've acknowledged.
|
|
661
|
+
let freshWorkGateFired = false;
|
|
662
|
+
// Counter for "no tool call returned despite tool_choice=required" violations.
|
|
663
|
+
// MiniMax reasoning models occasionally emit only a <think>...</think>
|
|
664
|
+
// block and stop, without any tool call — even when tool_choice is set to
|
|
665
|
+
// "required". This is a provider-level violation; the harness retries with
|
|
666
|
+
// a corrective nudge up to a small cap rather than silently accepting an
|
|
667
|
+
// empty turn.
|
|
668
|
+
let noToolCallRetries = 0;
|
|
669
|
+
const NO_TOOL_CALL_MAX_RETRIES = 2;
|
|
670
|
+
const toolLoopState = (0, tool_loop_1.createToolLoopState)();
|
|
671
|
+
const toolFrictionLedger = (0, tool_friction_1.createToolFrictionLedger)();
|
|
672
|
+
const finishTerminalProviderError = (error, classification) => {
|
|
673
|
+
terminalError = error;
|
|
674
|
+
terminalErrorClassification = classification;
|
|
675
|
+
/* v8 ignore start — auth-failure guidance: tested via provider error classification tests @preserve */
|
|
676
|
+
if (terminalErrorClassification === "auth-failure") {
|
|
677
|
+
const agentName = (0, identity_2.getAgentName)();
|
|
678
|
+
const currentProvider = providerRuntime.id;
|
|
679
|
+
callbacks.onError(new Error(buildAuthFailureGuidance(currentProvider, providerRuntime.model, agentName, terminalError.message)), "terminal");
|
|
680
|
+
}
|
|
681
|
+
else {
|
|
682
|
+
callbacks.onError(terminalError, "terminal");
|
|
683
|
+
}
|
|
684
|
+
/* v8 ignore stop */
|
|
685
|
+
const errorDetails = (0, error_classification_1.extractProviderErrorDetails)(terminalError);
|
|
686
|
+
(0, runtime_1.emitNervesEvent)({
|
|
687
|
+
level: "error",
|
|
688
|
+
event: "engine.error",
|
|
689
|
+
trace_id: traceId,
|
|
690
|
+
component: "engine",
|
|
691
|
+
message: terminalError.message,
|
|
692
|
+
meta: {
|
|
693
|
+
provider: providerRuntime.id,
|
|
694
|
+
model: providerRuntime.model,
|
|
695
|
+
errorClassification: terminalErrorClassification,
|
|
696
|
+
...(errorDetails.status !== undefined ? { httpStatus: errorDetails.status } : {}),
|
|
697
|
+
...(errorDetails.bodyExcerpt ? { bodyExcerpt: errorDetails.bodyExcerpt } : {}),
|
|
698
|
+
summary: (0, error_classification_1.summarizeProviderError)(terminalError, terminalErrorClassification, providerRuntime.id, providerRuntime.model),
|
|
699
|
+
},
|
|
700
|
+
});
|
|
701
|
+
stripLastToolCalls(messages);
|
|
702
|
+
outcome = "errored";
|
|
703
|
+
done = true;
|
|
704
|
+
};
|
|
397
705
|
// Prevent MaxListenersExceeded warning — each iteration adds a listener
|
|
398
706
|
try {
|
|
399
707
|
require("events").setMaxListeners(50, signal);
|
|
400
708
|
}
|
|
401
709
|
catch { /* unsupported */ }
|
|
402
710
|
const toolPreferences = currentContext?.friend?.toolPreferences;
|
|
403
|
-
const baseTools = options?.tools ?? (0, tools_1.getToolsForChannel)(channel ? (0, channel_1.getChannelCapabilities)(channel) : undefined, toolPreferences && Object.keys(toolPreferences).length > 0 ? toolPreferences : undefined, currentContext, providerRuntime.capabilities);
|
|
711
|
+
const baseTools = options?.tools ?? (0, tools_1.getToolsForChannel)(channel ? (0, channel_1.getChannelCapabilities)(channel) : undefined, toolPreferences && Object.keys(toolPreferences).length > 0 ? toolPreferences : undefined, currentContext, providerRuntime.capabilities, options?.mcpManager, providerRuntime.model);
|
|
404
712
|
// Augment tool context with reasoning effort controls from provider
|
|
405
|
-
const
|
|
713
|
+
const baseToolContext = options?.toolContext
|
|
714
|
+
?? (options?.orientationFrame ? { signin: async () => undefined, orientationFrame: options.orientationFrame } : undefined);
|
|
715
|
+
const augmentedToolContext = baseToolContext
|
|
406
716
|
? {
|
|
407
|
-
...
|
|
717
|
+
...baseToolContext,
|
|
408
718
|
supportedReasoningEfforts: providerRuntime.supportedReasoningEfforts,
|
|
409
719
|
setReasoningEffort: (level) => { currentReasoningEffort = level; },
|
|
720
|
+
activeWorkFrame: options?.activeWorkFrame,
|
|
721
|
+
orientationFrame: options?.orientationFrame ?? baseToolContext.orientationFrame,
|
|
410
722
|
}
|
|
411
723
|
: undefined;
|
|
412
724
|
// Rebase provider-owned turn state from canonical messages at user-turn start.
|
|
413
725
|
// This prevents stale provider caches from replaying prior-turn context.
|
|
414
726
|
providerRuntime.resetTurnState(messages);
|
|
415
727
|
while (!done) {
|
|
416
|
-
//
|
|
417
|
-
//
|
|
418
|
-
//
|
|
419
|
-
//
|
|
420
|
-
|
|
728
|
+
// Channel-based tool filtering:
|
|
729
|
+
// - Inner dialog: exclude send_message (delivery via surface), observe (no one to observe)
|
|
730
|
+
// - All outward channels (1:1, group, reaction): observe available
|
|
731
|
+
//
|
|
732
|
+
// ponder, settle/rest, surface, and observe are always assembled based on channel context.
|
|
733
|
+
// ponder is available in ALL channels (outer: think privately, inner: keep turning).
|
|
734
|
+
// Inner dialog gets restTool instead of settleTool (rest = end turn, gated by attention queue).
|
|
735
|
+
// toolChoiceRequired only controls whether tool_choice: "required" is set in the API call.
|
|
736
|
+
const isInnerDialog = channel === "inner";
|
|
737
|
+
const filteredBaseTools = isInnerDialog
|
|
738
|
+
? baseTools.filter((t) => t.function.name !== "send_message")
|
|
739
|
+
: baseTools;
|
|
740
|
+
const activeTools = [
|
|
741
|
+
...filteredBaseTools,
|
|
742
|
+
tools_1.ponderTool,
|
|
743
|
+
...(isInnerDialog ? [tools_2.surfaceToolDef, tools_1.restTool] : []),
|
|
744
|
+
...(!isInnerDialog ? [tools_1.observeTool] : []),
|
|
745
|
+
...(!isInnerDialog ? [tools_1.settleTool] : []),
|
|
746
|
+
...(isChatStyleChannel(channel ?? "") ? [tools_1.speakTool] : []),
|
|
747
|
+
];
|
|
421
748
|
const steeringFollowUps = options?.drainSteeringFollowUps?.() ?? [];
|
|
422
749
|
if (steeringFollowUps.length > 0) {
|
|
423
750
|
const hasSupersedingFollowUp = steeringFollowUps.some((followUp) => followUp.effect === "clear_and_supersede");
|
|
@@ -444,26 +771,124 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
444
771
|
break;
|
|
445
772
|
}
|
|
446
773
|
try {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
774
|
+
const callProviderTurn = async () => {
|
|
775
|
+
callbacks.onModelStart();
|
|
776
|
+
try {
|
|
777
|
+
return await providerRuntime.streamTurn({
|
|
778
|
+
messages,
|
|
779
|
+
activeTools,
|
|
780
|
+
callbacks,
|
|
781
|
+
signal,
|
|
782
|
+
traceId,
|
|
783
|
+
toolChoiceRequired,
|
|
784
|
+
reasoningEffort: currentReasoningEffort,
|
|
785
|
+
eagerSettleStreaming: true,
|
|
786
|
+
systemPrompt: structuredSystemPrompt,
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
catch (error) {
|
|
790
|
+
if (signal?.aborted)
|
|
791
|
+
throw new provider_attempt_1.ProviderAttemptAbortError();
|
|
792
|
+
throw error;
|
|
793
|
+
}
|
|
794
|
+
};
|
|
795
|
+
const callProviderTurnWithOverflowRecovery = async () => {
|
|
796
|
+
try {
|
|
797
|
+
return await callProviderTurn();
|
|
798
|
+
}
|
|
799
|
+
catch (error) {
|
|
800
|
+
if (error instanceof provider_attempt_1.ProviderAttemptAbortError)
|
|
801
|
+
throw error;
|
|
802
|
+
if (isContextOverflow(error) && !overflowRetried) {
|
|
803
|
+
overflowRetried = true;
|
|
804
|
+
stripLastToolCalls(messages);
|
|
805
|
+
const { maxTokens, contextMargin } = (0, config_1.getContextConfig)();
|
|
806
|
+
const trimmed = (0, context_1.trimMessages)(messages, maxTokens, contextMargin, maxTokens * 2);
|
|
807
|
+
messages.splice(0, messages.length, ...trimmed);
|
|
808
|
+
providerRuntime.resetTurnState(messages);
|
|
809
|
+
callbacks.onError(new Error("context trimmed, retrying..."), "transient");
|
|
810
|
+
return callProviderTurn();
|
|
811
|
+
}
|
|
812
|
+
throw error;
|
|
813
|
+
}
|
|
814
|
+
};
|
|
815
|
+
const attempt = await (0, provider_attempt_1.runProviderAttempt)({
|
|
816
|
+
operation: "turn",
|
|
817
|
+
provider: providerRuntime.id,
|
|
818
|
+
model: providerRuntime.model,
|
|
819
|
+
run: callProviderTurnWithOverflowRecovery,
|
|
820
|
+
classifyError: (error) => providerRuntime.classifyError(error),
|
|
821
|
+
onRetry: async (record, maxAttempts) => {
|
|
822
|
+
const delayMs = record.delayMs;
|
|
823
|
+
const seconds = delayMs / 1000;
|
|
824
|
+
const cause = RETRY_LABELS[record.classification];
|
|
825
|
+
try {
|
|
826
|
+
await (0, provider_credentials_1.refreshProviderCredentialPool)((0, identity_2.getAgentName)(), {
|
|
827
|
+
preserveCachedOnFailure: true,
|
|
828
|
+
providers: [record.provider],
|
|
829
|
+
});
|
|
830
|
+
_providerRuntimes[facing] = null;
|
|
831
|
+
providerRuntime = await getProviderRuntime(facing);
|
|
832
|
+
providerRuntime.resetTurnState(messages);
|
|
833
|
+
}
|
|
834
|
+
catch (refreshError) {
|
|
835
|
+
(0, runtime_1.emitNervesEvent)({
|
|
836
|
+
level: "warn",
|
|
837
|
+
component: "engine",
|
|
838
|
+
event: "engine.provider_retry_refresh_failed",
|
|
839
|
+
message: "provider credential refresh failed during retry",
|
|
840
|
+
meta: { provider: record.provider, model: record.model, reason: refreshError instanceof Error ? refreshError.message : String(refreshError) },
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
callbacks.onError(new Error(`${cause}, retrying in ${seconds}s (${record.attempt}/${maxAttempts})...`), "transient");
|
|
844
|
+
},
|
|
845
|
+
sleep: async (delayMs) => {
|
|
846
|
+
await waitForProviderRetry(delayMs, signal);
|
|
847
|
+
providerRuntime.resetTurnState(messages);
|
|
848
|
+
},
|
|
456
849
|
});
|
|
850
|
+
if (!attempt.ok) {
|
|
851
|
+
finishTerminalProviderError(attempt.error, attempt.classification);
|
|
852
|
+
continue;
|
|
853
|
+
}
|
|
854
|
+
const result = attempt.value;
|
|
457
855
|
// Track usage from the latest API call
|
|
458
856
|
if (result.usage)
|
|
459
857
|
lastUsage = result.usage;
|
|
460
|
-
retryCount = 0; // reset on success
|
|
461
858
|
// SHARED: build CC-format assistant message from TurnResult
|
|
462
859
|
const msg = {
|
|
463
860
|
role: "assistant",
|
|
464
861
|
};
|
|
465
|
-
|
|
466
|
-
|
|
862
|
+
// Persist assistant content WITHOUT inline <think>...</think> blocks.
|
|
863
|
+
// Reasoning content already routed through onReasoningChunk for live
|
|
864
|
+
// surfacing and persisted separately as `_reasoning_items` for
|
|
865
|
+
// providers that support a reasoning channel; saving it inline AND
|
|
866
|
+
// alongside tool_calls causes MiniMax to reject the replayed turn
|
|
867
|
+
// with "tool result's tool id not found" (error code 2013) because
|
|
868
|
+
// it can't reconcile reasoning-with-tools in the same assistant
|
|
869
|
+
// message. Strip aggressively at persist so the next replay is
|
|
870
|
+
// clean; preserve the original reasoning trace on the message via
|
|
871
|
+
// `_inline_reasoning` so debug/audit paths can still see it.
|
|
872
|
+
if (result.content) {
|
|
873
|
+
const stripped = stripThinkBlocksForViolationCheck(result.content);
|
|
874
|
+
if (stripped.length > 0)
|
|
875
|
+
msg.content = stripped;
|
|
876
|
+
if (stripped.length !== result.content.length) {
|
|
877
|
+
msg._inline_reasoning = result.content;
|
|
878
|
+
(0, runtime_1.emitNervesEvent)({
|
|
879
|
+
level: "info",
|
|
880
|
+
component: "engine",
|
|
881
|
+
event: "engine.inline_reasoning_stripped",
|
|
882
|
+
message: "stripped inline <think> blocks from persisted assistant message; preserved on _inline_reasoning",
|
|
883
|
+
meta: {
|
|
884
|
+
provider: providerRuntime.id,
|
|
885
|
+
model: providerRuntime.model,
|
|
886
|
+
originalLength: result.content.length,
|
|
887
|
+
strippedLength: stripped.length,
|
|
888
|
+
},
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
}
|
|
467
892
|
if (result.toolCalls.length)
|
|
468
893
|
msg.tool_calls = result.toolCalls.map((tc) => ({
|
|
469
894
|
id: tc.id,
|
|
@@ -483,35 +908,109 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
483
908
|
}
|
|
484
909
|
// Phase annotation for Codex provider
|
|
485
910
|
const hasPhaseAnnotation = providerRuntime.capabilities.has("phase-annotation");
|
|
486
|
-
const
|
|
911
|
+
const isSoleSettle = result.toolCalls.length === 1 && result.toolCalls[0].name === "settle";
|
|
487
912
|
if (hasPhaseAnnotation) {
|
|
488
|
-
msg.phase =
|
|
913
|
+
msg.phase = isSoleSettle ? "settle" : "commentary";
|
|
489
914
|
}
|
|
915
|
+
// Detect the MiniMax "only-thinking, no tool call" violation: no tool
|
|
916
|
+
// calls returned, and the content is empty after stripping
|
|
917
|
+
// <think>...</think> blocks. This is a narrow check — legitimate
|
|
918
|
+
// content-only responses (text without think tags, or text outside
|
|
919
|
+
// think tags) still flow through the original "no tool calls →
|
|
920
|
+
// accept as-is" path so existing channels and tests are unaffected.
|
|
921
|
+
const onlyThinkContent = !result.toolCalls.length
|
|
922
|
+
&& typeof result.content === "string"
|
|
923
|
+
&& stripThinkBlocksForViolationCheck(result.content).length === 0
|
|
924
|
+
&& result.content.length > 0;
|
|
490
925
|
if (!result.toolCalls.length) {
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
926
|
+
if (onlyThinkContent && toolChoiceRequired && noToolCallRetries < NO_TOOL_CALL_MAX_RETRIES) {
|
|
927
|
+
// Provider-level violation: tool_choice was required, model emitted
|
|
928
|
+
// only a <think>...</think> block (or empty content) with no tool
|
|
929
|
+
// call. Retry with a corrective nudge up to NO_TOOL_CALL_MAX_RETRIES
|
|
930
|
+
// times. After cap, accept as-is (the readback path strips think
|
|
931
|
+
// tags and surfaces a clear diagnostic).
|
|
932
|
+
noToolCallRetries++;
|
|
933
|
+
(0, runtime_1.emitNervesEvent)({
|
|
934
|
+
level: "warn",
|
|
935
|
+
component: "engine",
|
|
936
|
+
event: "engine.no_tool_call_retry",
|
|
937
|
+
message: "model returned only <think> content with no tool call despite tool_choice=required; retrying with corrective nudge",
|
|
938
|
+
meta: {
|
|
939
|
+
attempt: noToolCallRetries,
|
|
940
|
+
cap: NO_TOOL_CALL_MAX_RETRIES,
|
|
941
|
+
provider: providerRuntime.id,
|
|
942
|
+
model: providerRuntime.model,
|
|
943
|
+
contentLength: result.content.length,
|
|
944
|
+
},
|
|
945
|
+
});
|
|
946
|
+
messages.push(msg);
|
|
947
|
+
messages.push({
|
|
948
|
+
role: "user",
|
|
949
|
+
content: isInnerDialog
|
|
950
|
+
? "no tool was called this turn. you must end every turn by calling rest (or surface, ponder, observe). emit the tool call now."
|
|
951
|
+
: "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.",
|
|
952
|
+
});
|
|
953
|
+
continue;
|
|
954
|
+
}
|
|
955
|
+
// Legitimate text-only response, or cap reached — accept as-is.
|
|
494
956
|
messages.push(msg);
|
|
495
957
|
done = true;
|
|
496
958
|
}
|
|
497
959
|
else {
|
|
498
|
-
//
|
|
499
|
-
|
|
960
|
+
// Reset the retry counter on any successful tool call.
|
|
961
|
+
noToolCallRetries = 0;
|
|
962
|
+
// Check for settle sole call: intercept before tool execution
|
|
963
|
+
if (isSoleSettle) {
|
|
964
|
+
/* v8 ignore next -- defensive: JSON.parse catch for malformed settle args @preserve */
|
|
965
|
+
const settleArgs = (() => { try {
|
|
966
|
+
return JSON.parse(result.toolCalls[0].arguments);
|
|
967
|
+
}
|
|
968
|
+
catch {
|
|
969
|
+
return {};
|
|
970
|
+
} })();
|
|
971
|
+
callbacks.onToolStart("settle", settleArgs);
|
|
972
|
+
// Inner dialog attention queue gate: reject settle if items remain
|
|
973
|
+
const attentionQueue = (augmentedToolContext ?? options?.toolContext)?.delegatedOrigins;
|
|
974
|
+
if (isInnerDialog && attentionQueue && attentionQueue.length > 0) {
|
|
975
|
+
callbacks.onToolEnd("settle", (0, tools_1.summarizeArgs)("settle", settleArgs), false);
|
|
976
|
+
callbacks.onClearText?.();
|
|
977
|
+
messages.push(msg);
|
|
978
|
+
const gateMessage = "current held-work frame still has unsurfaced items — return each listed item with surface(delegationId=...) before you settle. Older transcript claims are historical; only the current held-work frame is the gate.";
|
|
979
|
+
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: gateMessage });
|
|
980
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, gateMessage);
|
|
981
|
+
continue;
|
|
982
|
+
}
|
|
500
983
|
// Extract answer from the tool call arguments.
|
|
501
984
|
// Supports: {"answer":"text","intent":"..."} or "text" (JSON string).
|
|
502
|
-
const { answer, intent } =
|
|
985
|
+
const { answer, intent } = parseSettlePayload(result.toolCalls[0].arguments);
|
|
986
|
+
// Inner dialog settle: no CompletionMetadata, "(settled)" ack
|
|
987
|
+
if (isInnerDialog) {
|
|
988
|
+
callbacks.onToolEnd("settle", (0, tools_1.summarizeArgs)("settle", settleArgs), true);
|
|
989
|
+
messages.push(msg);
|
|
990
|
+
const settled = "(settled)";
|
|
991
|
+
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: settled });
|
|
992
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, settled);
|
|
993
|
+
outcome = "settled";
|
|
994
|
+
done = true;
|
|
995
|
+
continue;
|
|
996
|
+
}
|
|
997
|
+
const deliveredAnswer = answer;
|
|
998
|
+
const retryError = privateReturnAckLeakError(deliveredAnswer, privateReturnHeldTokens)
|
|
999
|
+
?? getSettleRetryError(mustResolveBeforeHandoffActive, intent, sawSteeringFollowUp, options?.delegationDecision, sawSendMessageSelf, sawPonder, sawQuerySession, options?.currentObligation ?? null, options?.activeWorkFrame?.inner?.job, sawExternalStateQuery);
|
|
503
1000
|
const validDirectReply = mustResolveBeforeHandoffActive && intent === "direct_reply" && sawSteeringFollowUp;
|
|
504
1001
|
const validTerminalIntent = intent === "complete" || intent === "blocked";
|
|
505
|
-
const validClosure =
|
|
1002
|
+
const validClosure = deliveredAnswer != null
|
|
1003
|
+
&& !retryError
|
|
506
1004
|
&& (!mustResolveBeforeHandoffActive || validDirectReply || validTerminalIntent);
|
|
507
1005
|
if (validClosure) {
|
|
1006
|
+
callbacks.onToolEnd("settle", (0, tools_1.summarizeArgs)("settle", settleArgs), true);
|
|
508
1007
|
completion = {
|
|
509
|
-
answer,
|
|
1008
|
+
answer: deliveredAnswer,
|
|
510
1009
|
intent: validDirectReply ? "direct_reply" : intent === "blocked" ? "blocked" : "complete",
|
|
511
1010
|
};
|
|
512
|
-
if (result.
|
|
1011
|
+
if (result.settleStreamed) {
|
|
513
1012
|
// The streaming layer already parsed and emitted the answer
|
|
514
|
-
// progressively via
|
|
1013
|
+
// progressively via SettleParser. Skip clearing and
|
|
515
1014
|
// re-emitting to avoid double-delivery.
|
|
516
1015
|
}
|
|
517
1016
|
else {
|
|
@@ -519,7 +1018,7 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
519
1018
|
callbacks.onClearText?.();
|
|
520
1019
|
// Emit the answer through the callback pipeline so channels receive it.
|
|
521
1020
|
// Never truncate -- channel adapters handle splitting long messages.
|
|
522
|
-
callbacks.onTextChunk(
|
|
1021
|
+
callbacks.onTextChunk(deliveredAnswer);
|
|
523
1022
|
}
|
|
524
1023
|
messages.push(msg);
|
|
525
1024
|
if (validDirectReply) {
|
|
@@ -531,32 +1030,114 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
531
1030
|
const delivered = "(delivered)";
|
|
532
1031
|
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: delivered });
|
|
533
1032
|
providerRuntime.appendToolOutput(result.toolCalls[0].id, delivered);
|
|
534
|
-
outcome = intent === "blocked" ? "blocked" : "
|
|
1033
|
+
outcome = intent === "blocked" ? "blocked" : "settled";
|
|
535
1034
|
done = true;
|
|
536
1035
|
}
|
|
537
1036
|
}
|
|
538
1037
|
else {
|
|
539
|
-
// Answer is undefined -- the model's
|
|
1038
|
+
// Answer is undefined -- the model's settle was incomplete or
|
|
540
1039
|
// malformed. Clear any partial streamed text or noise, then push the
|
|
541
1040
|
// assistant msg + error tool result and let the model try again.
|
|
1041
|
+
callbacks.onToolEnd("settle", (0, tools_1.summarizeArgs)("settle", settleArgs), false);
|
|
542
1042
|
callbacks.onClearText?.();
|
|
543
|
-
const retryError = getFinalAnswerRetryError(mustResolveBeforeHandoffActive, intent, sawSteeringFollowUp);
|
|
544
1043
|
messages.push(msg);
|
|
545
|
-
|
|
546
|
-
|
|
1044
|
+
const toolRetryMessage = retryError
|
|
1045
|
+
?? "your settle was incomplete or malformed. call settle again with your complete response.";
|
|
1046
|
+
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: toolRetryMessage });
|
|
1047
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, toolRetryMessage);
|
|
1048
|
+
}
|
|
1049
|
+
continue;
|
|
1050
|
+
}
|
|
1051
|
+
// Check for observe sole call: intercept before tool execution
|
|
1052
|
+
const isSoleObserve = result.toolCalls.length === 1 && result.toolCalls[0].name === "observe";
|
|
1053
|
+
if (isSoleObserve) {
|
|
1054
|
+
/* v8 ignore next -- defensive: JSON.parse catch for malformed observe args @preserve */
|
|
1055
|
+
const observeArgs = (() => { try {
|
|
1056
|
+
return JSON.parse(result.toolCalls[0].arguments);
|
|
547
1057
|
}
|
|
1058
|
+
catch {
|
|
1059
|
+
return {};
|
|
1060
|
+
} })();
|
|
1061
|
+
let reason;
|
|
1062
|
+
if (typeof observeArgs?.reason === "string")
|
|
1063
|
+
reason = observeArgs.reason;
|
|
1064
|
+
callbacks.onToolStart("observe", observeArgs);
|
|
1065
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1066
|
+
component: "engine",
|
|
1067
|
+
event: "engine.observe",
|
|
1068
|
+
message: "agent observed without responding",
|
|
1069
|
+
meta: { ...(reason ? { reason } : {}) },
|
|
1070
|
+
});
|
|
1071
|
+
callbacks.onToolEnd("observe", (0, tools_1.summarizeArgs)("observe", observeArgs), true);
|
|
1072
|
+
messages.push(msg);
|
|
1073
|
+
const silenced = "(silenced)";
|
|
1074
|
+
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: silenced });
|
|
1075
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, silenced);
|
|
1076
|
+
outcome = "observed";
|
|
1077
|
+
done = true;
|
|
1078
|
+
continue;
|
|
1079
|
+
}
|
|
1080
|
+
// Check for rest sole call: intercept before tool execution
|
|
1081
|
+
const isSoleRest = result.toolCalls.length === 1 && result.toolCalls[0].name === "rest";
|
|
1082
|
+
if (isSoleRest) {
|
|
1083
|
+
const restArgs = (() => { try {
|
|
1084
|
+
return JSON.parse(result.toolCalls[0].arguments);
|
|
1085
|
+
}
|
|
1086
|
+
catch {
|
|
1087
|
+
return {};
|
|
1088
|
+
} })();
|
|
1089
|
+
callbacks.onToolStart("rest", restArgs);
|
|
1090
|
+
// Attention queue gate: reject rest if items remain
|
|
1091
|
+
const attentionQueue = (augmentedToolContext ?? options?.toolContext)?.delegatedOrigins;
|
|
1092
|
+
if (attentionQueue && attentionQueue.length > 0) {
|
|
1093
|
+
callbacks.onToolEnd("rest", (0, tools_1.summarizeArgs)("rest", restArgs), false);
|
|
1094
|
+
messages.push(msg);
|
|
1095
|
+
const gateMessage = "current held-work frame still has unsurfaced items — return each listed item with surface(delegationId=...) before you rest. Older transcript claims are historical; only the current held-work frame is the gate.";
|
|
1096
|
+
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: gateMessage });
|
|
1097
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, gateMessage);
|
|
1098
|
+
continue;
|
|
1099
|
+
}
|
|
1100
|
+
if (hasFreshPendingWork(options) && !freshWorkGateFired) {
|
|
1101
|
+
freshWorkGateFired = true;
|
|
1102
|
+
callbacks.onToolEnd("rest", (0, tools_1.summarizeArgs)("rest", restArgs), false);
|
|
1103
|
+
messages.push(msg);
|
|
1104
|
+
const gateMessage = "fresh work arrived for me this turn — inspect the pending messages above and take the next concrete action before you rest.";
|
|
1105
|
+
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: gateMessage });
|
|
1106
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, gateMessage);
|
|
1107
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1108
|
+
level: "info",
|
|
1109
|
+
component: "engine",
|
|
1110
|
+
event: "engine.fresh_work_gate_fired",
|
|
1111
|
+
message: "rest deferred once because pending work arrived this turn; agent has been notified",
|
|
1112
|
+
meta: { pendingCount: options.pendingMessages.length },
|
|
1113
|
+
});
|
|
1114
|
+
continue;
|
|
1115
|
+
}
|
|
1116
|
+
callbacks.onToolEnd("rest", (0, tools_1.summarizeArgs)("rest", restArgs), true);
|
|
1117
|
+
messages.push(msg);
|
|
1118
|
+
const ack = "(resting)";
|
|
1119
|
+
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: ack });
|
|
1120
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, ack);
|
|
1121
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1122
|
+
component: "engine",
|
|
1123
|
+
event: "engine.rested",
|
|
1124
|
+
message: "resting until next heartbeat",
|
|
1125
|
+
meta: { ...(typeof restArgs?.status === "string" ? { status: restArgs.status } : {}) },
|
|
1126
|
+
});
|
|
1127
|
+
outcome = "rested";
|
|
1128
|
+
done = true;
|
|
548
1129
|
continue;
|
|
549
1130
|
}
|
|
550
1131
|
messages.push(msg);
|
|
551
|
-
//
|
|
1132
|
+
// Execute tools (sole-call tools in mixed calls are rejected inline)
|
|
552
1133
|
for (const tc of result.toolCalls) {
|
|
553
1134
|
if (signal?.aborted)
|
|
554
1135
|
break;
|
|
555
|
-
//
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
messages.push({ role: "tool", tool_call_id: tc.id, content:
|
|
559
|
-
providerRuntime.appendToolOutput(tc.id,
|
|
1136
|
+
// Reject sole-call tools when mixed with other tool calls
|
|
1137
|
+
const soleCallRejection = SOLE_CALL_REJECTION[tc.name];
|
|
1138
|
+
if (soleCallRejection) {
|
|
1139
|
+
messages.push({ role: "tool", tool_call_id: tc.id, content: soleCallRejection });
|
|
1140
|
+
providerRuntime.appendToolOutput(tc.id, soleCallRejection);
|
|
560
1141
|
continue;
|
|
561
1142
|
}
|
|
562
1143
|
let args = {};
|
|
@@ -566,21 +1147,252 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
566
1147
|
catch {
|
|
567
1148
|
/* ignore */
|
|
568
1149
|
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
decision = await callbacks.onConfirmAction(tc.name, args);
|
|
575
|
-
}
|
|
576
|
-
if (decision !== "confirmed") {
|
|
577
|
-
const cancelled = "Action cancelled by user.";
|
|
1150
|
+
if (tc.name === "send_message" && args.friendId === "self") {
|
|
1151
|
+
const latestUserText = latestUserMessageText(messages);
|
|
1152
|
+
if (!isInnerDialog && looksLikePrivateReturnRequest(latestUserText)) {
|
|
1153
|
+
const argSummary = (0, tools_1.summarizeArgs)(tc.name, args);
|
|
1154
|
+
const rejection = "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.";
|
|
578
1155
|
callbacks.onToolStart(tc.name, args);
|
|
579
1156
|
callbacks.onToolEnd(tc.name, argSummary, false);
|
|
580
|
-
messages.push({ role: "tool", tool_call_id: tc.id, content:
|
|
581
|
-
providerRuntime.appendToolOutput(tc.id,
|
|
1157
|
+
messages.push({ role: "tool", tool_call_id: tc.id, content: rejection });
|
|
1158
|
+
providerRuntime.appendToolOutput(tc.id, rejection);
|
|
1159
|
+
continue;
|
|
1160
|
+
}
|
|
1161
|
+
sawSendMessageSelf = true;
|
|
1162
|
+
}
|
|
1163
|
+
if (tc.name === "speak") {
|
|
1164
|
+
let speakArgs = {};
|
|
1165
|
+
try {
|
|
1166
|
+
speakArgs = JSON.parse(tc.arguments);
|
|
1167
|
+
}
|
|
1168
|
+
catch { /* malformed */ }
|
|
1169
|
+
const speakMessage = typeof speakArgs.message === "string" ? speakArgs.message : "";
|
|
1170
|
+
const argSummary = (0, tools_1.summarizeArgs)("speak", { message: speakMessage });
|
|
1171
|
+
callbacks.onToolStart("speak", { message: speakMessage });
|
|
1172
|
+
if (speakMessage.trim().length === 0) {
|
|
1173
|
+
const err = "speak requires a non-empty `message` string.";
|
|
1174
|
+
callbacks.onToolEnd("speak", argSummary, false);
|
|
1175
|
+
messages.push({ role: "tool", tool_call_id: tc.id, content: err });
|
|
1176
|
+
providerRuntime.appendToolOutput(tc.id, err);
|
|
1177
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1178
|
+
level: "warn",
|
|
1179
|
+
component: "engine",
|
|
1180
|
+
event: "engine.speak_invalid",
|
|
1181
|
+
message: "speak rejected: missing or empty message",
|
|
1182
|
+
meta: {},
|
|
1183
|
+
});
|
|
582
1184
|
continue;
|
|
583
1185
|
}
|
|
1186
|
+
callbacks.onTextChunk(speakMessage);
|
|
1187
|
+
let speakDeliveryError = null;
|
|
1188
|
+
try {
|
|
1189
|
+
await callbacks.flushNow?.();
|
|
1190
|
+
}
|
|
1191
|
+
catch (err) {
|
|
1192
|
+
speakDeliveryError = err instanceof Error ? err : new Error(String(err));
|
|
1193
|
+
}
|
|
1194
|
+
if (speakDeliveryError) {
|
|
1195
|
+
callbacks.onToolEnd("speak", argSummary, false);
|
|
1196
|
+
const failMsg = `speak delivery failed: ${speakDeliveryError.message}. the message did not reach your friend; do not assume they saw it.`;
|
|
1197
|
+
messages.push({ role: "tool", tool_call_id: tc.id, content: failMsg });
|
|
1198
|
+
providerRuntime.appendToolOutput(tc.id, failMsg);
|
|
1199
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1200
|
+
level: "error",
|
|
1201
|
+
component: "engine",
|
|
1202
|
+
event: "engine.speak_delivery_failed",
|
|
1203
|
+
message: "speak delivery failed",
|
|
1204
|
+
meta: { error: speakDeliveryError.message, messageLength: speakMessage.length },
|
|
1205
|
+
});
|
|
1206
|
+
continue;
|
|
1207
|
+
}
|
|
1208
|
+
callbacks.onToolEnd("speak", argSummary, true);
|
|
1209
|
+
const ack = "(spoken)";
|
|
1210
|
+
messages.push({ role: "tool", tool_call_id: tc.id, content: ack });
|
|
1211
|
+
providerRuntime.appendToolOutput(tc.id, ack);
|
|
1212
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1213
|
+
component: "engine",
|
|
1214
|
+
event: "engine.speak",
|
|
1215
|
+
message: "agent spoke mid-turn",
|
|
1216
|
+
meta: { messageLength: speakMessage.length },
|
|
1217
|
+
});
|
|
1218
|
+
continue;
|
|
1219
|
+
}
|
|
1220
|
+
if (tc.name === "ponder") {
|
|
1221
|
+
const parsedArgs = normalizeLegacyPonderArgs(parsePonderPayload(tc.arguments));
|
|
1222
|
+
const argSummary = (0, tools_1.summarizeArgs)(tc.name, parsedArgs);
|
|
1223
|
+
callbacks.onToolStart(tc.name, parsedArgs);
|
|
1224
|
+
let toolResult;
|
|
1225
|
+
let success = false;
|
|
1226
|
+
try {
|
|
1227
|
+
const action = parsedArgs.action ?? "create";
|
|
1228
|
+
const currentSession = (augmentedToolContext ?? options?.toolContext)?.currentSession;
|
|
1229
|
+
const currentOrigin = currentSession
|
|
1230
|
+
? { friendId: currentSession.friendId, channel: currentSession.channel, key: currentSession.key }
|
|
1231
|
+
: undefined;
|
|
1232
|
+
const isInnerChannel = currentOrigin?.friendId === "self" && currentOrigin?.channel === "inner";
|
|
1233
|
+
const shouldCreateReturnObligation = !!currentOrigin && !isInnerChannel;
|
|
1234
|
+
const attentionQueue = (augmentedToolContext ?? options?.toolContext)?.delegatedOrigins ?? [];
|
|
1235
|
+
const successCriteria = parseSuccessCriteria(parsedArgs.success_criteria);
|
|
1236
|
+
const payload = parsePacketPayload(parsedArgs.payload_json);
|
|
1237
|
+
let packet;
|
|
1238
|
+
let returnObligationId = null;
|
|
1239
|
+
let resultAction = "created";
|
|
1240
|
+
let privateReturnSourceRequest = "";
|
|
1241
|
+
if (action === "create") {
|
|
1242
|
+
if (isInnerChannel && attentionQueue.length > 0) {
|
|
1243
|
+
throw new Error("inner dialog already has held return work in the attention queue; surface the existing delegationId instead of creating a replacement ponder packet.");
|
|
1244
|
+
}
|
|
1245
|
+
const kind = parsedArgs.kind;
|
|
1246
|
+
const objective = typeof parsedArgs.objective === "string" ? parsedArgs.objective.trim() : "";
|
|
1247
|
+
const summary = typeof parsedArgs.summary === "string" ? parsedArgs.summary.trim() : "";
|
|
1248
|
+
const sourceRequest = currentOrigin && !isInnerChannel ? latestUserMessageText(messages) : "";
|
|
1249
|
+
privateReturnSourceRequest = sourceRequest;
|
|
1250
|
+
if (!kind || !objective || !successCriteria || !payload) {
|
|
1251
|
+
throw new Error("ponder create requires kind, objective, success_criteria, and valid payload_json.");
|
|
1252
|
+
}
|
|
1253
|
+
const packetPayload = sourceRequest && typeof payload.sourceRequest !== "string"
|
|
1254
|
+
? { ...payload, sourceRequest }
|
|
1255
|
+
: payload;
|
|
1256
|
+
const createLinkedReturnObligation = (id, packetId) => {
|
|
1257
|
+
(0, obligations_1.createReturnObligation)((0, identity_2.getAgentName)(), {
|
|
1258
|
+
id,
|
|
1259
|
+
origin: currentOrigin,
|
|
1260
|
+
status: "queued",
|
|
1261
|
+
delegatedContent: buildPonderDelegatedContent({ summary, objective, sourceRequest }),
|
|
1262
|
+
packetId,
|
|
1263
|
+
createdAt: Date.now(),
|
|
1264
|
+
});
|
|
1265
|
+
};
|
|
1266
|
+
const agentRoot = (0, identity_2.getAgentRoot)();
|
|
1267
|
+
let relatedObligationId;
|
|
1268
|
+
if (currentOrigin && !isInnerChannel) {
|
|
1269
|
+
try {
|
|
1270
|
+
const obligation = (0, obligations_1.createObligation)(agentRoot, {
|
|
1271
|
+
origin: currentOrigin,
|
|
1272
|
+
content: objective,
|
|
1273
|
+
});
|
|
1274
|
+
relatedObligationId = obligation.id;
|
|
1275
|
+
}
|
|
1276
|
+
catch {
|
|
1277
|
+
relatedObligationId = undefined;
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
const frictionSignature = kind === "harness_friction" && typeof packetPayload.frictionSignature === "string"
|
|
1281
|
+
? packetPayload.frictionSignature
|
|
1282
|
+
: null;
|
|
1283
|
+
const existing = frictionSignature && currentOrigin
|
|
1284
|
+
? (0, packets_1.findHarnessFrictionPacket)(agentRoot, currentOrigin, frictionSignature)
|
|
1285
|
+
: null;
|
|
1286
|
+
if (existing) {
|
|
1287
|
+
resultAction = "revised";
|
|
1288
|
+
const existingActiveReturnId = shouldCreateReturnObligation
|
|
1289
|
+
? activeReturnObligationId((0, identity_2.getAgentName)(), existing.relatedReturnObligationId)
|
|
1290
|
+
: null;
|
|
1291
|
+
returnObligationId = existingActiveReturnId
|
|
1292
|
+
?? (shouldCreateReturnObligation ? (0, obligations_1.generateObligationId)(Date.now()) : null);
|
|
1293
|
+
packet = existing.status === "drafting"
|
|
1294
|
+
? (0, packets_1.revisePonderPacket)(agentRoot, existing.id, {
|
|
1295
|
+
kind,
|
|
1296
|
+
objective,
|
|
1297
|
+
summary,
|
|
1298
|
+
successCriteria,
|
|
1299
|
+
payload: packetPayload,
|
|
1300
|
+
})
|
|
1301
|
+
: existing;
|
|
1302
|
+
if (returnObligationId && returnObligationId !== existing.relatedReturnObligationId) {
|
|
1303
|
+
packet = (0, packets_1.advancePonderPacket)(agentRoot, packet.id, { relatedReturnObligationId: returnObligationId });
|
|
1304
|
+
createLinkedReturnObligation(returnObligationId, packet.id);
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
else {
|
|
1308
|
+
returnObligationId = shouldCreateReturnObligation ? (0, obligations_1.generateObligationId)(Date.now()) : null;
|
|
1309
|
+
packet = (0, packets_1.createPonderPacket)(agentRoot, {
|
|
1310
|
+
kind,
|
|
1311
|
+
objective,
|
|
1312
|
+
summary,
|
|
1313
|
+
successCriteria,
|
|
1314
|
+
...(currentOrigin ? { origin: currentOrigin } : {}),
|
|
1315
|
+
...(relatedObligationId ? { relatedObligationId } : {}),
|
|
1316
|
+
...(returnObligationId ? { relatedReturnObligationId: returnObligationId } : {}),
|
|
1317
|
+
...(parsedArgs.follows_packet_id ? { followsPacketId: parsedArgs.follows_packet_id } : {}),
|
|
1318
|
+
payload: packetPayload,
|
|
1319
|
+
});
|
|
1320
|
+
if (returnObligationId) {
|
|
1321
|
+
createLinkedReturnObligation(returnObligationId, packet.id);
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
else if (action === "revise") {
|
|
1326
|
+
const packetId = typeof parsedArgs.packet_id === "string" ? parsedArgs.packet_id.trim() : "";
|
|
1327
|
+
const kind = parsedArgs.kind;
|
|
1328
|
+
const objective = typeof parsedArgs.objective === "string" ? parsedArgs.objective.trim() : "";
|
|
1329
|
+
const summary = typeof parsedArgs.summary === "string" ? parsedArgs.summary.trim() : "";
|
|
1330
|
+
if (!packetId || !kind || !objective || !successCriteria || !payload) {
|
|
1331
|
+
throw new Error("ponder revise requires packet_id, kind, objective, success_criteria, and valid payload_json.");
|
|
1332
|
+
}
|
|
1333
|
+
packet = (0, packets_1.revisePonderPacket)((0, identity_2.getAgentRoot)(), packetId, {
|
|
1334
|
+
kind,
|
|
1335
|
+
objective,
|
|
1336
|
+
summary,
|
|
1337
|
+
successCriteria,
|
|
1338
|
+
payload,
|
|
1339
|
+
});
|
|
1340
|
+
returnObligationId = packet.relatedReturnObligationId
|
|
1341
|
+
&& !(packet.origin?.friendId === "self" && packet.origin.channel === "inner")
|
|
1342
|
+
? packet.relatedReturnObligationId
|
|
1343
|
+
: null;
|
|
1344
|
+
resultAction = "revised";
|
|
1345
|
+
}
|
|
1346
|
+
else {
|
|
1347
|
+
throw new Error("ponder requires action=create or revise.");
|
|
1348
|
+
}
|
|
1349
|
+
if (returnObligationId) {
|
|
1350
|
+
for (const token of extractPrivateReturnHeldTokens(privateReturnSourceRequest)) {
|
|
1351
|
+
privateReturnHeldTokens.add(token);
|
|
1352
|
+
}
|
|
1353
|
+
await (0, socket_client_1.requestInnerWake)((0, identity_2.getAgentName)(), augmentedToolContext?.daemonSocketPath).catch(() => undefined);
|
|
1354
|
+
}
|
|
1355
|
+
sawPonder = true;
|
|
1356
|
+
toolResult = buildPonderResult(packet, resultAction, returnObligationId);
|
|
1357
|
+
success = true;
|
|
1358
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1359
|
+
component: "engine",
|
|
1360
|
+
event: "engine.ponder_packet",
|
|
1361
|
+
message: "ponder packet touched",
|
|
1362
|
+
meta: {
|
|
1363
|
+
action: resultAction,
|
|
1364
|
+
packetId: packet.id,
|
|
1365
|
+
kind: packet.kind,
|
|
1366
|
+
status: packet.status,
|
|
1367
|
+
},
|
|
1368
|
+
});
|
|
1369
|
+
}
|
|
1370
|
+
catch (error) {
|
|
1371
|
+
toolResult = error instanceof Error ? error.message : String(error);
|
|
1372
|
+
}
|
|
1373
|
+
callbacks.onToolEnd(tc.name, argSummary, success);
|
|
1374
|
+
messages.push({ role: "tool", tool_call_id: tc.id, content: toolResult });
|
|
1375
|
+
providerRuntime.appendToolOutput(tc.id, toolResult);
|
|
1376
|
+
continue;
|
|
1377
|
+
}
|
|
1378
|
+
/* v8 ignore next -- flag tested via truth-check integration tests @preserve */
|
|
1379
|
+
if (tc.name === "query_session")
|
|
1380
|
+
sawQuerySession = true;
|
|
1381
|
+
/* v8 ignore next -- flag tested via truth-check integration tests @preserve */
|
|
1382
|
+
if (tc.name === "bridge_manage")
|
|
1383
|
+
sawBridgeManage = true;
|
|
1384
|
+
/* v8 ignore next -- flag tested via truth-check integration tests @preserve */
|
|
1385
|
+
if (isExternalStateQuery(tc.name, args))
|
|
1386
|
+
sawExternalStateQuery = true;
|
|
1387
|
+
const argSummary = (0, tools_1.summarizeArgs)(tc.name, args);
|
|
1388
|
+
const toolLoop = (0, tool_loop_1.detectToolLoop)(toolLoopState, tc.name, args);
|
|
1389
|
+
if (toolLoop.stuck) {
|
|
1390
|
+
const rejection = `loop guard: ${toolLoop.message}`;
|
|
1391
|
+
callbacks.onToolStart(tc.name, args);
|
|
1392
|
+
callbacks.onToolEnd(tc.name, argSummary, false);
|
|
1393
|
+
messages.push({ role: "tool", tool_call_id: tc.id, content: rejection });
|
|
1394
|
+
providerRuntime.appendToolOutput(tc.id, rejection);
|
|
1395
|
+
continue;
|
|
584
1396
|
}
|
|
585
1397
|
callbacks.onToolStart(tc.name, args);
|
|
586
1398
|
let toolResult;
|
|
@@ -594,69 +1406,32 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
594
1406
|
toolResult = `error: ${e}`;
|
|
595
1407
|
success = false;
|
|
596
1408
|
}
|
|
597
|
-
|
|
1409
|
+
toolResult = (0, tool_friction_1.rewriteToolResultForModel)(tc.name, toolResult, toolFrictionLedger);
|
|
1410
|
+
(0, tool_loop_1.recordToolOutcome)(toolLoopState, tc.name, args, toolResult, success);
|
|
1411
|
+
callbacks.onToolEnd(tc.name, (0, tools_1.buildToolResultSummary)(tc.name, args, toolResult, success), success);
|
|
598
1412
|
messages.push({ role: "tool", tool_call_id: tc.id, content: toolResult });
|
|
599
1413
|
providerRuntime.appendToolOutput(tc.id, toolResult);
|
|
1414
|
+
callbacks.onToolResult?.(messages);
|
|
600
1415
|
}
|
|
601
1416
|
}
|
|
602
1417
|
}
|
|
603
1418
|
catch (e) {
|
|
604
1419
|
// Abort is not an error — just stop cleanly
|
|
605
|
-
if (signal?.aborted) {
|
|
1420
|
+
if (e instanceof provider_attempt_1.ProviderAttemptAbortError || signal?.aborted) {
|
|
606
1421
|
stripLastToolCalls(messages);
|
|
607
1422
|
outcome = "aborted";
|
|
608
1423
|
break;
|
|
609
1424
|
}
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
const { maxTokens, contextMargin } = (0, config_1.getContextConfig)();
|
|
615
|
-
const trimmed = (0, context_1.trimMessages)(messages, maxTokens, contextMargin, maxTokens * 2);
|
|
616
|
-
messages.splice(0, messages.length, ...trimmed);
|
|
617
|
-
providerRuntime.resetTurnState(messages);
|
|
618
|
-
callbacks.onError(new Error("context trimmed, retrying..."), "transient");
|
|
619
|
-
continue;
|
|
1425
|
+
const errorForClassification = e instanceof Error ? e : /* v8 ignore next -- defensive @preserve */ new Error(String(e));
|
|
1426
|
+
let providerClassification;
|
|
1427
|
+
try {
|
|
1428
|
+
providerClassification = providerRuntime.classifyError(errorForClassification);
|
|
620
1429
|
}
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
const delay = RETRY_BASE_MS * Math.pow(2, retryCount - 1);
|
|
625
|
-
const cause = classifyTransientError(e);
|
|
626
|
-
callbacks.onError(new Error(`${cause}, retrying in ${delay / 1000}s (${retryCount}/${MAX_RETRIES})...`), "transient");
|
|
627
|
-
// Wait with abort support
|
|
628
|
-
const aborted = await new Promise((resolve) => {
|
|
629
|
-
const timer = setTimeout(() => resolve(false), delay);
|
|
630
|
-
if (signal) {
|
|
631
|
-
const onAbort = () => { clearTimeout(timer); resolve(true); };
|
|
632
|
-
if (signal.aborted) {
|
|
633
|
-
clearTimeout(timer);
|
|
634
|
-
resolve(true);
|
|
635
|
-
return;
|
|
636
|
-
}
|
|
637
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
638
|
-
}
|
|
639
|
-
});
|
|
640
|
-
if (aborted) {
|
|
641
|
-
stripLastToolCalls(messages);
|
|
642
|
-
outcome = "aborted";
|
|
643
|
-
break;
|
|
644
|
-
}
|
|
645
|
-
providerRuntime.resetTurnState(messages);
|
|
646
|
-
continue;
|
|
1430
|
+
catch {
|
|
1431
|
+
/* v8 ignore next -- defensive: classifyError should not throw @preserve */
|
|
1432
|
+
providerClassification = "unknown";
|
|
647
1433
|
}
|
|
648
|
-
|
|
649
|
-
(0, runtime_1.emitNervesEvent)({
|
|
650
|
-
level: "error",
|
|
651
|
-
event: "engine.error",
|
|
652
|
-
trace_id: traceId,
|
|
653
|
-
component: "engine",
|
|
654
|
-
message: e instanceof Error ? e.message : String(e),
|
|
655
|
-
meta: {},
|
|
656
|
-
});
|
|
657
|
-
stripLastToolCalls(messages);
|
|
658
|
-
outcome = "errored";
|
|
659
|
-
done = true;
|
|
1434
|
+
finishTerminalProviderError(errorForClassification, providerClassification);
|
|
660
1435
|
}
|
|
661
1436
|
}
|
|
662
1437
|
(0, runtime_1.emitNervesEvent)({
|
|
@@ -664,7 +1439,12 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
664
1439
|
trace_id: traceId,
|
|
665
1440
|
component: "engine",
|
|
666
1441
|
message: "runAgent turn completed",
|
|
667
|
-
meta: { done },
|
|
1442
|
+
meta: { done, sawPonder, sawQuerySession, sawBridgeManage },
|
|
668
1443
|
});
|
|
669
|
-
return {
|
|
1444
|
+
return {
|
|
1445
|
+
usage: lastUsage,
|
|
1446
|
+
outcome,
|
|
1447
|
+
completion,
|
|
1448
|
+
...(terminalError ? { error: terminalError, errorClassification: terminalErrorClassification } : {}),
|
|
1449
|
+
};
|
|
670
1450
|
}
|