@ouro.bot/cli 0.1.0-alpha.49 → 0.1.0-alpha.491
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 +133 -19
- package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/agent.json +3 -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 +3126 -0
- package/dist/arc/attention-types.js +8 -0
- package/dist/arc/cares.js +140 -0
- package/dist/arc/episodes.js +117 -0
- package/dist/arc/intentions.js +133 -0
- package/dist/arc/json-store.js +117 -0
- package/dist/arc/obligations.js +237 -0
- package/dist/arc/packets.js +193 -0
- package/dist/arc/presence.js +185 -0
- package/dist/arc/task-lifecycle.js +65 -0
- package/dist/heart/active-work.js +989 -0
- package/dist/heart/agent-entry.js +58 -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/adapter.js +2 -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 +426 -0
- package/dist/heart/background-operations.js +281 -0
- package/dist/heart/bridges/manager.js +37 -0
- package/dist/heart/bridges/state-machine.js +20 -0
- package/dist/heart/bundle-state.js +168 -0
- package/dist/heart/commitments.js +111 -0
- package/dist/heart/config-registry.js +304 -0
- package/dist/heart/config.js +119 -129
- package/dist/heart/core.js +845 -229
- package/dist/heart/cross-chat-delivery.js +131 -0
- package/dist/heart/daemon/agent-config-check.js +490 -0
- package/dist/heart/daemon/agent-discovery.js +79 -3
- package/dist/heart/daemon/agent-service.js +360 -0
- package/dist/heart/daemon/agentic-repair.js +216 -0
- package/dist/heart/daemon/bluebubbles-health-diagnostics.js +122 -0
- package/dist/heart/daemon/cadence.js +70 -0
- package/dist/heart/daemon/cli-defaults.js +640 -0
- package/dist/heart/daemon/cli-exec.js +7239 -0
- package/dist/heart/daemon/cli-help.js +493 -0
- package/dist/heart/daemon/cli-parse.js +1533 -0
- package/dist/heart/daemon/cli-render-doctor.js +57 -0
- package/dist/heart/daemon/cli-render.js +561 -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 -1616
- package/dist/heart/daemon/daemon-entry.js +345 -3
- package/dist/heart/daemon/daemon-health.js +141 -0
- package/dist/heart/daemon/daemon-runtime-sync.js +190 -12
- package/dist/heart/daemon/daemon-tombstone.js +236 -0
- package/dist/heart/daemon/daemon.js +677 -58
- package/dist/heart/daemon/dns-workflow.js +394 -0
- package/dist/heart/daemon/doctor-types.js +8 -0
- package/dist/heart/daemon/doctor.js +486 -0
- package/dist/heart/daemon/health-monitor.js +92 -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 +25 -5
- package/dist/heart/daemon/log-tailer.js +82 -12
- package/dist/heart/daemon/logs-prune.js +110 -0
- package/dist/heart/daemon/message-router.js +2 -2
- package/dist/heart/daemon/os-cron-deps.js +134 -0
- package/dist/heart/daemon/ouro-bot-entry.js +4 -2
- package/dist/heart/daemon/ouro-entry.js +3 -1
- package/dist/heart/daemon/process-manager.js +214 -0
- 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 +67 -16
- package/dist/heart/daemon/runtime-metadata.js +73 -0
- package/dist/heart/daemon/runtime-mode.js +67 -0
- package/dist/heart/daemon/safe-mode.js +161 -0
- package/dist/heart/daemon/sense-manager.js +178 -37
- package/dist/heart/daemon/session-id-resolver.js +131 -0
- package/dist/heart/daemon/skill-management-installer.js +94 -0
- package/dist/heart/daemon/socket-client.js +109 -4
- package/dist/heart/daemon/stale-bundle-prune.js +96 -0
- package/dist/heart/daemon/startup-tui.js +264 -0
- package/dist/heart/daemon/task-scheduler.js +3 -25
- package/dist/heart/daemon/terminal-ui.js +499 -0
- package/dist/heart/daemon/thoughts.js +162 -17
- package/dist/heart/daemon/up-progress.js +366 -0
- package/dist/heart/daemon/vault-items.js +56 -0
- package/dist/heart/delegation.js +62 -0
- 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 +52 -117
- package/dist/heart/{daemon → hatch}/hatch-specialist.js +3 -3
- package/dist/heart/{daemon → hatch}/specialist-prompt.js +12 -9
- package/dist/heart/{daemon → hatch}/specialist-tools.js +35 -12
- package/dist/heart/identity.js +201 -66
- 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/mcp/mcp-server.js +653 -0
- package/dist/heart/migrate-config.js +100 -0
- package/dist/heart/model-capabilities.js +59 -0
- package/dist/heart/outlook/outlook-http-hooks.js +66 -0
- package/dist/heart/outlook/outlook-http-response.js +7 -0
- package/dist/heart/outlook/outlook-http-routes.js +244 -0
- package/dist/heart/outlook/outlook-http-static.js +103 -0
- package/dist/heart/outlook/outlook-http-transport.js +116 -0
- package/dist/heart/outlook/outlook-http.js +99 -0
- package/dist/heart/outlook/outlook-read.js +31 -0
- package/dist/heart/outlook/outlook-types.js +27 -0
- package/dist/heart/outlook/outlook-view.js +195 -0
- package/dist/heart/outlook/readers/agent-machine.js +382 -0
- package/dist/heart/outlook/readers/continuity-readers.js +336 -0
- package/dist/heart/outlook/readers/mail.js +362 -0
- package/dist/heart/outlook/readers/runtime-readers.js +644 -0
- package/dist/heart/outlook/readers/sessions.js +232 -0
- package/dist/heart/outlook/readers/shared.js +111 -0
- package/dist/heart/platform.js +81 -0
- package/dist/heart/progress-story.js +42 -0
- package/dist/heart/provider-attempt.js +134 -0
- package/dist/heart/provider-binding-resolver.js +255 -0
- package/dist/heart/provider-credentials.js +424 -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-state.js +216 -0
- package/dist/heart/provider-visibility.js +188 -0
- package/dist/heart/providers/anthropic-token.js +131 -0
- package/dist/heart/providers/anthropic.js +193 -55
- package/dist/heart/providers/azure.js +104 -13
- package/dist/heart/providers/error-classification.js +63 -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 +29 -7
- package/dist/heart/providers/openai-codex.js +63 -39
- package/dist/heart/runtime-capability-check.js +170 -0
- package/dist/heart/runtime-credentials.js +260 -0
- package/dist/heart/sense-truth.js +11 -4
- package/dist/heart/session-activity.js +190 -0
- package/dist/heart/session-events.js +981 -0
- package/dist/heart/session-transcript.js +167 -0
- package/dist/heart/start-of-turn-packet.js +345 -0
- package/dist/heart/streaming.js +48 -28
- package/dist/heart/sync.js +332 -0
- package/dist/heart/target-resolution.js +127 -0
- package/dist/heart/tempo.js +93 -0
- package/dist/heart/temporal-view.js +41 -0
- package/dist/heart/tool-activity-callbacks.js +36 -0
- package/dist/heart/tool-description.js +135 -0
- package/dist/heart/tool-friction.js +55 -0
- package/dist/heart/tool-loop.js +200 -0
- package/dist/heart/turn-context.js +372 -0
- package/dist/heart/{daemon → versioning}/ouro-bot-global-installer.js +1 -1
- package/dist/heart/{daemon → versioning}/ouro-bot-wrapper.js +1 -1
- package/dist/heart/versioning/ouro-path-installer.js +425 -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 +5 -1
- package/dist/heart/{daemon → versioning}/update-hooks.js +63 -59
- package/dist/mailroom/attention.js +167 -0
- package/dist/mailroom/autonomy.js +209 -0
- package/dist/mailroom/blob-store.js +600 -0
- package/dist/mailroom/core.js +658 -0
- package/dist/mailroom/entry.js +160 -0
- package/dist/mailroom/file-store.js +426 -0
- package/dist/mailroom/mbox-import.js +382 -0
- package/dist/mailroom/outbound.js +380 -0
- package/dist/mailroom/policy.js +263 -0
- package/dist/mailroom/reader.js +219 -0
- package/dist/mailroom/search-cache.js +182 -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/travel-extract.js +89 -0
- package/dist/mind/bundle-manifest.js +7 -1
- package/dist/mind/context.js +164 -93
- package/dist/mind/diary-integrity.js +60 -0
- package/dist/mind/{memory.js → diary.js} +74 -93
- package/dist/mind/embedding-provider.js +60 -0
- package/dist/mind/file-state.js +179 -0
- package/dist/mind/friends/channel.js +30 -0
- package/dist/mind/friends/group-context.js +144 -0
- package/dist/mind/friends/resolver.js +54 -2
- package/dist/mind/friends/store-file.js +39 -3
- package/dist/mind/friends/trust-explanation.js +74 -0
- package/dist/mind/friends/types.js +2 -2
- package/dist/mind/journal-index.js +161 -0
- package/dist/mind/note-search.js +268 -0
- package/dist/mind/obligation-steering.js +221 -0
- package/dist/mind/pending.js +56 -8
- package/dist/mind/prompt-refresh.js +3 -2
- package/dist/mind/prompt.js +973 -168
- 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 +93 -5
- package/dist/nerves/coverage/run-artifacts.js +1 -1
- 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/runtime.js +5 -1
- package/dist/outlook-ui/assets/index-BPr5vNuM.css +1 -0
- package/dist/outlook-ui/assets/index-Cm51CY9W.js +61 -0
- package/dist/outlook-ui/index.html +15 -0
- package/dist/repertoire/ado-client.js +15 -56
- package/dist/repertoire/ado-semantic.js +11 -10
- package/dist/repertoire/api-client.js +97 -0
- package/dist/repertoire/bitwarden-store.js +774 -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 +330 -0
- package/dist/repertoire/coding/feedback.js +197 -30
- package/dist/repertoire/coding/manager.js +158 -9
- package/dist/repertoire/coding/spawner.js +55 -9
- package/dist/repertoire/coding/tools.js +170 -7
- package/dist/repertoire/commerce-errors.js +109 -0
- package/dist/repertoire/commerce-self-test.js +156 -0
- package/dist/repertoire/credential-access.js +111 -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 +396 -0
- package/dist/repertoire/mcp-client.js +255 -0
- package/dist/repertoire/mcp-manager.js +305 -0
- package/dist/repertoire/mcp-tools.js +63 -0
- package/dist/repertoire/shell-sessions.js +133 -0
- package/dist/repertoire/skills.js +15 -24
- package/dist/repertoire/stripe-client.js +131 -0
- package/dist/repertoire/tasks/board.js +31 -5
- package/dist/repertoire/tasks/fix.js +182 -0
- package/dist/repertoire/tasks/index.js +16 -4
- package/dist/repertoire/tasks/lifecycle.js +2 -2
- package/dist/repertoire/tasks/parser.js +3 -2
- package/dist/repertoire/tasks/scanner.js +194 -37
- package/dist/repertoire/tasks/transitions.js +16 -78
- package/dist/repertoire/tool-results.js +29 -0
- package/dist/repertoire/tools-attachments.js +317 -0
- package/dist/repertoire/tools-base.js +46 -842
- package/dist/repertoire/tools-bluebubbles.js +1 -0
- package/dist/repertoire/tools-bridge.js +141 -0
- package/dist/repertoire/tools-bundle.js +984 -0
- package/dist/repertoire/tools-config.js +185 -0
- package/dist/repertoire/tools-continuity.js +248 -0
- package/dist/repertoire/tools-credential.js +381 -0
- package/dist/repertoire/tools-files.js +342 -0
- package/dist/repertoire/tools-flight.js +224 -0
- package/dist/repertoire/tools-flow.js +105 -0
- package/dist/repertoire/tools-github.js +1 -7
- package/dist/repertoire/tools-mail.js +1281 -0
- package/dist/repertoire/tools-notes.js +376 -0
- package/dist/repertoire/tools-session.js +749 -0
- package/dist/repertoire/tools-shell.js +120 -0
- package/dist/repertoire/tools-stripe.js +180 -0
- package/dist/repertoire/tools-surface.js +243 -0
- package/dist/repertoire/tools-teams.js +9 -39
- package/dist/repertoire/tools-travel.js +125 -0
- package/dist/repertoire/tools-trip.js +356 -0
- package/dist/repertoire/tools-user-profile.js +144 -0
- package/dist/repertoire/tools-vault.js +40 -0
- package/dist/repertoire/tools.js +144 -115
- 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 +561 -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 +116 -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 +73 -0
- package/dist/senses/{bluebubbles-inbound-log.js → bluebubbles/inbound-log.js} +20 -3
- package/dist/senses/bluebubbles/index.js +1835 -0
- package/dist/senses/{bluebubbles-media.js → bluebubbles/media.js} +121 -70
- 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 +111 -0
- package/dist/senses/bluebubbles/replay.js +129 -0
- package/dist/senses/{bluebubbles-runtime-state.js → bluebubbles/runtime-state.js} +2 -2
- package/dist/senses/{bluebubbles-session-cleanup.js → bluebubbles/session-cleanup.js} +1 -1
- 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 +605 -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 +83 -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 +187 -0
- package/dist/senses/cli.js +515 -211
- package/dist/senses/commands.js +66 -3
- package/dist/senses/habit-turn-message.js +108 -0
- package/dist/senses/inner-dialog-worker.js +110 -20
- package/dist/senses/inner-dialog.js +408 -21
- package/dist/senses/mail-entry.js +66 -0
- package/dist/senses/mail.js +379 -0
- package/dist/senses/pipeline.js +588 -81
- package/dist/senses/proactive-content-guard.js +51 -0
- package/dist/senses/shared-turn.js +248 -0
- package/dist/senses/surface-tool.js +68 -0
- package/dist/senses/teams-entry.js +60 -8
- package/dist/senses/teams.js +412 -163
- package/dist/senses/trust-gate.js +100 -5
- package/dist/trips/core.js +138 -0
- package/dist/trips/store.js +146 -0
- package/package.json +37 -7
- 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 +101 -0
- package/skills/travel-planning.md +138 -0
- package/dist/heart/daemon/ouro-path-installer.js +0 -178
- package/dist/heart/daemon/subagent-installer.js +0 -166
- package/dist/heart/session-recall.js +0 -116
- package/dist/mind/associative-recall.js +0 -209
- package/dist/senses/bluebubbles-entry.js +0 -13
- package/dist/senses/bluebubbles.js +0 -1032
- package/dist/senses/debug-activity.js +0 -127
- package/subagents/README.md +0 -86
- package/subagents/work-doer.md +0 -237
- package/subagents/work-merger.md +0 -618
- package/subagents/work-planner.md +0 -390
- /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/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,94 +1,157 @@
|
|
|
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.isExternalStateQuery = isExternalStateQuery;
|
|
10
|
+
exports.getSettleRetryError = getSettleRetryError;
|
|
10
11
|
exports.stripLastToolCalls = stripLastToolCalls;
|
|
11
12
|
exports.repairOrphanedToolCalls = repairOrphanedToolCalls;
|
|
12
|
-
exports.isTransientError = isTransientError;
|
|
13
|
-
exports.classifyTransientError = classifyTransientError;
|
|
14
13
|
exports.runAgent = runAgent;
|
|
15
14
|
const config_1 = require("./config");
|
|
16
15
|
const identity_1 = require("./identity");
|
|
17
16
|
const tools_1 = require("../repertoire/tools");
|
|
18
17
|
const channel_1 = require("../mind/friends/channel");
|
|
18
|
+
const tools_2 = require("../repertoire/tools");
|
|
19
19
|
const runtime_1 = require("../nerves/runtime");
|
|
20
20
|
const context_1 = require("../mind/context");
|
|
21
21
|
const prompt_1 = require("../mind/prompt");
|
|
22
|
-
const
|
|
22
|
+
const kept_notes_1 = require("./kept-notes");
|
|
23
23
|
const anthropic_1 = require("./providers/anthropic");
|
|
24
24
|
const azure_1 = require("./providers/azure");
|
|
25
25
|
const minimax_1 = require("./providers/minimax");
|
|
26
26
|
const openai_codex_1 = require("./providers/openai-codex");
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
const github_copilot_1 = require("./providers/github-copilot");
|
|
28
|
+
const identity_2 = require("./identity");
|
|
29
|
+
const socket_client_1 = require("./daemon/socket-client");
|
|
30
|
+
const obligations_1 = require("../arc/obligations");
|
|
31
|
+
const tool_loop_1 = require("./tool-loop");
|
|
32
|
+
const packets_1 = require("../arc/packets");
|
|
33
|
+
const tool_friction_1 = require("./tool-friction");
|
|
34
|
+
const provider_models_1 = require("./provider-models");
|
|
35
|
+
const provider_credentials_1 = require("./provider-credentials");
|
|
36
|
+
const provider_state_1 = require("./provider-state");
|
|
37
|
+
const provider_attempt_1 = require("./provider-attempt");
|
|
38
|
+
const _providerRuntimes = {
|
|
39
|
+
human: null,
|
|
40
|
+
agent: null,
|
|
41
|
+
};
|
|
42
|
+
function providerLaneForFacing(facing) {
|
|
43
|
+
return facing === "human" ? "outward" : "inner";
|
|
44
|
+
}
|
|
45
|
+
function resolveRuntimeProviderBinding(facing) {
|
|
46
|
+
const agentName = (0, identity_2.getAgentName)();
|
|
47
|
+
const lane = providerLaneForFacing(facing);
|
|
48
|
+
const stateResult = (0, provider_state_1.readProviderState)((0, identity_2.getAgentRoot)(agentName));
|
|
49
|
+
if (stateResult.ok) {
|
|
50
|
+
const binding = stateResult.state.lanes[lane];
|
|
51
|
+
return { lane, provider: binding.provider, model: binding.model };
|
|
52
|
+
}
|
|
53
|
+
if (stateResult.reason === "invalid") {
|
|
54
|
+
throw new Error(`provider state for ${agentName} is invalid at ${stateResult.statePath}: ${stateResult.error}`);
|
|
55
|
+
}
|
|
56
|
+
// First-run and SerpentGuide bootstrap path. Daemon startup normally
|
|
57
|
+
// bootstraps state/providers.json from agent.json before model calls.
|
|
58
|
+
const config = (0, identity_1.loadAgentConfig)();
|
|
59
|
+
const facingConfig = facing === "human" ? config.humanFacing : config.agentFacing;
|
|
60
|
+
return { lane, provider: facingConfig.provider, model: facingConfig.model };
|
|
61
|
+
}
|
|
62
|
+
async function getProviderRuntimeFingerprint(facing) {
|
|
63
|
+
const agentName = (0, identity_2.getAgentName)();
|
|
64
|
+
const binding = resolveRuntimeProviderBinding(facing);
|
|
65
|
+
const credential = await (0, provider_credentials_1.readProviderCredentialRecord)(agentName, binding.provider);
|
|
66
|
+
if (!credential.ok) {
|
|
67
|
+
throw new Error([
|
|
68
|
+
`${binding.lane} provider ${binding.provider} (${binding.model}) has no credentials for ${agentName}.`,
|
|
69
|
+
credential.error,
|
|
70
|
+
`Run \`ouro auth --agent ${agentName} --provider ${binding.provider}\`.`,
|
|
71
|
+
].join("\n"));
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
binding,
|
|
75
|
+
fingerprint: JSON.stringify({
|
|
76
|
+
lane: binding.lane,
|
|
77
|
+
provider: binding.provider,
|
|
78
|
+
model: binding.model,
|
|
79
|
+
credentialRevision: credential.record.revision,
|
|
80
|
+
}),
|
|
81
|
+
credential: credential.record,
|
|
34
82
|
};
|
|
83
|
+
}
|
|
84
|
+
function createProviderRegistry() {
|
|
35
85
|
return {
|
|
36
|
-
resolve() {
|
|
37
|
-
const
|
|
38
|
-
|
|
86
|
+
resolve(provider, model, credential) {
|
|
87
|
+
const providerConfig = { ...credential.config, ...credential.credentials };
|
|
88
|
+
switch (provider) {
|
|
89
|
+
case "azure":
|
|
90
|
+
return (0, azure_1.createAzureProviderRuntime)(model, providerConfig);
|
|
91
|
+
case "anthropic":
|
|
92
|
+
return (0, anthropic_1.createAnthropicProviderRuntime)(model, providerConfig);
|
|
93
|
+
case "minimax":
|
|
94
|
+
return (0, minimax_1.createMinimaxProviderRuntime)(model, providerConfig);
|
|
95
|
+
case "openai-codex":
|
|
96
|
+
return (0, openai_codex_1.createOpenAICodexProviderRuntime)(model, providerConfig);
|
|
97
|
+
case "github-copilot":
|
|
98
|
+
return (0, github_copilot_1.createGithubCopilotProviderRuntime)(model, providerConfig);
|
|
99
|
+
}
|
|
39
100
|
},
|
|
40
101
|
};
|
|
41
102
|
}
|
|
42
|
-
function getProviderRuntime() {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
(0, runtime_1.emitNervesEvent)({
|
|
50
|
-
level: "error",
|
|
51
|
-
event: "engine.provider_init_error",
|
|
52
|
-
component: "engine",
|
|
53
|
-
message: msg,
|
|
54
|
-
meta: {},
|
|
55
|
-
});
|
|
56
|
-
// eslint-disable-next-line no-console -- pre-boot guard: provider init failure
|
|
57
|
-
console.error(`\n[fatal] ${msg}\n`);
|
|
58
|
-
process.exit(1);
|
|
59
|
-
throw new Error("unreachable");
|
|
60
|
-
}
|
|
61
|
-
if (!_providerRuntime) {
|
|
62
|
-
(0, runtime_1.emitNervesEvent)({
|
|
63
|
-
level: "error",
|
|
64
|
-
event: "engine.provider_init_error",
|
|
65
|
-
component: "engine",
|
|
66
|
-
message: "provider runtime could not be initialized.",
|
|
67
|
-
meta: {},
|
|
68
|
-
});
|
|
69
|
-
process.exit(1);
|
|
70
|
-
throw new Error("unreachable");
|
|
103
|
+
async function getProviderRuntime(facing = "human") {
|
|
104
|
+
try {
|
|
105
|
+
const { binding, fingerprint, credential } = await getProviderRuntimeFingerprint(facing);
|
|
106
|
+
const cached = _providerRuntimes[facing];
|
|
107
|
+
if (!cached || cached.fingerprint !== fingerprint) {
|
|
108
|
+
const runtime = createProviderRegistry().resolve(binding.provider, binding.model, credential);
|
|
109
|
+
_providerRuntimes[facing] = runtime ? { fingerprint, runtime } : null;
|
|
71
110
|
}
|
|
72
111
|
}
|
|
73
|
-
|
|
112
|
+
catch (error) {
|
|
113
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
114
|
+
(0, runtime_1.emitNervesEvent)({
|
|
115
|
+
level: "error",
|
|
116
|
+
event: "engine.provider_init_error",
|
|
117
|
+
component: "engine",
|
|
118
|
+
message: msg,
|
|
119
|
+
meta: {},
|
|
120
|
+
});
|
|
121
|
+
// eslint-disable-next-line no-console -- pre-boot guard: provider init failure
|
|
122
|
+
console.error(`\n[fatal] ${msg}\n`);
|
|
123
|
+
process.exit(1);
|
|
124
|
+
}
|
|
125
|
+
if (!_providerRuntimes[facing]) {
|
|
126
|
+
(0, runtime_1.emitNervesEvent)({
|
|
127
|
+
level: "error",
|
|
128
|
+
event: "engine.provider_init_error",
|
|
129
|
+
component: "engine",
|
|
130
|
+
message: "provider runtime could not be initialized.",
|
|
131
|
+
meta: {},
|
|
132
|
+
});
|
|
133
|
+
process.exit(1);
|
|
134
|
+
}
|
|
135
|
+
return _providerRuntimes[facing].runtime;
|
|
74
136
|
}
|
|
75
137
|
/**
|
|
76
|
-
* Clear the cached provider runtime so the next
|
|
77
|
-
*
|
|
78
|
-
*
|
|
138
|
+
* Clear the cached provider runtime so the next access re-creates it from
|
|
139
|
+
* current config. Runtime access also auto-refreshes when the selected
|
|
140
|
+
* provider fingerprint changes on disk.
|
|
79
141
|
*/
|
|
80
142
|
function resetProviderRuntime() {
|
|
81
|
-
|
|
143
|
+
_providerRuntimes.human = null;
|
|
144
|
+
_providerRuntimes.agent = null;
|
|
82
145
|
}
|
|
83
|
-
function getModel() {
|
|
84
|
-
return
|
|
146
|
+
function getModel(facing = "human") {
|
|
147
|
+
return resolveRuntimeProviderBinding(facing).model;
|
|
85
148
|
}
|
|
86
|
-
function getProvider() {
|
|
87
|
-
return
|
|
149
|
+
function getProvider(facing = "human") {
|
|
150
|
+
return resolveRuntimeProviderBinding(facing).provider;
|
|
88
151
|
}
|
|
89
|
-
function createSummarize() {
|
|
152
|
+
function createSummarize(facing = "human") {
|
|
90
153
|
return async (transcript, instruction) => {
|
|
91
|
-
const runtime = getProviderRuntime();
|
|
154
|
+
const runtime = await getProviderRuntime(facing);
|
|
92
155
|
const client = runtime.client;
|
|
93
156
|
const response = await client.chat.completions.create({
|
|
94
157
|
model: runtime.model,
|
|
@@ -101,32 +164,60 @@ function createSummarize() {
|
|
|
101
164
|
return response.choices?.[0]?.message?.content ?? transcript;
|
|
102
165
|
};
|
|
103
166
|
}
|
|
104
|
-
function getProviderDisplayLabel() {
|
|
105
|
-
const
|
|
167
|
+
function getProviderDisplayLabel(facing = "human") {
|
|
168
|
+
const binding = resolveRuntimeProviderBinding(facing);
|
|
169
|
+
const provider = binding.provider;
|
|
170
|
+
const model = binding.model || "unknown";
|
|
106
171
|
const providerLabelBuilders = {
|
|
107
|
-
azure: () =>
|
|
172
|
+
azure: () => {
|
|
173
|
+
return `azure openai (model: ${model})`;
|
|
174
|
+
},
|
|
108
175
|
anthropic: () => `anthropic (${model})`,
|
|
109
176
|
minimax: () => `minimax (${model})`,
|
|
110
177
|
"openai-codex": () => `openai codex (${model})`,
|
|
178
|
+
/* v8 ignore next -- branch: tested via display label unit test @preserve */
|
|
179
|
+
"github-copilot": () => `github copilot (${model})`,
|
|
111
180
|
};
|
|
112
|
-
return providerLabelBuilders[
|
|
181
|
+
return providerLabelBuilders[provider]();
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Strip <think>...</think> blocks for the violation-detection check at the
|
|
185
|
+
* end of a streaming turn. Used to tell legitimate text-only responses
|
|
186
|
+
* apart from the MiniMax-M2.7 "only thinking, no tool call" violation
|
|
187
|
+
* shape. Mirrors the more thorough stripThinkBlocks helper in
|
|
188
|
+
* senses/shared-turn.ts (which is for operator-facing output) — kept
|
|
189
|
+
* inline here to avoid pulling senses/ into the core module's import graph.
|
|
190
|
+
*/
|
|
191
|
+
function stripThinkBlocksForViolationCheck(input) {
|
|
192
|
+
let out = input;
|
|
193
|
+
for (;;) {
|
|
194
|
+
const open = out.indexOf("<think>");
|
|
195
|
+
if (open === -1)
|
|
196
|
+
break;
|
|
197
|
+
const close = out.indexOf("</think>", open + "<think>".length);
|
|
198
|
+
if (close === -1) {
|
|
199
|
+
out = out.slice(0, open);
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
out = out.slice(0, open) + out.slice(close + "</think>".length);
|
|
203
|
+
}
|
|
204
|
+
return out.trim();
|
|
205
|
+
}
|
|
206
|
+
function hasFreshPendingWork(options) {
|
|
207
|
+
const pendingMessages = options?.pendingMessages;
|
|
208
|
+
if (!Array.isArray(pendingMessages))
|
|
209
|
+
return false;
|
|
210
|
+
return pendingMessages.some((message) => typeof message?.content === "string"
|
|
211
|
+
&& message.content.trim().length > 0);
|
|
113
212
|
}
|
|
114
|
-
//
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
Object.defineProperty(exports, "streamChatCompletion", { enumerable: true, get: function () { return streaming_1.streamChatCompletion; } });
|
|
123
|
-
Object.defineProperty(exports, "streamResponsesApi", { enumerable: true, get: function () { return streaming_1.streamResponsesApi; } });
|
|
124
|
-
Object.defineProperty(exports, "toResponsesInput", { enumerable: true, get: function () { return streaming_1.toResponsesInput; } });
|
|
125
|
-
Object.defineProperty(exports, "toResponsesTools", { enumerable: true, get: function () { return streaming_1.toResponsesTools; } });
|
|
126
|
-
// Re-export prompt functions for backward compat
|
|
127
|
-
var prompt_2 = require("../mind/prompt");
|
|
128
|
-
Object.defineProperty(exports, "buildSystem", { enumerable: true, get: function () { return prompt_2.buildSystem; } });
|
|
129
|
-
function parseFinalAnswerPayload(argumentsText) {
|
|
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) {
|
|
130
221
|
try {
|
|
131
222
|
const parsed = JSON.parse(argumentsText);
|
|
132
223
|
if (typeof parsed === "string") {
|
|
@@ -146,18 +237,93 @@ function parseFinalAnswerPayload(argumentsText) {
|
|
|
146
237
|
return {};
|
|
147
238
|
}
|
|
148
239
|
}
|
|
149
|
-
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 buildPonderResult(packet, action, returnObligationId) {
|
|
285
|
+
return JSON.stringify({
|
|
286
|
+
ok: true,
|
|
287
|
+
packet_id: packet.id,
|
|
288
|
+
action,
|
|
289
|
+
status: packet.status,
|
|
290
|
+
return_obligation_id: returnObligationId,
|
|
291
|
+
}, null, 2);
|
|
292
|
+
}
|
|
293
|
+
/** Returns true when a tool call queries external state (GitHub, npm registry). */
|
|
294
|
+
function isExternalStateQuery(toolName, args) {
|
|
295
|
+
if (toolName !== "shell")
|
|
296
|
+
return false;
|
|
297
|
+
const cmd = String(args.command ?? "");
|
|
298
|
+
return /\bgh\s+(pr|run|api|issue)\b/.test(cmd) || /\bnpm\s+(view|info|show)\b/.test(cmd);
|
|
299
|
+
}
|
|
300
|
+
function getSettleRetryError(mustResolveBeforeHandoff, intent, sawSteeringFollowUp, _delegationDecision, sawSendMessageSelf, sawPonder, _sawQuerySession, currentObligation, innerJob, sawExternalStateQuery) {
|
|
301
|
+
// Delegation adherence removed: the delegation decision is surfaced in the
|
|
302
|
+
// system prompt as a suggestion. Hard-gating settle caused infinite
|
|
303
|
+
// rejection loops where the agent couldn't respond to the user at all.
|
|
304
|
+
// The agent is free to follow or ignore the delegation hint.
|
|
305
|
+
// 2. Pending obligation not addressed
|
|
306
|
+
if (innerJob?.obligationStatus === "pending" && !sawSendMessageSelf && !sawPonder) {
|
|
307
|
+
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.";
|
|
308
|
+
}
|
|
309
|
+
// 3. mustResolveBeforeHandoff + missing intent
|
|
150
310
|
if (mustResolveBeforeHandoff && !intent) {
|
|
151
|
-
return "your
|
|
311
|
+
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.";
|
|
152
312
|
}
|
|
313
|
+
// 4. mustResolveBeforeHandoff + direct_reply without follow-up
|
|
153
314
|
if (mustResolveBeforeHandoff && intent === "direct_reply" && !sawSteeringFollowUp) {
|
|
154
|
-
return "your
|
|
315
|
+
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.";
|
|
316
|
+
}
|
|
317
|
+
// 5. mustResolveBeforeHandoff + complete while a live return loop is still active
|
|
318
|
+
if (mustResolveBeforeHandoff && intent === "complete" && currentObligation && !sawSteeringFollowUp) {
|
|
319
|
+
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.";
|
|
155
320
|
}
|
|
156
|
-
|
|
321
|
+
// 6. External-state grounding: obligation + complete requires fresh external verification
|
|
322
|
+
if (intent === "complete" && currentObligation && !sawExternalStateQuery && !sawSteeringFollowUp) {
|
|
323
|
+
return "you're claiming this work is complete, but the external state hasn't been verified this turn. ground your claim with a fresh check (gh pr view, npm view, gh run view, etc.) before calling settle.";
|
|
324
|
+
}
|
|
325
|
+
return null;
|
|
157
326
|
}
|
|
158
|
-
// Re-export kick utilities for backward compat
|
|
159
|
-
var kicks_1 = require("./kicks");
|
|
160
|
-
Object.defineProperty(exports, "hasToolIntent", { enumerable: true, get: function () { return kicks_1.hasToolIntent; } });
|
|
161
327
|
function upsertSystemPrompt(messages, systemText) {
|
|
162
328
|
const systemMessage = { role: "system", content: systemText };
|
|
163
329
|
if (messages[0]?.role === "system") {
|
|
@@ -263,49 +429,67 @@ function isContextOverflow(err) {
|
|
|
263
429
|
return true;
|
|
264
430
|
return false;
|
|
265
431
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
432
|
+
const RETRY_LABELS = {
|
|
433
|
+
"auth-failure": "auth error",
|
|
434
|
+
"usage-limit": "usage limit",
|
|
435
|
+
"rate-limit": "rate limited",
|
|
436
|
+
"server-error": "server error",
|
|
437
|
+
"network-error": "network error",
|
|
438
|
+
"unknown": "error",
|
|
439
|
+
};
|
|
440
|
+
function waitForProviderRetry(delayMs, signal) {
|
|
441
|
+
if (!signal) {
|
|
442
|
+
return new Promise((resolve) => {
|
|
443
|
+
setTimeout(resolve, delayMs);
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
return new Promise((resolve, reject) => {
|
|
447
|
+
let timer;
|
|
448
|
+
const onAbort = () => {
|
|
449
|
+
clearTimeout(timer);
|
|
450
|
+
reject(new provider_attempt_1.ProviderAttemptAbortError());
|
|
451
|
+
};
|
|
452
|
+
timer = setTimeout(() => {
|
|
453
|
+
signal.removeEventListener("abort", onAbort);
|
|
454
|
+
resolve();
|
|
455
|
+
}, delayMs);
|
|
456
|
+
if (signal.aborted) {
|
|
457
|
+
onAbort();
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
461
|
+
});
|
|
292
462
|
}
|
|
293
|
-
function
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
463
|
+
function buildAuthFailureGuidance(provider, model, agentName, detail) {
|
|
464
|
+
const mismatch = (0, provider_models_1.getProviderModelMismatchMessage)(provider, model);
|
|
465
|
+
const modelLabel = model
|
|
466
|
+
? mismatch
|
|
467
|
+
? `${provider} [configured model: ${model}]`
|
|
468
|
+
: `${provider} (${model})`
|
|
469
|
+
: provider;
|
|
470
|
+
const lines = [`${modelLabel} authentication failed.`];
|
|
471
|
+
const cleanDetail = detail.replace(/\s+/g, " ").trim();
|
|
472
|
+
if (cleanDetail)
|
|
473
|
+
lines.push(`provider detail: ${cleanDetail.length > 300 ? `${cleanDetail.slice(0, 297)}...` : cleanDetail}`);
|
|
474
|
+
lines.push("");
|
|
475
|
+
lines.push("To keep using this provider:");
|
|
476
|
+
lines.push(` 1. Run \`ouro auth --agent ${agentName} --provider ${provider}\``);
|
|
477
|
+
if (mismatch) {
|
|
478
|
+
const defaultModel = (0, provider_models_1.getDefaultModelForProvider)(provider);
|
|
479
|
+
lines.push("");
|
|
480
|
+
lines.push("Config warning:");
|
|
481
|
+
lines.push(` - ${mismatch}`);
|
|
482
|
+
lines.push(" - Repair the configured model with:");
|
|
483
|
+
lines.push(` \`ouro config model --agent ${agentName} --facing human ${defaultModel}\``);
|
|
484
|
+
lines.push(` \`ouro config model --agent ${agentName} --facing agent ${defaultModel}\``);
|
|
485
|
+
}
|
|
486
|
+
lines.push("");
|
|
487
|
+
lines.push(`To use another configured provider instead, run \`ouro auth switch --agent ${agentName} --provider <provider>\`.`);
|
|
488
|
+
return lines.join("\n");
|
|
304
489
|
}
|
|
305
|
-
const MAX_RETRIES = 3;
|
|
306
|
-
const RETRY_BASE_MS = 2000;
|
|
307
490
|
async function runAgent(messages, callbacks, channel, signal, options) {
|
|
308
|
-
const
|
|
491
|
+
const facing = (0, channel_1.channelToFacing)(channel);
|
|
492
|
+
let providerRuntime = await getProviderRuntime(facing);
|
|
309
493
|
const provider = providerRuntime.id;
|
|
310
494
|
const toolChoiceRequired = options?.toolChoiceRequired ?? true;
|
|
311
495
|
const traceId = options?.traceId;
|
|
@@ -329,10 +513,17 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
329
513
|
// Refresh system prompt at start of each turn when channel is provided.
|
|
330
514
|
// If refresh fails, keep existing system prompt (or inject a minimal safe fallback)
|
|
331
515
|
// so turn execution remains consistent and non-fatal.
|
|
516
|
+
let structuredSystemPrompt;
|
|
332
517
|
if (channel) {
|
|
333
518
|
try {
|
|
334
|
-
const
|
|
335
|
-
|
|
519
|
+
const buildSystemOptions = {
|
|
520
|
+
...options,
|
|
521
|
+
providerCapabilities: providerRuntime.capabilities,
|
|
522
|
+
supportedReasoningEfforts: providerRuntime.supportedReasoningEfforts,
|
|
523
|
+
};
|
|
524
|
+
const refreshed = await (0, prompt_1.buildSystem)(channel, buildSystemOptions, currentContext);
|
|
525
|
+
structuredSystemPrompt = refreshed;
|
|
526
|
+
upsertSystemPrompt(messages, (0, prompt_1.flattenSystemPrompt)(refreshed));
|
|
336
527
|
}
|
|
337
528
|
catch (error) {
|
|
338
529
|
const hadExistingSystemPrompt = messages[0]?.role === "system" && typeof messages[0].content === "string";
|
|
@@ -353,30 +544,115 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
353
544
|
});
|
|
354
545
|
}
|
|
355
546
|
}
|
|
356
|
-
|
|
547
|
+
if (channel) {
|
|
548
|
+
await (0, kept_notes_1.injectKeptNotes)(messages, {
|
|
549
|
+
channel,
|
|
550
|
+
friend: currentContext?.friend,
|
|
551
|
+
judge: async (input) => (0, kept_notes_1.createKeptNotesJudge)(await getProviderRuntime("agent"), signal)(input),
|
|
552
|
+
signal,
|
|
553
|
+
traceId,
|
|
554
|
+
});
|
|
555
|
+
}
|
|
357
556
|
let done = false;
|
|
358
557
|
let lastUsage;
|
|
359
558
|
let overflowRetried = false;
|
|
360
|
-
let
|
|
361
|
-
let
|
|
559
|
+
let outcome = "settled";
|
|
560
|
+
let completion;
|
|
561
|
+
let terminalError;
|
|
562
|
+
let terminalErrorClassification;
|
|
362
563
|
let sawSteeringFollowUp = false;
|
|
363
564
|
let mustResolveBeforeHandoffActive = options?.mustResolveBeforeHandoff === true;
|
|
565
|
+
let currentReasoningEffort = "medium";
|
|
566
|
+
let sawSendMessageSelf = false;
|
|
567
|
+
let sawPonder = false;
|
|
568
|
+
let sawQuerySession = false;
|
|
569
|
+
let sawBridgeManage = false;
|
|
570
|
+
let sawExternalStateQuery = false;
|
|
571
|
+
// Once-per-turn flag for the fresh-work rest gate. Without this, an agent
|
|
572
|
+
// that called rest, was told "fresh work arrived", processed the items,
|
|
573
|
+
// and called rest again would get the same message forever — the gate
|
|
574
|
+
// condition is read from the turn-start snapshot of pendingMessages,
|
|
575
|
+
// which doesn't update mid-turn. The agent only needs to be told once;
|
|
576
|
+
// after that, repeated rest attempts mean they've acknowledged.
|
|
577
|
+
let freshWorkGateFired = false;
|
|
578
|
+
// Counter for "no tool call returned despite tool_choice=required" violations.
|
|
579
|
+
// MiniMax reasoning models occasionally emit only a <think>...</think>
|
|
580
|
+
// block and stop, without any tool call — even when tool_choice is set to
|
|
581
|
+
// "required". This is a provider-level violation; the harness retries with
|
|
582
|
+
// a corrective nudge up to a small cap rather than silently accepting an
|
|
583
|
+
// empty turn.
|
|
584
|
+
let noToolCallRetries = 0;
|
|
585
|
+
const NO_TOOL_CALL_MAX_RETRIES = 2;
|
|
586
|
+
const toolLoopState = (0, tool_loop_1.createToolLoopState)();
|
|
587
|
+
const toolFrictionLedger = (0, tool_friction_1.createToolFrictionLedger)();
|
|
588
|
+
const finishTerminalProviderError = (error, classification) => {
|
|
589
|
+
terminalError = error;
|
|
590
|
+
terminalErrorClassification = classification;
|
|
591
|
+
/* v8 ignore start — auth-failure guidance: tested via provider error classification tests @preserve */
|
|
592
|
+
if (terminalErrorClassification === "auth-failure") {
|
|
593
|
+
const agentName = (0, identity_2.getAgentName)();
|
|
594
|
+
const currentProvider = providerRuntime.id;
|
|
595
|
+
callbacks.onError(new Error(buildAuthFailureGuidance(currentProvider, providerRuntime.model, agentName, terminalError.message)), "terminal");
|
|
596
|
+
}
|
|
597
|
+
else {
|
|
598
|
+
callbacks.onError(terminalError, "terminal");
|
|
599
|
+
}
|
|
600
|
+
/* v8 ignore stop */
|
|
601
|
+
(0, runtime_1.emitNervesEvent)({
|
|
602
|
+
level: "error",
|
|
603
|
+
event: "engine.error",
|
|
604
|
+
trace_id: traceId,
|
|
605
|
+
component: "engine",
|
|
606
|
+
message: terminalError.message,
|
|
607
|
+
meta: {
|
|
608
|
+
provider: providerRuntime.id,
|
|
609
|
+
model: providerRuntime.model,
|
|
610
|
+
errorClassification: terminalErrorClassification,
|
|
611
|
+
},
|
|
612
|
+
});
|
|
613
|
+
stripLastToolCalls(messages);
|
|
614
|
+
outcome = "errored";
|
|
615
|
+
done = true;
|
|
616
|
+
};
|
|
364
617
|
// Prevent MaxListenersExceeded warning — each iteration adds a listener
|
|
365
618
|
try {
|
|
366
619
|
require("events").setMaxListeners(50, signal);
|
|
367
620
|
}
|
|
368
621
|
catch { /* unsupported */ }
|
|
369
622
|
const toolPreferences = currentContext?.friend?.toolPreferences;
|
|
370
|
-
const baseTools = options?.tools ?? (0, tools_1.getToolsForChannel)(channel ? (0, channel_1.getChannelCapabilities)(channel) : undefined, toolPreferences && Object.keys(toolPreferences).length > 0 ? toolPreferences : undefined, currentContext);
|
|
623
|
+
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);
|
|
624
|
+
// Augment tool context with reasoning effort controls from provider
|
|
625
|
+
const augmentedToolContext = options?.toolContext
|
|
626
|
+
? {
|
|
627
|
+
...options.toolContext,
|
|
628
|
+
supportedReasoningEfforts: providerRuntime.supportedReasoningEfforts,
|
|
629
|
+
setReasoningEffort: (level) => { currentReasoningEffort = level; },
|
|
630
|
+
activeWorkFrame: options?.activeWorkFrame,
|
|
631
|
+
}
|
|
632
|
+
: undefined;
|
|
371
633
|
// Rebase provider-owned turn state from canonical messages at user-turn start.
|
|
372
634
|
// This prevents stale provider caches from replaying prior-turn context.
|
|
373
635
|
providerRuntime.resetTurnState(messages);
|
|
374
636
|
while (!done) {
|
|
375
|
-
//
|
|
376
|
-
//
|
|
377
|
-
//
|
|
378
|
-
//
|
|
379
|
-
|
|
637
|
+
// Channel-based tool filtering:
|
|
638
|
+
// - Inner dialog: exclude send_message (delivery via surface), observe (no one to observe)
|
|
639
|
+
// - All outward channels (1:1, group, reaction): observe available
|
|
640
|
+
//
|
|
641
|
+
// ponder, settle/rest, surface, and observe are always assembled based on channel context.
|
|
642
|
+
// ponder is available in ALL channels (outer: think privately, inner: keep turning).
|
|
643
|
+
// Inner dialog gets restTool instead of settleTool (rest = end turn, gated by attention queue).
|
|
644
|
+
// toolChoiceRequired only controls whether tool_choice: "required" is set in the API call.
|
|
645
|
+
const isInnerDialog = channel === "inner";
|
|
646
|
+
const filteredBaseTools = isInnerDialog
|
|
647
|
+
? baseTools.filter((t) => t.function.name !== "send_message")
|
|
648
|
+
: baseTools;
|
|
649
|
+
const activeTools = [
|
|
650
|
+
...filteredBaseTools,
|
|
651
|
+
tools_1.ponderTool,
|
|
652
|
+
...(isInnerDialog ? [tools_2.surfaceToolDef, tools_1.restTool] : []),
|
|
653
|
+
...(!isInnerDialog ? [tools_1.observeTool] : []),
|
|
654
|
+
...(!isInnerDialog ? [tools_1.settleTool] : []),
|
|
655
|
+
];
|
|
380
656
|
const steeringFollowUps = options?.drainSteeringFollowUps?.() ?? [];
|
|
381
657
|
if (steeringFollowUps.length > 0) {
|
|
382
658
|
const hasSupersedingFollowUp = steeringFollowUps.some((followUp) => followUp.effect === "clear_and_supersede");
|
|
@@ -403,19 +679,87 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
403
679
|
break;
|
|
404
680
|
}
|
|
405
681
|
try {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
682
|
+
const callProviderTurn = async () => {
|
|
683
|
+
callbacks.onModelStart();
|
|
684
|
+
try {
|
|
685
|
+
return await providerRuntime.streamTurn({
|
|
686
|
+
messages,
|
|
687
|
+
activeTools,
|
|
688
|
+
callbacks,
|
|
689
|
+
signal,
|
|
690
|
+
traceId,
|
|
691
|
+
toolChoiceRequired,
|
|
692
|
+
reasoningEffort: currentReasoningEffort,
|
|
693
|
+
eagerSettleStreaming: true,
|
|
694
|
+
systemPrompt: structuredSystemPrompt,
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
catch (error) {
|
|
698
|
+
if (signal?.aborted)
|
|
699
|
+
throw new provider_attempt_1.ProviderAttemptAbortError();
|
|
700
|
+
throw error;
|
|
701
|
+
}
|
|
702
|
+
};
|
|
703
|
+
const callProviderTurnWithOverflowRecovery = async () => {
|
|
704
|
+
try {
|
|
705
|
+
return await callProviderTurn();
|
|
706
|
+
}
|
|
707
|
+
catch (error) {
|
|
708
|
+
if (error instanceof provider_attempt_1.ProviderAttemptAbortError)
|
|
709
|
+
throw error;
|
|
710
|
+
if (isContextOverflow(error) && !overflowRetried) {
|
|
711
|
+
overflowRetried = true;
|
|
712
|
+
stripLastToolCalls(messages);
|
|
713
|
+
const { maxTokens, contextMargin } = (0, config_1.getContextConfig)();
|
|
714
|
+
const trimmed = (0, context_1.trimMessages)(messages, maxTokens, contextMargin, maxTokens * 2);
|
|
715
|
+
messages.splice(0, messages.length, ...trimmed);
|
|
716
|
+
providerRuntime.resetTurnState(messages);
|
|
717
|
+
callbacks.onError(new Error("context trimmed, retrying..."), "transient");
|
|
718
|
+
return callProviderTurn();
|
|
719
|
+
}
|
|
720
|
+
throw error;
|
|
721
|
+
}
|
|
722
|
+
};
|
|
723
|
+
const attempt = await (0, provider_attempt_1.runProviderAttempt)({
|
|
724
|
+
operation: "turn",
|
|
725
|
+
provider: providerRuntime.id,
|
|
726
|
+
model: providerRuntime.model,
|
|
727
|
+
run: callProviderTurnWithOverflowRecovery,
|
|
728
|
+
classifyError: (error) => providerRuntime.classifyError(error),
|
|
729
|
+
onRetry: async (record, maxAttempts) => {
|
|
730
|
+
const delayMs = record.delayMs;
|
|
731
|
+
const seconds = delayMs / 1000;
|
|
732
|
+
const cause = RETRY_LABELS[record.classification];
|
|
733
|
+
try {
|
|
734
|
+
await (0, provider_credentials_1.refreshProviderCredentialPool)((0, identity_2.getAgentName)(), { preserveCachedOnFailure: true });
|
|
735
|
+
_providerRuntimes[facing] = null;
|
|
736
|
+
providerRuntime = await getProviderRuntime(facing);
|
|
737
|
+
providerRuntime.resetTurnState(messages);
|
|
738
|
+
}
|
|
739
|
+
catch (refreshError) {
|
|
740
|
+
(0, runtime_1.emitNervesEvent)({
|
|
741
|
+
level: "warn",
|
|
742
|
+
component: "engine",
|
|
743
|
+
event: "engine.provider_retry_refresh_failed",
|
|
744
|
+
message: "provider credential refresh failed during retry",
|
|
745
|
+
meta: { provider: record.provider, model: record.model, reason: refreshError instanceof Error ? refreshError.message : String(refreshError) },
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
callbacks.onError(new Error(`${cause}, retrying in ${seconds}s (${record.attempt}/${maxAttempts})...`), "transient");
|
|
749
|
+
},
|
|
750
|
+
sleep: async (delayMs) => {
|
|
751
|
+
await waitForProviderRetry(delayMs, signal);
|
|
752
|
+
providerRuntime.resetTurnState(messages);
|
|
753
|
+
},
|
|
414
754
|
});
|
|
755
|
+
if (!attempt.ok) {
|
|
756
|
+
finishTerminalProviderError(attempt.error, attempt.classification);
|
|
757
|
+
continue;
|
|
758
|
+
}
|
|
759
|
+
const result = attempt.value;
|
|
415
760
|
// Track usage from the latest API call
|
|
416
761
|
if (result.usage)
|
|
417
762
|
lastUsage = result.usage;
|
|
418
|
-
retryCount = 0; // reset on success
|
|
419
763
|
// SHARED: build CC-format assistant message from TurnResult
|
|
420
764
|
const msg = {
|
|
421
765
|
role: "assistant",
|
|
@@ -434,28 +778,115 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
434
778
|
if (reasoningItems.length > 0) {
|
|
435
779
|
msg._reasoning_items = reasoningItems;
|
|
436
780
|
}
|
|
781
|
+
// Store thinking blocks (Anthropic) on the assistant message for round-tripping
|
|
782
|
+
const thinkingItems = result.outputItems.filter((item) => "type" in item && (item.type === "thinking" || item.type === "redacted_thinking"));
|
|
783
|
+
if (thinkingItems.length > 0) {
|
|
784
|
+
msg._thinking_blocks = thinkingItems;
|
|
785
|
+
}
|
|
786
|
+
// Phase annotation for Codex provider
|
|
787
|
+
const hasPhaseAnnotation = providerRuntime.capabilities.has("phase-annotation");
|
|
788
|
+
const isSoleSettle = result.toolCalls.length === 1 && result.toolCalls[0].name === "settle";
|
|
789
|
+
if (hasPhaseAnnotation) {
|
|
790
|
+
msg.phase = isSoleSettle ? "settle" : "commentary";
|
|
791
|
+
}
|
|
792
|
+
// Detect the MiniMax "only-thinking, no tool call" violation: no tool
|
|
793
|
+
// calls returned, and the content is empty after stripping
|
|
794
|
+
// <think>...</think> blocks. This is a narrow check — legitimate
|
|
795
|
+
// content-only responses (text without think tags, or text outside
|
|
796
|
+
// think tags) still flow through the original "no tool calls →
|
|
797
|
+
// accept as-is" path so existing channels and tests are unaffected.
|
|
798
|
+
const onlyThinkContent = !result.toolCalls.length
|
|
799
|
+
&& typeof result.content === "string"
|
|
800
|
+
&& stripThinkBlocksForViolationCheck(result.content).length === 0
|
|
801
|
+
&& result.content.length > 0;
|
|
437
802
|
if (!result.toolCalls.length) {
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
803
|
+
if (onlyThinkContent && toolChoiceRequired && noToolCallRetries < NO_TOOL_CALL_MAX_RETRIES) {
|
|
804
|
+
// Provider-level violation: tool_choice was required, model emitted
|
|
805
|
+
// only a <think>...</think> block (or empty content) with no tool
|
|
806
|
+
// call. Retry with a corrective nudge up to NO_TOOL_CALL_MAX_RETRIES
|
|
807
|
+
// times. After cap, accept as-is (the readback path strips think
|
|
808
|
+
// tags and surfaces a clear diagnostic).
|
|
809
|
+
noToolCallRetries++;
|
|
810
|
+
(0, runtime_1.emitNervesEvent)({
|
|
811
|
+
level: "warn",
|
|
812
|
+
component: "engine",
|
|
813
|
+
event: "engine.no_tool_call_retry",
|
|
814
|
+
message: "model returned only <think> content with no tool call despite tool_choice=required; retrying with corrective nudge",
|
|
815
|
+
meta: {
|
|
816
|
+
attempt: noToolCallRetries,
|
|
817
|
+
cap: NO_TOOL_CALL_MAX_RETRIES,
|
|
818
|
+
provider: providerRuntime.id,
|
|
819
|
+
model: providerRuntime.model,
|
|
820
|
+
contentLength: result.content.length,
|
|
821
|
+
},
|
|
822
|
+
});
|
|
823
|
+
messages.push(msg);
|
|
824
|
+
messages.push({
|
|
825
|
+
role: "user",
|
|
826
|
+
content: isInnerDialog
|
|
827
|
+
? "no tool was called this turn. you must end every turn by calling rest (or surface, ponder, observe). emit the tool call now."
|
|
828
|
+
: "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.",
|
|
829
|
+
});
|
|
830
|
+
continue;
|
|
831
|
+
}
|
|
832
|
+
// Legitimate text-only response, or cap reached — accept as-is.
|
|
441
833
|
messages.push(msg);
|
|
442
834
|
done = true;
|
|
443
835
|
}
|
|
444
836
|
else {
|
|
445
|
-
//
|
|
446
|
-
|
|
447
|
-
|
|
837
|
+
// Reset the retry counter on any successful tool call.
|
|
838
|
+
noToolCallRetries = 0;
|
|
839
|
+
// Check for settle sole call: intercept before tool execution
|
|
840
|
+
if (isSoleSettle) {
|
|
841
|
+
/* v8 ignore next -- defensive: JSON.parse catch for malformed settle args @preserve */
|
|
842
|
+
const settleArgs = (() => { try {
|
|
843
|
+
return JSON.parse(result.toolCalls[0].arguments);
|
|
844
|
+
}
|
|
845
|
+
catch {
|
|
846
|
+
return {};
|
|
847
|
+
} })();
|
|
848
|
+
callbacks.onToolStart("settle", settleArgs);
|
|
849
|
+
// Inner dialog attention queue gate: reject settle if items remain
|
|
850
|
+
const attentionQueue = (augmentedToolContext ?? options?.toolContext)?.delegatedOrigins;
|
|
851
|
+
if (isInnerDialog && attentionQueue && attentionQueue.length > 0) {
|
|
852
|
+
callbacks.onToolEnd("settle", (0, tools_1.summarizeArgs)("settle", settleArgs), false);
|
|
853
|
+
callbacks.onClearText?.();
|
|
854
|
+
messages.push(msg);
|
|
855
|
+
const gateMessage = "you're holding thoughts someone is waiting for — surface them before you settle.";
|
|
856
|
+
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: gateMessage });
|
|
857
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, gateMessage);
|
|
858
|
+
continue;
|
|
859
|
+
}
|
|
448
860
|
// Extract answer from the tool call arguments.
|
|
449
861
|
// Supports: {"answer":"text","intent":"..."} or "text" (JSON string).
|
|
450
|
-
const { answer, intent } =
|
|
862
|
+
const { answer, intent } = parseSettlePayload(result.toolCalls[0].arguments);
|
|
863
|
+
// Inner dialog settle: no CompletionMetadata, "(settled)" ack
|
|
864
|
+
if (isInnerDialog) {
|
|
865
|
+
callbacks.onToolEnd("settle", (0, tools_1.summarizeArgs)("settle", settleArgs), true);
|
|
866
|
+
messages.push(msg);
|
|
867
|
+
const settled = "(settled)";
|
|
868
|
+
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: settled });
|
|
869
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, settled);
|
|
870
|
+
outcome = "settled";
|
|
871
|
+
done = true;
|
|
872
|
+
continue;
|
|
873
|
+
}
|
|
874
|
+
const retryError = getSettleRetryError(mustResolveBeforeHandoffActive, intent, sawSteeringFollowUp, options?.delegationDecision, sawSendMessageSelf, sawPonder, sawQuerySession, options?.currentObligation ?? null, options?.activeWorkFrame?.inner?.job, sawExternalStateQuery);
|
|
875
|
+
const deliveredAnswer = answer;
|
|
451
876
|
const validDirectReply = mustResolveBeforeHandoffActive && intent === "direct_reply" && sawSteeringFollowUp;
|
|
452
877
|
const validTerminalIntent = intent === "complete" || intent === "blocked";
|
|
453
|
-
const validClosure =
|
|
878
|
+
const validClosure = deliveredAnswer != null
|
|
879
|
+
&& !retryError
|
|
454
880
|
&& (!mustResolveBeforeHandoffActive || validDirectReply || validTerminalIntent);
|
|
455
881
|
if (validClosure) {
|
|
456
|
-
|
|
882
|
+
callbacks.onToolEnd("settle", (0, tools_1.summarizeArgs)("settle", settleArgs), true);
|
|
883
|
+
completion = {
|
|
884
|
+
answer: deliveredAnswer,
|
|
885
|
+
intent: validDirectReply ? "direct_reply" : intent === "blocked" ? "blocked" : "complete",
|
|
886
|
+
};
|
|
887
|
+
if (result.settleStreamed) {
|
|
457
888
|
// The streaming layer already parsed and emitted the answer
|
|
458
|
-
// progressively via
|
|
889
|
+
// progressively via SettleParser. Skip clearing and
|
|
459
890
|
// re-emitting to avoid double-delivery.
|
|
460
891
|
}
|
|
461
892
|
else {
|
|
@@ -463,7 +894,7 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
463
894
|
callbacks.onClearText?.();
|
|
464
895
|
// Emit the answer through the callback pipeline so channels receive it.
|
|
465
896
|
// Never truncate -- channel adapters handle splitting long messages.
|
|
466
|
-
callbacks.onTextChunk(
|
|
897
|
+
callbacks.onTextChunk(deliveredAnswer);
|
|
467
898
|
}
|
|
468
899
|
messages.push(msg);
|
|
469
900
|
if (validDirectReply) {
|
|
@@ -475,32 +906,114 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
475
906
|
const delivered = "(delivered)";
|
|
476
907
|
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: delivered });
|
|
477
908
|
providerRuntime.appendToolOutput(result.toolCalls[0].id, delivered);
|
|
478
|
-
outcome = intent === "blocked" ? "blocked" : "
|
|
909
|
+
outcome = intent === "blocked" ? "blocked" : "settled";
|
|
479
910
|
done = true;
|
|
480
911
|
}
|
|
481
912
|
}
|
|
482
913
|
else {
|
|
483
|
-
// Answer is undefined -- the model's
|
|
914
|
+
// Answer is undefined -- the model's settle was incomplete or
|
|
484
915
|
// malformed. Clear any partial streamed text or noise, then push the
|
|
485
916
|
// assistant msg + error tool result and let the model try again.
|
|
917
|
+
callbacks.onToolEnd("settle", (0, tools_1.summarizeArgs)("settle", settleArgs), false);
|
|
486
918
|
callbacks.onClearText?.();
|
|
487
|
-
const retryError = getFinalAnswerRetryError(mustResolveBeforeHandoffActive, intent, sawSteeringFollowUp);
|
|
488
919
|
messages.push(msg);
|
|
489
|
-
|
|
490
|
-
|
|
920
|
+
const toolRetryMessage = retryError
|
|
921
|
+
?? "your settle was incomplete or malformed. call settle again with your complete response.";
|
|
922
|
+
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: toolRetryMessage });
|
|
923
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, toolRetryMessage);
|
|
924
|
+
}
|
|
925
|
+
continue;
|
|
926
|
+
}
|
|
927
|
+
// Check for observe sole call: intercept before tool execution
|
|
928
|
+
const isSoleObserve = result.toolCalls.length === 1 && result.toolCalls[0].name === "observe";
|
|
929
|
+
if (isSoleObserve) {
|
|
930
|
+
/* v8 ignore next -- defensive: JSON.parse catch for malformed observe args @preserve */
|
|
931
|
+
const observeArgs = (() => { try {
|
|
932
|
+
return JSON.parse(result.toolCalls[0].arguments);
|
|
933
|
+
}
|
|
934
|
+
catch {
|
|
935
|
+
return {};
|
|
936
|
+
} })();
|
|
937
|
+
let reason;
|
|
938
|
+
if (typeof observeArgs?.reason === "string")
|
|
939
|
+
reason = observeArgs.reason;
|
|
940
|
+
callbacks.onToolStart("observe", observeArgs);
|
|
941
|
+
(0, runtime_1.emitNervesEvent)({
|
|
942
|
+
component: "engine",
|
|
943
|
+
event: "engine.observe",
|
|
944
|
+
message: "agent observed without responding",
|
|
945
|
+
meta: { ...(reason ? { reason } : {}) },
|
|
946
|
+
});
|
|
947
|
+
callbacks.onToolEnd("observe", (0, tools_1.summarizeArgs)("observe", observeArgs), true);
|
|
948
|
+
messages.push(msg);
|
|
949
|
+
const silenced = "(silenced)";
|
|
950
|
+
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: silenced });
|
|
951
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, silenced);
|
|
952
|
+
outcome = "observed";
|
|
953
|
+
done = true;
|
|
954
|
+
continue;
|
|
955
|
+
}
|
|
956
|
+
// Check for rest sole call: intercept before tool execution
|
|
957
|
+
const isSoleRest = result.toolCalls.length === 1 && result.toolCalls[0].name === "rest";
|
|
958
|
+
if (isSoleRest) {
|
|
959
|
+
const restArgs = (() => { try {
|
|
960
|
+
return JSON.parse(result.toolCalls[0].arguments);
|
|
961
|
+
}
|
|
962
|
+
catch {
|
|
963
|
+
return {};
|
|
964
|
+
} })();
|
|
965
|
+
callbacks.onToolStart("rest", restArgs);
|
|
966
|
+
// Attention queue gate: reject rest if items remain
|
|
967
|
+
const attentionQueue = (augmentedToolContext ?? options?.toolContext)?.delegatedOrigins;
|
|
968
|
+
if (attentionQueue && attentionQueue.length > 0) {
|
|
969
|
+
callbacks.onToolEnd("rest", (0, tools_1.summarizeArgs)("rest", restArgs), false);
|
|
970
|
+
messages.push(msg);
|
|
971
|
+
const gateMessage = "you're holding thoughts someone is waiting for — surface them before you rest.";
|
|
972
|
+
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: gateMessage });
|
|
973
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, gateMessage);
|
|
974
|
+
continue;
|
|
491
975
|
}
|
|
976
|
+
if (hasFreshPendingWork(options) && !freshWorkGateFired) {
|
|
977
|
+
freshWorkGateFired = true;
|
|
978
|
+
callbacks.onToolEnd("rest", (0, tools_1.summarizeArgs)("rest", restArgs), false);
|
|
979
|
+
messages.push(msg);
|
|
980
|
+
const gateMessage = "fresh work arrived for me this turn — inspect the pending messages above and take the next concrete action before you rest.";
|
|
981
|
+
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: gateMessage });
|
|
982
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, gateMessage);
|
|
983
|
+
(0, runtime_1.emitNervesEvent)({
|
|
984
|
+
level: "info",
|
|
985
|
+
component: "engine",
|
|
986
|
+
event: "engine.fresh_work_gate_fired",
|
|
987
|
+
message: "rest deferred once because pending work arrived this turn; agent has been notified",
|
|
988
|
+
meta: { pendingCount: options.pendingMessages.length },
|
|
989
|
+
});
|
|
990
|
+
continue;
|
|
991
|
+
}
|
|
992
|
+
callbacks.onToolEnd("rest", (0, tools_1.summarizeArgs)("rest", restArgs), true);
|
|
993
|
+
messages.push(msg);
|
|
994
|
+
const ack = "(resting)";
|
|
995
|
+
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: ack });
|
|
996
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, ack);
|
|
997
|
+
(0, runtime_1.emitNervesEvent)({
|
|
998
|
+
component: "engine",
|
|
999
|
+
event: "engine.rested",
|
|
1000
|
+
message: "resting until next heartbeat",
|
|
1001
|
+
meta: { ...(typeof restArgs?.status === "string" ? { status: restArgs.status } : {}) },
|
|
1002
|
+
});
|
|
1003
|
+
outcome = "rested";
|
|
1004
|
+
done = true;
|
|
492
1005
|
continue;
|
|
493
1006
|
}
|
|
494
1007
|
messages.push(msg);
|
|
495
|
-
//
|
|
1008
|
+
// Execute tools (sole-call tools in mixed calls are rejected inline)
|
|
496
1009
|
for (const tc of result.toolCalls) {
|
|
497
1010
|
if (signal?.aborted)
|
|
498
1011
|
break;
|
|
499
|
-
//
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
messages.push({ role: "tool", tool_call_id: tc.id, content:
|
|
503
|
-
providerRuntime.appendToolOutput(tc.id,
|
|
1012
|
+
// Reject sole-call tools when mixed with other tool calls
|
|
1013
|
+
const soleCallRejection = SOLE_CALL_REJECTION[tc.name];
|
|
1014
|
+
if (soleCallRejection) {
|
|
1015
|
+
messages.push({ role: "tool", tool_call_id: tc.id, content: soleCallRejection });
|
|
1016
|
+
providerRuntime.appendToolOutput(tc.id, soleCallRejection);
|
|
504
1017
|
continue;
|
|
505
1018
|
}
|
|
506
1019
|
let args = {};
|
|
@@ -510,97 +1023,195 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
510
1023
|
catch {
|
|
511
1024
|
/* ignore */
|
|
512
1025
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
1026
|
+
if (tc.name === "send_message" && args.friendId === "self") {
|
|
1027
|
+
sawSendMessageSelf = true;
|
|
1028
|
+
}
|
|
1029
|
+
if (tc.name === "ponder") {
|
|
1030
|
+
const parsedArgs = normalizeLegacyPonderArgs(parsePonderPayload(tc.arguments));
|
|
1031
|
+
const argSummary = (0, tools_1.summarizeArgs)(tc.name, parsedArgs);
|
|
1032
|
+
callbacks.onToolStart(tc.name, parsedArgs);
|
|
1033
|
+
let toolResult;
|
|
1034
|
+
let success = false;
|
|
1035
|
+
try {
|
|
1036
|
+
const action = parsedArgs.action ?? "create";
|
|
1037
|
+
const currentSession = (augmentedToolContext ?? options?.toolContext)?.currentSession;
|
|
1038
|
+
const currentOrigin = currentSession
|
|
1039
|
+
? { friendId: currentSession.friendId, channel: currentSession.channel, key: currentSession.key }
|
|
1040
|
+
: undefined;
|
|
1041
|
+
const isInnerChannel = currentOrigin?.friendId === "self" && currentOrigin?.channel === "inner";
|
|
1042
|
+
const successCriteria = parseSuccessCriteria(parsedArgs.success_criteria);
|
|
1043
|
+
const payload = parsePacketPayload(parsedArgs.payload_json);
|
|
1044
|
+
let packet;
|
|
1045
|
+
let returnObligationId = null;
|
|
1046
|
+
let resultAction = "created";
|
|
1047
|
+
if (action === "create") {
|
|
1048
|
+
const kind = parsedArgs.kind;
|
|
1049
|
+
const objective = typeof parsedArgs.objective === "string" ? parsedArgs.objective.trim() : "";
|
|
1050
|
+
const summary = typeof parsedArgs.summary === "string" ? parsedArgs.summary.trim() : "";
|
|
1051
|
+
if (!kind || !objective || !successCriteria || !payload) {
|
|
1052
|
+
throw new Error("ponder create requires kind, objective, success_criteria, and valid payload_json.");
|
|
1053
|
+
}
|
|
1054
|
+
const agentRoot = (0, identity_2.getAgentRoot)();
|
|
1055
|
+
let relatedObligationId;
|
|
1056
|
+
if (currentOrigin && !isInnerChannel) {
|
|
1057
|
+
try {
|
|
1058
|
+
const obligation = (0, obligations_1.createObligation)(agentRoot, {
|
|
1059
|
+
origin: currentOrigin,
|
|
1060
|
+
content: objective,
|
|
1061
|
+
});
|
|
1062
|
+
relatedObligationId = obligation.id;
|
|
1063
|
+
}
|
|
1064
|
+
catch {
|
|
1065
|
+
relatedObligationId = undefined;
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
const frictionSignature = kind === "harness_friction" && typeof payload.frictionSignature === "string"
|
|
1069
|
+
? payload.frictionSignature
|
|
1070
|
+
: null;
|
|
1071
|
+
const existing = frictionSignature && currentOrigin
|
|
1072
|
+
? (0, packets_1.findHarnessFrictionPacket)(agentRoot, currentOrigin, frictionSignature)
|
|
1073
|
+
: null;
|
|
1074
|
+
if (existing) {
|
|
1075
|
+
resultAction = "revised";
|
|
1076
|
+
returnObligationId = existing.relatedReturnObligationId ?? null;
|
|
1077
|
+
packet = existing.status === "drafting"
|
|
1078
|
+
? (0, packets_1.revisePonderPacket)(agentRoot, existing.id, {
|
|
1079
|
+
kind,
|
|
1080
|
+
objective,
|
|
1081
|
+
summary,
|
|
1082
|
+
successCriteria,
|
|
1083
|
+
payload,
|
|
1084
|
+
})
|
|
1085
|
+
: existing;
|
|
1086
|
+
}
|
|
1087
|
+
else {
|
|
1088
|
+
returnObligationId = (0, obligations_1.generateObligationId)(Date.now());
|
|
1089
|
+
packet = (0, packets_1.createPonderPacket)(agentRoot, {
|
|
1090
|
+
kind,
|
|
1091
|
+
objective,
|
|
1092
|
+
summary,
|
|
1093
|
+
successCriteria,
|
|
1094
|
+
...(currentOrigin ? { origin: currentOrigin } : {}),
|
|
1095
|
+
...(relatedObligationId ? { relatedObligationId } : {}),
|
|
1096
|
+
relatedReturnObligationId: returnObligationId,
|
|
1097
|
+
...(parsedArgs.follows_packet_id ? { followsPacketId: parsedArgs.follows_packet_id } : {}),
|
|
1098
|
+
payload,
|
|
1099
|
+
});
|
|
1100
|
+
(0, obligations_1.createReturnObligation)((0, identity_2.getAgentName)(), {
|
|
1101
|
+
id: returnObligationId,
|
|
1102
|
+
origin: currentOrigin ?? { friendId: "self", channel: "inner", key: "dialog" },
|
|
1103
|
+
status: "queued",
|
|
1104
|
+
delegatedContent: (summary || objective).length > 120 ? `${(summary || objective).slice(0, 117)}...` : (summary || objective),
|
|
1105
|
+
packetId: packet.id,
|
|
1106
|
+
createdAt: Date.now(),
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
else if (action === "revise") {
|
|
1111
|
+
const packetId = typeof parsedArgs.packet_id === "string" ? parsedArgs.packet_id.trim() : "";
|
|
1112
|
+
const kind = parsedArgs.kind;
|
|
1113
|
+
const objective = typeof parsedArgs.objective === "string" ? parsedArgs.objective.trim() : "";
|
|
1114
|
+
const summary = typeof parsedArgs.summary === "string" ? parsedArgs.summary.trim() : "";
|
|
1115
|
+
if (!packetId || !kind || !objective || !successCriteria || !payload) {
|
|
1116
|
+
throw new Error("ponder revise requires packet_id, kind, objective, success_criteria, and valid payload_json.");
|
|
1117
|
+
}
|
|
1118
|
+
packet = (0, packets_1.revisePonderPacket)((0, identity_2.getAgentRoot)(), packetId, {
|
|
1119
|
+
kind,
|
|
1120
|
+
objective,
|
|
1121
|
+
summary,
|
|
1122
|
+
successCriteria,
|
|
1123
|
+
payload,
|
|
1124
|
+
});
|
|
1125
|
+
returnObligationId = packet.relatedReturnObligationId ?? null;
|
|
1126
|
+
resultAction = "revised";
|
|
1127
|
+
}
|
|
1128
|
+
else {
|
|
1129
|
+
throw new Error("ponder requires action=create or revise.");
|
|
1130
|
+
}
|
|
1131
|
+
try {
|
|
1132
|
+
await (0, socket_client_1.requestInnerWake)((0, identity_2.getAgentName)());
|
|
1133
|
+
}
|
|
1134
|
+
catch { /* daemon may not be running */ }
|
|
1135
|
+
sawPonder = true;
|
|
1136
|
+
toolResult = buildPonderResult(packet, resultAction, returnObligationId);
|
|
1137
|
+
success = true;
|
|
1138
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1139
|
+
component: "engine",
|
|
1140
|
+
event: "engine.ponder_packet",
|
|
1141
|
+
message: "ponder packet touched",
|
|
1142
|
+
meta: {
|
|
1143
|
+
action: resultAction,
|
|
1144
|
+
packetId: packet.id,
|
|
1145
|
+
kind: packet.kind,
|
|
1146
|
+
status: packet.status,
|
|
1147
|
+
},
|
|
1148
|
+
});
|
|
519
1149
|
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
callbacks.onToolStart(tc.name, args);
|
|
523
|
-
callbacks.onToolEnd(tc.name, argSummary, false);
|
|
524
|
-
messages.push({ role: "tool", tool_call_id: tc.id, content: cancelled });
|
|
525
|
-
providerRuntime.appendToolOutput(tc.id, cancelled);
|
|
526
|
-
continue;
|
|
1150
|
+
catch (error) {
|
|
1151
|
+
toolResult = error instanceof Error ? error.message : String(error);
|
|
527
1152
|
}
|
|
1153
|
+
callbacks.onToolEnd(tc.name, argSummary, success);
|
|
1154
|
+
messages.push({ role: "tool", tool_call_id: tc.id, content: toolResult });
|
|
1155
|
+
providerRuntime.appendToolOutput(tc.id, toolResult);
|
|
1156
|
+
continue;
|
|
1157
|
+
}
|
|
1158
|
+
/* v8 ignore next -- flag tested via truth-check integration tests @preserve */
|
|
1159
|
+
if (tc.name === "query_session")
|
|
1160
|
+
sawQuerySession = true;
|
|
1161
|
+
/* v8 ignore next -- flag tested via truth-check integration tests @preserve */
|
|
1162
|
+
if (tc.name === "bridge_manage")
|
|
1163
|
+
sawBridgeManage = true;
|
|
1164
|
+
/* v8 ignore next -- flag tested via truth-check integration tests @preserve */
|
|
1165
|
+
if (isExternalStateQuery(tc.name, args))
|
|
1166
|
+
sawExternalStateQuery = true;
|
|
1167
|
+
const argSummary = (0, tools_1.summarizeArgs)(tc.name, args);
|
|
1168
|
+
const toolLoop = (0, tool_loop_1.detectToolLoop)(toolLoopState, tc.name, args);
|
|
1169
|
+
if (toolLoop.stuck) {
|
|
1170
|
+
const rejection = `loop guard: ${toolLoop.message}`;
|
|
1171
|
+
callbacks.onToolStart(tc.name, args);
|
|
1172
|
+
callbacks.onToolEnd(tc.name, argSummary, false);
|
|
1173
|
+
messages.push({ role: "tool", tool_call_id: tc.id, content: rejection });
|
|
1174
|
+
providerRuntime.appendToolOutput(tc.id, rejection);
|
|
1175
|
+
continue;
|
|
528
1176
|
}
|
|
529
1177
|
callbacks.onToolStart(tc.name, args);
|
|
530
1178
|
let toolResult;
|
|
531
1179
|
let success;
|
|
532
1180
|
try {
|
|
533
1181
|
const execToolFn = options?.execTool ?? tools_1.execTool;
|
|
534
|
-
toolResult = await execToolFn(tc.name, args, options?.toolContext);
|
|
1182
|
+
toolResult = await execToolFn(tc.name, args, augmentedToolContext ?? options?.toolContext);
|
|
535
1183
|
success = true;
|
|
536
1184
|
}
|
|
537
1185
|
catch (e) {
|
|
538
1186
|
toolResult = `error: ${e}`;
|
|
539
1187
|
success = false;
|
|
540
1188
|
}
|
|
541
|
-
|
|
1189
|
+
toolResult = (0, tool_friction_1.rewriteToolResultForModel)(tc.name, toolResult, toolFrictionLedger);
|
|
1190
|
+
(0, tool_loop_1.recordToolOutcome)(toolLoopState, tc.name, args, toolResult, success);
|
|
1191
|
+
callbacks.onToolEnd(tc.name, (0, tools_1.buildToolResultSummary)(tc.name, args, toolResult, success), success);
|
|
542
1192
|
messages.push({ role: "tool", tool_call_id: tc.id, content: toolResult });
|
|
543
1193
|
providerRuntime.appendToolOutput(tc.id, toolResult);
|
|
1194
|
+
callbacks.onToolResult?.(messages);
|
|
544
1195
|
}
|
|
545
1196
|
}
|
|
546
1197
|
}
|
|
547
1198
|
catch (e) {
|
|
548
1199
|
// Abort is not an error — just stop cleanly
|
|
549
|
-
if (signal?.aborted) {
|
|
1200
|
+
if (e instanceof provider_attempt_1.ProviderAttemptAbortError || signal?.aborted) {
|
|
550
1201
|
stripLastToolCalls(messages);
|
|
551
1202
|
outcome = "aborted";
|
|
552
1203
|
break;
|
|
553
1204
|
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
const { maxTokens, contextMargin } = (0, config_1.getContextConfig)();
|
|
559
|
-
const trimmed = (0, context_1.trimMessages)(messages, maxTokens, contextMargin, maxTokens * 2);
|
|
560
|
-
messages.splice(0, messages.length, ...trimmed);
|
|
561
|
-
providerRuntime.resetTurnState(messages);
|
|
562
|
-
callbacks.onError(new Error("context trimmed, retrying..."), "transient");
|
|
563
|
-
continue;
|
|
1205
|
+
const errorForClassification = e instanceof Error ? e : /* v8 ignore next -- defensive @preserve */ new Error(String(e));
|
|
1206
|
+
let providerClassification;
|
|
1207
|
+
try {
|
|
1208
|
+
providerClassification = providerRuntime.classifyError(errorForClassification);
|
|
564
1209
|
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
const delay = RETRY_BASE_MS * Math.pow(2, retryCount - 1);
|
|
569
|
-
const cause = classifyTransientError(e);
|
|
570
|
-
callbacks.onError(new Error(`${cause}, retrying in ${delay / 1000}s (${retryCount}/${MAX_RETRIES})...`), "transient");
|
|
571
|
-
// Wait with abort support
|
|
572
|
-
const aborted = await new Promise((resolve) => {
|
|
573
|
-
const timer = setTimeout(() => resolve(false), delay);
|
|
574
|
-
if (signal) {
|
|
575
|
-
const onAbort = () => { clearTimeout(timer); resolve(true); };
|
|
576
|
-
if (signal.aborted) {
|
|
577
|
-
clearTimeout(timer);
|
|
578
|
-
resolve(true);
|
|
579
|
-
return;
|
|
580
|
-
}
|
|
581
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
582
|
-
}
|
|
583
|
-
});
|
|
584
|
-
if (aborted) {
|
|
585
|
-
stripLastToolCalls(messages);
|
|
586
|
-
outcome = "aborted";
|
|
587
|
-
break;
|
|
588
|
-
}
|
|
589
|
-
providerRuntime.resetTurnState(messages);
|
|
590
|
-
continue;
|
|
1210
|
+
catch {
|
|
1211
|
+
/* v8 ignore next -- defensive: classifyError should not throw @preserve */
|
|
1212
|
+
providerClassification = "unknown";
|
|
591
1213
|
}
|
|
592
|
-
|
|
593
|
-
(0, runtime_1.emitNervesEvent)({
|
|
594
|
-
level: "error",
|
|
595
|
-
event: "engine.error",
|
|
596
|
-
trace_id: traceId,
|
|
597
|
-
component: "engine",
|
|
598
|
-
message: e instanceof Error ? e.message : String(e),
|
|
599
|
-
meta: {},
|
|
600
|
-
});
|
|
601
|
-
stripLastToolCalls(messages);
|
|
602
|
-
outcome = "errored";
|
|
603
|
-
done = true;
|
|
1214
|
+
finishTerminalProviderError(errorForClassification, providerClassification);
|
|
604
1215
|
}
|
|
605
1216
|
}
|
|
606
1217
|
(0, runtime_1.emitNervesEvent)({
|
|
@@ -608,7 +1219,12 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
608
1219
|
trace_id: traceId,
|
|
609
1220
|
component: "engine",
|
|
610
1221
|
message: "runAgent turn completed",
|
|
611
|
-
meta: { done },
|
|
1222
|
+
meta: { done, sawPonder, sawQuerySession, sawBridgeManage },
|
|
612
1223
|
});
|
|
613
|
-
return {
|
|
1224
|
+
return {
|
|
1225
|
+
usage: lastUsage,
|
|
1226
|
+
outcome,
|
|
1227
|
+
completion,
|
|
1228
|
+
...(terminalError ? { error: terminalError, errorClassification: terminalErrorClassification } : {}),
|
|
1229
|
+
};
|
|
614
1230
|
}
|