@ouro.bot/cli 0.1.0-alpha.49 → 0.1.0-alpha.490
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 +3118 -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 +758 -227
- 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 +7229 -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 +280 -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 +205 -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,37 @@ 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
|
+
function hasFreshPendingWork(options) {
|
|
184
|
+
const pendingMessages = options?.pendingMessages;
|
|
185
|
+
if (!Array.isArray(pendingMessages))
|
|
186
|
+
return false;
|
|
187
|
+
return pendingMessages.some((message) => typeof message?.content === "string"
|
|
188
|
+
&& message.content.trim().length > 0);
|
|
113
189
|
}
|
|
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) {
|
|
190
|
+
// Sole-call tools must be the only tool call in a turn. When they appear
|
|
191
|
+
// alongside other tools, the sole-call tool is rejected with this message.
|
|
192
|
+
const SOLE_CALL_REJECTION = {
|
|
193
|
+
settle: "rejected: settle must be the only tool call. finish your work first, then call settle alone.",
|
|
194
|
+
observe: "rejected: observe must be the only tool call. call observe alone when you want to stay silent.",
|
|
195
|
+
rest: "rejected: rest must be the only tool call. finish your work first, then call rest alone.",
|
|
196
|
+
};
|
|
197
|
+
function parseSettlePayload(argumentsText) {
|
|
130
198
|
try {
|
|
131
199
|
const parsed = JSON.parse(argumentsText);
|
|
132
200
|
if (typeof parsed === "string") {
|
|
@@ -146,18 +214,93 @@ function parseFinalAnswerPayload(argumentsText) {
|
|
|
146
214
|
return {};
|
|
147
215
|
}
|
|
148
216
|
}
|
|
149
|
-
function
|
|
217
|
+
function parsePonderPayload(argumentsText) {
|
|
218
|
+
try {
|
|
219
|
+
const parsed = JSON.parse(argumentsText);
|
|
220
|
+
return parsed && typeof parsed === "object" ? parsed : {};
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
return {};
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function parseSuccessCriteria(raw) {
|
|
227
|
+
if (typeof raw !== "string")
|
|
228
|
+
return null;
|
|
229
|
+
const criteria = raw
|
|
230
|
+
.split("\n")
|
|
231
|
+
.map((line) => line.replace(/^\s*[-*]\s*/, "").trim())
|
|
232
|
+
.filter((line) => line.length > 0);
|
|
233
|
+
return criteria.length > 0 ? criteria : null;
|
|
234
|
+
}
|
|
235
|
+
function parsePacketPayload(raw) {
|
|
236
|
+
if (typeof raw !== "string")
|
|
237
|
+
return null;
|
|
238
|
+
try {
|
|
239
|
+
const parsed = JSON.parse(raw);
|
|
240
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed)
|
|
241
|
+
? parsed
|
|
242
|
+
: null;
|
|
243
|
+
}
|
|
244
|
+
catch {
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function normalizeLegacyPonderArgs(parsed) {
|
|
249
|
+
if (typeof parsed.thought !== "string" || parsed.thought.trim().length === 0) {
|
|
250
|
+
return parsed;
|
|
251
|
+
}
|
|
252
|
+
return {
|
|
253
|
+
action: "create",
|
|
254
|
+
kind: "reflection",
|
|
255
|
+
objective: parsed.thought.trim(),
|
|
256
|
+
summary: typeof parsed.say === "string" ? parsed.say.trim() : "",
|
|
257
|
+
success_criteria: "- preserve the thread for later work",
|
|
258
|
+
payload_json: "{}",
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
function buildPonderResult(packet, action, returnObligationId) {
|
|
262
|
+
return JSON.stringify({
|
|
263
|
+
ok: true,
|
|
264
|
+
packet_id: packet.id,
|
|
265
|
+
action,
|
|
266
|
+
status: packet.status,
|
|
267
|
+
return_obligation_id: returnObligationId,
|
|
268
|
+
}, null, 2);
|
|
269
|
+
}
|
|
270
|
+
/** Returns true when a tool call queries external state (GitHub, npm registry). */
|
|
271
|
+
function isExternalStateQuery(toolName, args) {
|
|
272
|
+
if (toolName !== "shell")
|
|
273
|
+
return false;
|
|
274
|
+
const cmd = String(args.command ?? "");
|
|
275
|
+
return /\bgh\s+(pr|run|api|issue)\b/.test(cmd) || /\bnpm\s+(view|info|show)\b/.test(cmd);
|
|
276
|
+
}
|
|
277
|
+
function getSettleRetryError(mustResolveBeforeHandoff, intent, sawSteeringFollowUp, _delegationDecision, sawSendMessageSelf, sawPonder, _sawQuerySession, currentObligation, innerJob, sawExternalStateQuery) {
|
|
278
|
+
// Delegation adherence removed: the delegation decision is surfaced in the
|
|
279
|
+
// system prompt as a suggestion. Hard-gating settle caused infinite
|
|
280
|
+
// rejection loops where the agent couldn't respond to the user at all.
|
|
281
|
+
// The agent is free to follow or ignore the delegation hint.
|
|
282
|
+
// 2. Pending obligation not addressed
|
|
283
|
+
if (innerJob?.obligationStatus === "pending" && !sawSendMessageSelf && !sawPonder) {
|
|
284
|
+
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.";
|
|
285
|
+
}
|
|
286
|
+
// 3. mustResolveBeforeHandoff + missing intent
|
|
150
287
|
if (mustResolveBeforeHandoff && !intent) {
|
|
151
|
-
return "your
|
|
288
|
+
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
289
|
}
|
|
290
|
+
// 4. mustResolveBeforeHandoff + direct_reply without follow-up
|
|
153
291
|
if (mustResolveBeforeHandoff && intent === "direct_reply" && !sawSteeringFollowUp) {
|
|
154
|
-
return "your
|
|
292
|
+
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.";
|
|
155
293
|
}
|
|
156
|
-
|
|
294
|
+
// 5. mustResolveBeforeHandoff + complete while a live return loop is still active
|
|
295
|
+
if (mustResolveBeforeHandoff && intent === "complete" && currentObligation && !sawSteeringFollowUp) {
|
|
296
|
+
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.";
|
|
297
|
+
}
|
|
298
|
+
// 6. External-state grounding: obligation + complete requires fresh external verification
|
|
299
|
+
if (intent === "complete" && currentObligation && !sawExternalStateQuery && !sawSteeringFollowUp) {
|
|
300
|
+
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.";
|
|
301
|
+
}
|
|
302
|
+
return null;
|
|
157
303
|
}
|
|
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
304
|
function upsertSystemPrompt(messages, systemText) {
|
|
162
305
|
const systemMessage = { role: "system", content: systemText };
|
|
163
306
|
if (messages[0]?.role === "system") {
|
|
@@ -263,49 +406,67 @@ function isContextOverflow(err) {
|
|
|
263
406
|
return true;
|
|
264
407
|
return false;
|
|
265
408
|
}
|
|
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
|
-
|
|
409
|
+
const RETRY_LABELS = {
|
|
410
|
+
"auth-failure": "auth error",
|
|
411
|
+
"usage-limit": "usage limit",
|
|
412
|
+
"rate-limit": "rate limited",
|
|
413
|
+
"server-error": "server error",
|
|
414
|
+
"network-error": "network error",
|
|
415
|
+
"unknown": "error",
|
|
416
|
+
};
|
|
417
|
+
function waitForProviderRetry(delayMs, signal) {
|
|
418
|
+
if (!signal) {
|
|
419
|
+
return new Promise((resolve) => {
|
|
420
|
+
setTimeout(resolve, delayMs);
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
return new Promise((resolve, reject) => {
|
|
424
|
+
let timer;
|
|
425
|
+
const onAbort = () => {
|
|
426
|
+
clearTimeout(timer);
|
|
427
|
+
reject(new provider_attempt_1.ProviderAttemptAbortError());
|
|
428
|
+
};
|
|
429
|
+
timer = setTimeout(() => {
|
|
430
|
+
signal.removeEventListener("abort", onAbort);
|
|
431
|
+
resolve();
|
|
432
|
+
}, delayMs);
|
|
433
|
+
if (signal.aborted) {
|
|
434
|
+
onAbort();
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
438
|
+
});
|
|
292
439
|
}
|
|
293
|
-
function
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
440
|
+
function buildAuthFailureGuidance(provider, model, agentName, detail) {
|
|
441
|
+
const mismatch = (0, provider_models_1.getProviderModelMismatchMessage)(provider, model);
|
|
442
|
+
const modelLabel = model
|
|
443
|
+
? mismatch
|
|
444
|
+
? `${provider} [configured model: ${model}]`
|
|
445
|
+
: `${provider} (${model})`
|
|
446
|
+
: provider;
|
|
447
|
+
const lines = [`${modelLabel} authentication failed.`];
|
|
448
|
+
const cleanDetail = detail.replace(/\s+/g, " ").trim();
|
|
449
|
+
if (cleanDetail)
|
|
450
|
+
lines.push(`provider detail: ${cleanDetail.length > 300 ? `${cleanDetail.slice(0, 297)}...` : cleanDetail}`);
|
|
451
|
+
lines.push("");
|
|
452
|
+
lines.push("To keep using this provider:");
|
|
453
|
+
lines.push(` 1. Run \`ouro auth --agent ${agentName} --provider ${provider}\``);
|
|
454
|
+
if (mismatch) {
|
|
455
|
+
const defaultModel = (0, provider_models_1.getDefaultModelForProvider)(provider);
|
|
456
|
+
lines.push("");
|
|
457
|
+
lines.push("Config warning:");
|
|
458
|
+
lines.push(` - ${mismatch}`);
|
|
459
|
+
lines.push(" - Repair the configured model with:");
|
|
460
|
+
lines.push(` \`ouro config model --agent ${agentName} --facing human ${defaultModel}\``);
|
|
461
|
+
lines.push(` \`ouro config model --agent ${agentName} --facing agent ${defaultModel}\``);
|
|
462
|
+
}
|
|
463
|
+
lines.push("");
|
|
464
|
+
lines.push(`To use another configured provider instead, run \`ouro auth switch --agent ${agentName} --provider <provider>\`.`);
|
|
465
|
+
return lines.join("\n");
|
|
304
466
|
}
|
|
305
|
-
const MAX_RETRIES = 3;
|
|
306
|
-
const RETRY_BASE_MS = 2000;
|
|
307
467
|
async function runAgent(messages, callbacks, channel, signal, options) {
|
|
308
|
-
const
|
|
468
|
+
const facing = (0, channel_1.channelToFacing)(channel);
|
|
469
|
+
let providerRuntime = await getProviderRuntime(facing);
|
|
309
470
|
const provider = providerRuntime.id;
|
|
310
471
|
const toolChoiceRequired = options?.toolChoiceRequired ?? true;
|
|
311
472
|
const traceId = options?.traceId;
|
|
@@ -329,10 +490,17 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
329
490
|
// Refresh system prompt at start of each turn when channel is provided.
|
|
330
491
|
// If refresh fails, keep existing system prompt (or inject a minimal safe fallback)
|
|
331
492
|
// so turn execution remains consistent and non-fatal.
|
|
493
|
+
let structuredSystemPrompt;
|
|
332
494
|
if (channel) {
|
|
333
495
|
try {
|
|
334
|
-
const
|
|
335
|
-
|
|
496
|
+
const buildSystemOptions = {
|
|
497
|
+
...options,
|
|
498
|
+
providerCapabilities: providerRuntime.capabilities,
|
|
499
|
+
supportedReasoningEfforts: providerRuntime.supportedReasoningEfforts,
|
|
500
|
+
};
|
|
501
|
+
const refreshed = await (0, prompt_1.buildSystem)(channel, buildSystemOptions, currentContext);
|
|
502
|
+
structuredSystemPrompt = refreshed;
|
|
503
|
+
upsertSystemPrompt(messages, (0, prompt_1.flattenSystemPrompt)(refreshed));
|
|
336
504
|
}
|
|
337
505
|
catch (error) {
|
|
338
506
|
const hadExistingSystemPrompt = messages[0]?.role === "system" && typeof messages[0].content === "string";
|
|
@@ -353,30 +521,100 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
353
521
|
});
|
|
354
522
|
}
|
|
355
523
|
}
|
|
356
|
-
|
|
524
|
+
if (channel) {
|
|
525
|
+
await (0, kept_notes_1.injectKeptNotes)(messages, {
|
|
526
|
+
channel,
|
|
527
|
+
friend: currentContext?.friend,
|
|
528
|
+
judge: async (input) => (0, kept_notes_1.createKeptNotesJudge)(await getProviderRuntime("agent"), signal)(input),
|
|
529
|
+
signal,
|
|
530
|
+
traceId,
|
|
531
|
+
});
|
|
532
|
+
}
|
|
357
533
|
let done = false;
|
|
358
534
|
let lastUsage;
|
|
359
535
|
let overflowRetried = false;
|
|
360
|
-
let
|
|
361
|
-
let
|
|
536
|
+
let outcome = "settled";
|
|
537
|
+
let completion;
|
|
538
|
+
let terminalError;
|
|
539
|
+
let terminalErrorClassification;
|
|
362
540
|
let sawSteeringFollowUp = false;
|
|
363
541
|
let mustResolveBeforeHandoffActive = options?.mustResolveBeforeHandoff === true;
|
|
542
|
+
let currentReasoningEffort = "medium";
|
|
543
|
+
let sawSendMessageSelf = false;
|
|
544
|
+
let sawPonder = false;
|
|
545
|
+
let sawQuerySession = false;
|
|
546
|
+
let sawBridgeManage = false;
|
|
547
|
+
let sawExternalStateQuery = false;
|
|
548
|
+
const toolLoopState = (0, tool_loop_1.createToolLoopState)();
|
|
549
|
+
const toolFrictionLedger = (0, tool_friction_1.createToolFrictionLedger)();
|
|
550
|
+
const finishTerminalProviderError = (error, classification) => {
|
|
551
|
+
terminalError = error;
|
|
552
|
+
terminalErrorClassification = classification;
|
|
553
|
+
/* v8 ignore start — auth-failure guidance: tested via provider error classification tests @preserve */
|
|
554
|
+
if (terminalErrorClassification === "auth-failure") {
|
|
555
|
+
const agentName = (0, identity_2.getAgentName)();
|
|
556
|
+
const currentProvider = providerRuntime.id;
|
|
557
|
+
callbacks.onError(new Error(buildAuthFailureGuidance(currentProvider, providerRuntime.model, agentName, terminalError.message)), "terminal");
|
|
558
|
+
}
|
|
559
|
+
else {
|
|
560
|
+
callbacks.onError(terminalError, "terminal");
|
|
561
|
+
}
|
|
562
|
+
/* v8 ignore stop */
|
|
563
|
+
(0, runtime_1.emitNervesEvent)({
|
|
564
|
+
level: "error",
|
|
565
|
+
event: "engine.error",
|
|
566
|
+
trace_id: traceId,
|
|
567
|
+
component: "engine",
|
|
568
|
+
message: terminalError.message,
|
|
569
|
+
meta: {
|
|
570
|
+
provider: providerRuntime.id,
|
|
571
|
+
model: providerRuntime.model,
|
|
572
|
+
errorClassification: terminalErrorClassification,
|
|
573
|
+
},
|
|
574
|
+
});
|
|
575
|
+
stripLastToolCalls(messages);
|
|
576
|
+
outcome = "errored";
|
|
577
|
+
done = true;
|
|
578
|
+
};
|
|
364
579
|
// Prevent MaxListenersExceeded warning — each iteration adds a listener
|
|
365
580
|
try {
|
|
366
581
|
require("events").setMaxListeners(50, signal);
|
|
367
582
|
}
|
|
368
583
|
catch { /* unsupported */ }
|
|
369
584
|
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);
|
|
585
|
+
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);
|
|
586
|
+
// Augment tool context with reasoning effort controls from provider
|
|
587
|
+
const augmentedToolContext = options?.toolContext
|
|
588
|
+
? {
|
|
589
|
+
...options.toolContext,
|
|
590
|
+
supportedReasoningEfforts: providerRuntime.supportedReasoningEfforts,
|
|
591
|
+
setReasoningEffort: (level) => { currentReasoningEffort = level; },
|
|
592
|
+
activeWorkFrame: options?.activeWorkFrame,
|
|
593
|
+
}
|
|
594
|
+
: undefined;
|
|
371
595
|
// Rebase provider-owned turn state from canonical messages at user-turn start.
|
|
372
596
|
// This prevents stale provider caches from replaying prior-turn context.
|
|
373
597
|
providerRuntime.resetTurnState(messages);
|
|
374
598
|
while (!done) {
|
|
375
|
-
//
|
|
376
|
-
//
|
|
377
|
-
//
|
|
378
|
-
//
|
|
379
|
-
|
|
599
|
+
// Channel-based tool filtering:
|
|
600
|
+
// - Inner dialog: exclude send_message (delivery via surface), observe (no one to observe)
|
|
601
|
+
// - All outward channels (1:1, group, reaction): observe available
|
|
602
|
+
//
|
|
603
|
+
// ponder, settle/rest, surface, and observe are always assembled based on channel context.
|
|
604
|
+
// ponder is available in ALL channels (outer: think privately, inner: keep turning).
|
|
605
|
+
// Inner dialog gets restTool instead of settleTool (rest = end turn, gated by attention queue).
|
|
606
|
+
// toolChoiceRequired only controls whether tool_choice: "required" is set in the API call.
|
|
607
|
+
const isInnerDialog = channel === "inner";
|
|
608
|
+
const filteredBaseTools = isInnerDialog
|
|
609
|
+
? baseTools.filter((t) => t.function.name !== "send_message")
|
|
610
|
+
: baseTools;
|
|
611
|
+
const activeTools = [
|
|
612
|
+
...filteredBaseTools,
|
|
613
|
+
tools_1.ponderTool,
|
|
614
|
+
...(isInnerDialog ? [tools_2.surfaceToolDef, tools_1.restTool] : []),
|
|
615
|
+
...(!isInnerDialog ? [tools_1.observeTool] : []),
|
|
616
|
+
...(!isInnerDialog ? [tools_1.settleTool] : []),
|
|
617
|
+
];
|
|
380
618
|
const steeringFollowUps = options?.drainSteeringFollowUps?.() ?? [];
|
|
381
619
|
if (steeringFollowUps.length > 0) {
|
|
382
620
|
const hasSupersedingFollowUp = steeringFollowUps.some((followUp) => followUp.effect === "clear_and_supersede");
|
|
@@ -403,19 +641,87 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
403
641
|
break;
|
|
404
642
|
}
|
|
405
643
|
try {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
644
|
+
const callProviderTurn = async () => {
|
|
645
|
+
callbacks.onModelStart();
|
|
646
|
+
try {
|
|
647
|
+
return await providerRuntime.streamTurn({
|
|
648
|
+
messages,
|
|
649
|
+
activeTools,
|
|
650
|
+
callbacks,
|
|
651
|
+
signal,
|
|
652
|
+
traceId,
|
|
653
|
+
toolChoiceRequired,
|
|
654
|
+
reasoningEffort: currentReasoningEffort,
|
|
655
|
+
eagerSettleStreaming: true,
|
|
656
|
+
systemPrompt: structuredSystemPrompt,
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
catch (error) {
|
|
660
|
+
if (signal?.aborted)
|
|
661
|
+
throw new provider_attempt_1.ProviderAttemptAbortError();
|
|
662
|
+
throw error;
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
const callProviderTurnWithOverflowRecovery = async () => {
|
|
666
|
+
try {
|
|
667
|
+
return await callProviderTurn();
|
|
668
|
+
}
|
|
669
|
+
catch (error) {
|
|
670
|
+
if (error instanceof provider_attempt_1.ProviderAttemptAbortError)
|
|
671
|
+
throw error;
|
|
672
|
+
if (isContextOverflow(error) && !overflowRetried) {
|
|
673
|
+
overflowRetried = true;
|
|
674
|
+
stripLastToolCalls(messages);
|
|
675
|
+
const { maxTokens, contextMargin } = (0, config_1.getContextConfig)();
|
|
676
|
+
const trimmed = (0, context_1.trimMessages)(messages, maxTokens, contextMargin, maxTokens * 2);
|
|
677
|
+
messages.splice(0, messages.length, ...trimmed);
|
|
678
|
+
providerRuntime.resetTurnState(messages);
|
|
679
|
+
callbacks.onError(new Error("context trimmed, retrying..."), "transient");
|
|
680
|
+
return callProviderTurn();
|
|
681
|
+
}
|
|
682
|
+
throw error;
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
const attempt = await (0, provider_attempt_1.runProviderAttempt)({
|
|
686
|
+
operation: "turn",
|
|
687
|
+
provider: providerRuntime.id,
|
|
688
|
+
model: providerRuntime.model,
|
|
689
|
+
run: callProviderTurnWithOverflowRecovery,
|
|
690
|
+
classifyError: (error) => providerRuntime.classifyError(error),
|
|
691
|
+
onRetry: async (record, maxAttempts) => {
|
|
692
|
+
const delayMs = record.delayMs;
|
|
693
|
+
const seconds = delayMs / 1000;
|
|
694
|
+
const cause = RETRY_LABELS[record.classification];
|
|
695
|
+
try {
|
|
696
|
+
await (0, provider_credentials_1.refreshProviderCredentialPool)((0, identity_2.getAgentName)(), { preserveCachedOnFailure: true });
|
|
697
|
+
_providerRuntimes[facing] = null;
|
|
698
|
+
providerRuntime = await getProviderRuntime(facing);
|
|
699
|
+
providerRuntime.resetTurnState(messages);
|
|
700
|
+
}
|
|
701
|
+
catch (refreshError) {
|
|
702
|
+
(0, runtime_1.emitNervesEvent)({
|
|
703
|
+
level: "warn",
|
|
704
|
+
component: "engine",
|
|
705
|
+
event: "engine.provider_retry_refresh_failed",
|
|
706
|
+
message: "provider credential refresh failed during retry",
|
|
707
|
+
meta: { provider: record.provider, model: record.model, reason: refreshError instanceof Error ? refreshError.message : String(refreshError) },
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
callbacks.onError(new Error(`${cause}, retrying in ${seconds}s (${record.attempt}/${maxAttempts})...`), "transient");
|
|
711
|
+
},
|
|
712
|
+
sleep: async (delayMs) => {
|
|
713
|
+
await waitForProviderRetry(delayMs, signal);
|
|
714
|
+
providerRuntime.resetTurnState(messages);
|
|
715
|
+
},
|
|
414
716
|
});
|
|
717
|
+
if (!attempt.ok) {
|
|
718
|
+
finishTerminalProviderError(attempt.error, attempt.classification);
|
|
719
|
+
continue;
|
|
720
|
+
}
|
|
721
|
+
const result = attempt.value;
|
|
415
722
|
// Track usage from the latest API call
|
|
416
723
|
if (result.usage)
|
|
417
724
|
lastUsage = result.usage;
|
|
418
|
-
retryCount = 0; // reset on success
|
|
419
725
|
// SHARED: build CC-format assistant message from TurnResult
|
|
420
726
|
const msg = {
|
|
421
727
|
role: "assistant",
|
|
@@ -434,28 +740,76 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
434
740
|
if (reasoningItems.length > 0) {
|
|
435
741
|
msg._reasoning_items = reasoningItems;
|
|
436
742
|
}
|
|
743
|
+
// Store thinking blocks (Anthropic) on the assistant message for round-tripping
|
|
744
|
+
const thinkingItems = result.outputItems.filter((item) => "type" in item && (item.type === "thinking" || item.type === "redacted_thinking"));
|
|
745
|
+
if (thinkingItems.length > 0) {
|
|
746
|
+
msg._thinking_blocks = thinkingItems;
|
|
747
|
+
}
|
|
748
|
+
// Phase annotation for Codex provider
|
|
749
|
+
const hasPhaseAnnotation = providerRuntime.capabilities.has("phase-annotation");
|
|
750
|
+
const isSoleSettle = result.toolCalls.length === 1 && result.toolCalls[0].name === "settle";
|
|
751
|
+
if (hasPhaseAnnotation) {
|
|
752
|
+
msg.phase = isSoleSettle ? "settle" : "commentary";
|
|
753
|
+
}
|
|
437
754
|
if (!result.toolCalls.length) {
|
|
438
755
|
// No tool calls — accept response as-is.
|
|
439
|
-
// (Kick detection disabled; tool_choice: required +
|
|
756
|
+
// (Kick detection disabled; tool_choice: required + settle
|
|
440
757
|
// is the primary loop control. See src/heart/kicks.ts to re-enable.)
|
|
441
758
|
messages.push(msg);
|
|
442
759
|
done = true;
|
|
443
760
|
}
|
|
444
761
|
else {
|
|
445
|
-
// Check for
|
|
446
|
-
|
|
447
|
-
|
|
762
|
+
// Check for settle sole call: intercept before tool execution
|
|
763
|
+
if (isSoleSettle) {
|
|
764
|
+
/* v8 ignore next -- defensive: JSON.parse catch for malformed settle args @preserve */
|
|
765
|
+
const settleArgs = (() => { try {
|
|
766
|
+
return JSON.parse(result.toolCalls[0].arguments);
|
|
767
|
+
}
|
|
768
|
+
catch {
|
|
769
|
+
return {};
|
|
770
|
+
} })();
|
|
771
|
+
callbacks.onToolStart("settle", settleArgs);
|
|
772
|
+
// Inner dialog attention queue gate: reject settle if items remain
|
|
773
|
+
const attentionQueue = (augmentedToolContext ?? options?.toolContext)?.delegatedOrigins;
|
|
774
|
+
if (isInnerDialog && attentionQueue && attentionQueue.length > 0) {
|
|
775
|
+
callbacks.onToolEnd("settle", (0, tools_1.summarizeArgs)("settle", settleArgs), false);
|
|
776
|
+
callbacks.onClearText?.();
|
|
777
|
+
messages.push(msg);
|
|
778
|
+
const gateMessage = "you're holding thoughts someone is waiting for — surface them before you settle.";
|
|
779
|
+
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: gateMessage });
|
|
780
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, gateMessage);
|
|
781
|
+
continue;
|
|
782
|
+
}
|
|
448
783
|
// Extract answer from the tool call arguments.
|
|
449
784
|
// Supports: {"answer":"text","intent":"..."} or "text" (JSON string).
|
|
450
|
-
const { answer, intent } =
|
|
785
|
+
const { answer, intent } = parseSettlePayload(result.toolCalls[0].arguments);
|
|
786
|
+
// Inner dialog settle: no CompletionMetadata, "(settled)" ack
|
|
787
|
+
if (isInnerDialog) {
|
|
788
|
+
callbacks.onToolEnd("settle", (0, tools_1.summarizeArgs)("settle", settleArgs), true);
|
|
789
|
+
messages.push(msg);
|
|
790
|
+
const settled = "(settled)";
|
|
791
|
+
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: settled });
|
|
792
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, settled);
|
|
793
|
+
outcome = "settled";
|
|
794
|
+
done = true;
|
|
795
|
+
continue;
|
|
796
|
+
}
|
|
797
|
+
const retryError = getSettleRetryError(mustResolveBeforeHandoffActive, intent, sawSteeringFollowUp, options?.delegationDecision, sawSendMessageSelf, sawPonder, sawQuerySession, options?.currentObligation ?? null, options?.activeWorkFrame?.inner?.job, sawExternalStateQuery);
|
|
798
|
+
const deliveredAnswer = answer;
|
|
451
799
|
const validDirectReply = mustResolveBeforeHandoffActive && intent === "direct_reply" && sawSteeringFollowUp;
|
|
452
800
|
const validTerminalIntent = intent === "complete" || intent === "blocked";
|
|
453
|
-
const validClosure =
|
|
801
|
+
const validClosure = deliveredAnswer != null
|
|
802
|
+
&& !retryError
|
|
454
803
|
&& (!mustResolveBeforeHandoffActive || validDirectReply || validTerminalIntent);
|
|
455
804
|
if (validClosure) {
|
|
456
|
-
|
|
805
|
+
callbacks.onToolEnd("settle", (0, tools_1.summarizeArgs)("settle", settleArgs), true);
|
|
806
|
+
completion = {
|
|
807
|
+
answer: deliveredAnswer,
|
|
808
|
+
intent: validDirectReply ? "direct_reply" : intent === "blocked" ? "blocked" : "complete",
|
|
809
|
+
};
|
|
810
|
+
if (result.settleStreamed) {
|
|
457
811
|
// The streaming layer already parsed and emitted the answer
|
|
458
|
-
// progressively via
|
|
812
|
+
// progressively via SettleParser. Skip clearing and
|
|
459
813
|
// re-emitting to avoid double-delivery.
|
|
460
814
|
}
|
|
461
815
|
else {
|
|
@@ -463,7 +817,7 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
463
817
|
callbacks.onClearText?.();
|
|
464
818
|
// Emit the answer through the callback pipeline so channels receive it.
|
|
465
819
|
// Never truncate -- channel adapters handle splitting long messages.
|
|
466
|
-
callbacks.onTextChunk(
|
|
820
|
+
callbacks.onTextChunk(deliveredAnswer);
|
|
467
821
|
}
|
|
468
822
|
messages.push(msg);
|
|
469
823
|
if (validDirectReply) {
|
|
@@ -475,32 +829,106 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
475
829
|
const delivered = "(delivered)";
|
|
476
830
|
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: delivered });
|
|
477
831
|
providerRuntime.appendToolOutput(result.toolCalls[0].id, delivered);
|
|
478
|
-
outcome = intent === "blocked" ? "blocked" : "
|
|
832
|
+
outcome = intent === "blocked" ? "blocked" : "settled";
|
|
479
833
|
done = true;
|
|
480
834
|
}
|
|
481
835
|
}
|
|
482
836
|
else {
|
|
483
|
-
// Answer is undefined -- the model's
|
|
837
|
+
// Answer is undefined -- the model's settle was incomplete or
|
|
484
838
|
// malformed. Clear any partial streamed text or noise, then push the
|
|
485
839
|
// assistant msg + error tool result and let the model try again.
|
|
840
|
+
callbacks.onToolEnd("settle", (0, tools_1.summarizeArgs)("settle", settleArgs), false);
|
|
486
841
|
callbacks.onClearText?.();
|
|
487
|
-
const retryError = getFinalAnswerRetryError(mustResolveBeforeHandoffActive, intent, sawSteeringFollowUp);
|
|
488
842
|
messages.push(msg);
|
|
489
|
-
|
|
490
|
-
|
|
843
|
+
const toolRetryMessage = retryError
|
|
844
|
+
?? "your settle was incomplete or malformed. call settle again with your complete response.";
|
|
845
|
+
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: toolRetryMessage });
|
|
846
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, toolRetryMessage);
|
|
847
|
+
}
|
|
848
|
+
continue;
|
|
849
|
+
}
|
|
850
|
+
// Check for observe sole call: intercept before tool execution
|
|
851
|
+
const isSoleObserve = result.toolCalls.length === 1 && result.toolCalls[0].name === "observe";
|
|
852
|
+
if (isSoleObserve) {
|
|
853
|
+
/* v8 ignore next -- defensive: JSON.parse catch for malformed observe args @preserve */
|
|
854
|
+
const observeArgs = (() => { try {
|
|
855
|
+
return JSON.parse(result.toolCalls[0].arguments);
|
|
856
|
+
}
|
|
857
|
+
catch {
|
|
858
|
+
return {};
|
|
859
|
+
} })();
|
|
860
|
+
let reason;
|
|
861
|
+
if (typeof observeArgs?.reason === "string")
|
|
862
|
+
reason = observeArgs.reason;
|
|
863
|
+
callbacks.onToolStart("observe", observeArgs);
|
|
864
|
+
(0, runtime_1.emitNervesEvent)({
|
|
865
|
+
component: "engine",
|
|
866
|
+
event: "engine.observe",
|
|
867
|
+
message: "agent observed without responding",
|
|
868
|
+
meta: { ...(reason ? { reason } : {}) },
|
|
869
|
+
});
|
|
870
|
+
callbacks.onToolEnd("observe", (0, tools_1.summarizeArgs)("observe", observeArgs), true);
|
|
871
|
+
messages.push(msg);
|
|
872
|
+
const silenced = "(silenced)";
|
|
873
|
+
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: silenced });
|
|
874
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, silenced);
|
|
875
|
+
outcome = "observed";
|
|
876
|
+
done = true;
|
|
877
|
+
continue;
|
|
878
|
+
}
|
|
879
|
+
// Check for rest sole call: intercept before tool execution
|
|
880
|
+
const isSoleRest = result.toolCalls.length === 1 && result.toolCalls[0].name === "rest";
|
|
881
|
+
if (isSoleRest) {
|
|
882
|
+
const restArgs = (() => { try {
|
|
883
|
+
return JSON.parse(result.toolCalls[0].arguments);
|
|
884
|
+
}
|
|
885
|
+
catch {
|
|
886
|
+
return {};
|
|
887
|
+
} })();
|
|
888
|
+
callbacks.onToolStart("rest", restArgs);
|
|
889
|
+
// Attention queue gate: reject rest if items remain
|
|
890
|
+
const attentionQueue = (augmentedToolContext ?? options?.toolContext)?.delegatedOrigins;
|
|
891
|
+
if (attentionQueue && attentionQueue.length > 0) {
|
|
892
|
+
callbacks.onToolEnd("rest", (0, tools_1.summarizeArgs)("rest", restArgs), false);
|
|
893
|
+
messages.push(msg);
|
|
894
|
+
const gateMessage = "you're holding thoughts someone is waiting for — surface them before you rest.";
|
|
895
|
+
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: gateMessage });
|
|
896
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, gateMessage);
|
|
897
|
+
continue;
|
|
898
|
+
}
|
|
899
|
+
if (hasFreshPendingWork(options)) {
|
|
900
|
+
callbacks.onToolEnd("rest", (0, tools_1.summarizeArgs)("rest", restArgs), false);
|
|
901
|
+
messages.push(msg);
|
|
902
|
+
const gateMessage = "fresh work arrived for me this turn — inspect the pending messages above and take the next concrete action before you rest.";
|
|
903
|
+
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: gateMessage });
|
|
904
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, gateMessage);
|
|
905
|
+
continue;
|
|
491
906
|
}
|
|
907
|
+
callbacks.onToolEnd("rest", (0, tools_1.summarizeArgs)("rest", restArgs), true);
|
|
908
|
+
messages.push(msg);
|
|
909
|
+
const ack = "(resting)";
|
|
910
|
+
messages.push({ role: "tool", tool_call_id: result.toolCalls[0].id, content: ack });
|
|
911
|
+
providerRuntime.appendToolOutput(result.toolCalls[0].id, ack);
|
|
912
|
+
(0, runtime_1.emitNervesEvent)({
|
|
913
|
+
component: "engine",
|
|
914
|
+
event: "engine.rested",
|
|
915
|
+
message: "resting until next heartbeat",
|
|
916
|
+
meta: { ...(typeof restArgs?.status === "string" ? { status: restArgs.status } : {}) },
|
|
917
|
+
});
|
|
918
|
+
outcome = "rested";
|
|
919
|
+
done = true;
|
|
492
920
|
continue;
|
|
493
921
|
}
|
|
494
922
|
messages.push(msg);
|
|
495
|
-
//
|
|
923
|
+
// Execute tools (sole-call tools in mixed calls are rejected inline)
|
|
496
924
|
for (const tc of result.toolCalls) {
|
|
497
925
|
if (signal?.aborted)
|
|
498
926
|
break;
|
|
499
|
-
//
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
messages.push({ role: "tool", tool_call_id: tc.id, content:
|
|
503
|
-
providerRuntime.appendToolOutput(tc.id,
|
|
927
|
+
// Reject sole-call tools when mixed with other tool calls
|
|
928
|
+
const soleCallRejection = SOLE_CALL_REJECTION[tc.name];
|
|
929
|
+
if (soleCallRejection) {
|
|
930
|
+
messages.push({ role: "tool", tool_call_id: tc.id, content: soleCallRejection });
|
|
931
|
+
providerRuntime.appendToolOutput(tc.id, soleCallRejection);
|
|
504
932
|
continue;
|
|
505
933
|
}
|
|
506
934
|
let args = {};
|
|
@@ -510,97 +938,195 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
510
938
|
catch {
|
|
511
939
|
/* ignore */
|
|
512
940
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
941
|
+
if (tc.name === "send_message" && args.friendId === "self") {
|
|
942
|
+
sawSendMessageSelf = true;
|
|
943
|
+
}
|
|
944
|
+
if (tc.name === "ponder") {
|
|
945
|
+
const parsedArgs = normalizeLegacyPonderArgs(parsePonderPayload(tc.arguments));
|
|
946
|
+
const argSummary = (0, tools_1.summarizeArgs)(tc.name, parsedArgs);
|
|
947
|
+
callbacks.onToolStart(tc.name, parsedArgs);
|
|
948
|
+
let toolResult;
|
|
949
|
+
let success = false;
|
|
950
|
+
try {
|
|
951
|
+
const action = parsedArgs.action ?? "create";
|
|
952
|
+
const currentSession = (augmentedToolContext ?? options?.toolContext)?.currentSession;
|
|
953
|
+
const currentOrigin = currentSession
|
|
954
|
+
? { friendId: currentSession.friendId, channel: currentSession.channel, key: currentSession.key }
|
|
955
|
+
: undefined;
|
|
956
|
+
const isInnerChannel = currentOrigin?.friendId === "self" && currentOrigin?.channel === "inner";
|
|
957
|
+
const successCriteria = parseSuccessCriteria(parsedArgs.success_criteria);
|
|
958
|
+
const payload = parsePacketPayload(parsedArgs.payload_json);
|
|
959
|
+
let packet;
|
|
960
|
+
let returnObligationId = null;
|
|
961
|
+
let resultAction = "created";
|
|
962
|
+
if (action === "create") {
|
|
963
|
+
const kind = parsedArgs.kind;
|
|
964
|
+
const objective = typeof parsedArgs.objective === "string" ? parsedArgs.objective.trim() : "";
|
|
965
|
+
const summary = typeof parsedArgs.summary === "string" ? parsedArgs.summary.trim() : "";
|
|
966
|
+
if (!kind || !objective || !successCriteria || !payload) {
|
|
967
|
+
throw new Error("ponder create requires kind, objective, success_criteria, and valid payload_json.");
|
|
968
|
+
}
|
|
969
|
+
const agentRoot = (0, identity_2.getAgentRoot)();
|
|
970
|
+
let relatedObligationId;
|
|
971
|
+
if (currentOrigin && !isInnerChannel) {
|
|
972
|
+
try {
|
|
973
|
+
const obligation = (0, obligations_1.createObligation)(agentRoot, {
|
|
974
|
+
origin: currentOrigin,
|
|
975
|
+
content: objective,
|
|
976
|
+
});
|
|
977
|
+
relatedObligationId = obligation.id;
|
|
978
|
+
}
|
|
979
|
+
catch {
|
|
980
|
+
relatedObligationId = undefined;
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
const frictionSignature = kind === "harness_friction" && typeof payload.frictionSignature === "string"
|
|
984
|
+
? payload.frictionSignature
|
|
985
|
+
: null;
|
|
986
|
+
const existing = frictionSignature && currentOrigin
|
|
987
|
+
? (0, packets_1.findHarnessFrictionPacket)(agentRoot, currentOrigin, frictionSignature)
|
|
988
|
+
: null;
|
|
989
|
+
if (existing) {
|
|
990
|
+
resultAction = "revised";
|
|
991
|
+
returnObligationId = existing.relatedReturnObligationId ?? null;
|
|
992
|
+
packet = existing.status === "drafting"
|
|
993
|
+
? (0, packets_1.revisePonderPacket)(agentRoot, existing.id, {
|
|
994
|
+
kind,
|
|
995
|
+
objective,
|
|
996
|
+
summary,
|
|
997
|
+
successCriteria,
|
|
998
|
+
payload,
|
|
999
|
+
})
|
|
1000
|
+
: existing;
|
|
1001
|
+
}
|
|
1002
|
+
else {
|
|
1003
|
+
returnObligationId = (0, obligations_1.generateObligationId)(Date.now());
|
|
1004
|
+
packet = (0, packets_1.createPonderPacket)(agentRoot, {
|
|
1005
|
+
kind,
|
|
1006
|
+
objective,
|
|
1007
|
+
summary,
|
|
1008
|
+
successCriteria,
|
|
1009
|
+
...(currentOrigin ? { origin: currentOrigin } : {}),
|
|
1010
|
+
...(relatedObligationId ? { relatedObligationId } : {}),
|
|
1011
|
+
relatedReturnObligationId: returnObligationId,
|
|
1012
|
+
...(parsedArgs.follows_packet_id ? { followsPacketId: parsedArgs.follows_packet_id } : {}),
|
|
1013
|
+
payload,
|
|
1014
|
+
});
|
|
1015
|
+
(0, obligations_1.createReturnObligation)((0, identity_2.getAgentName)(), {
|
|
1016
|
+
id: returnObligationId,
|
|
1017
|
+
origin: currentOrigin ?? { friendId: "self", channel: "inner", key: "dialog" },
|
|
1018
|
+
status: "queued",
|
|
1019
|
+
delegatedContent: (summary || objective).length > 120 ? `${(summary || objective).slice(0, 117)}...` : (summary || objective),
|
|
1020
|
+
packetId: packet.id,
|
|
1021
|
+
createdAt: Date.now(),
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
else if (action === "revise") {
|
|
1026
|
+
const packetId = typeof parsedArgs.packet_id === "string" ? parsedArgs.packet_id.trim() : "";
|
|
1027
|
+
const kind = parsedArgs.kind;
|
|
1028
|
+
const objective = typeof parsedArgs.objective === "string" ? parsedArgs.objective.trim() : "";
|
|
1029
|
+
const summary = typeof parsedArgs.summary === "string" ? parsedArgs.summary.trim() : "";
|
|
1030
|
+
if (!packetId || !kind || !objective || !successCriteria || !payload) {
|
|
1031
|
+
throw new Error("ponder revise requires packet_id, kind, objective, success_criteria, and valid payload_json.");
|
|
1032
|
+
}
|
|
1033
|
+
packet = (0, packets_1.revisePonderPacket)((0, identity_2.getAgentRoot)(), packetId, {
|
|
1034
|
+
kind,
|
|
1035
|
+
objective,
|
|
1036
|
+
summary,
|
|
1037
|
+
successCriteria,
|
|
1038
|
+
payload,
|
|
1039
|
+
});
|
|
1040
|
+
returnObligationId = packet.relatedReturnObligationId ?? null;
|
|
1041
|
+
resultAction = "revised";
|
|
1042
|
+
}
|
|
1043
|
+
else {
|
|
1044
|
+
throw new Error("ponder requires action=create or revise.");
|
|
1045
|
+
}
|
|
1046
|
+
try {
|
|
1047
|
+
await (0, socket_client_1.requestInnerWake)((0, identity_2.getAgentName)());
|
|
1048
|
+
}
|
|
1049
|
+
catch { /* daemon may not be running */ }
|
|
1050
|
+
sawPonder = true;
|
|
1051
|
+
toolResult = buildPonderResult(packet, resultAction, returnObligationId);
|
|
1052
|
+
success = true;
|
|
1053
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1054
|
+
component: "engine",
|
|
1055
|
+
event: "engine.ponder_packet",
|
|
1056
|
+
message: "ponder packet touched",
|
|
1057
|
+
meta: {
|
|
1058
|
+
action: resultAction,
|
|
1059
|
+
packetId: packet.id,
|
|
1060
|
+
kind: packet.kind,
|
|
1061
|
+
status: packet.status,
|
|
1062
|
+
},
|
|
1063
|
+
});
|
|
519
1064
|
}
|
|
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;
|
|
1065
|
+
catch (error) {
|
|
1066
|
+
toolResult = error instanceof Error ? error.message : String(error);
|
|
527
1067
|
}
|
|
1068
|
+
callbacks.onToolEnd(tc.name, argSummary, success);
|
|
1069
|
+
messages.push({ role: "tool", tool_call_id: tc.id, content: toolResult });
|
|
1070
|
+
providerRuntime.appendToolOutput(tc.id, toolResult);
|
|
1071
|
+
continue;
|
|
1072
|
+
}
|
|
1073
|
+
/* v8 ignore next -- flag tested via truth-check integration tests @preserve */
|
|
1074
|
+
if (tc.name === "query_session")
|
|
1075
|
+
sawQuerySession = true;
|
|
1076
|
+
/* v8 ignore next -- flag tested via truth-check integration tests @preserve */
|
|
1077
|
+
if (tc.name === "bridge_manage")
|
|
1078
|
+
sawBridgeManage = true;
|
|
1079
|
+
/* v8 ignore next -- flag tested via truth-check integration tests @preserve */
|
|
1080
|
+
if (isExternalStateQuery(tc.name, args))
|
|
1081
|
+
sawExternalStateQuery = true;
|
|
1082
|
+
const argSummary = (0, tools_1.summarizeArgs)(tc.name, args);
|
|
1083
|
+
const toolLoop = (0, tool_loop_1.detectToolLoop)(toolLoopState, tc.name, args);
|
|
1084
|
+
if (toolLoop.stuck) {
|
|
1085
|
+
const rejection = `loop guard: ${toolLoop.message}`;
|
|
1086
|
+
callbacks.onToolStart(tc.name, args);
|
|
1087
|
+
callbacks.onToolEnd(tc.name, argSummary, false);
|
|
1088
|
+
messages.push({ role: "tool", tool_call_id: tc.id, content: rejection });
|
|
1089
|
+
providerRuntime.appendToolOutput(tc.id, rejection);
|
|
1090
|
+
continue;
|
|
528
1091
|
}
|
|
529
1092
|
callbacks.onToolStart(tc.name, args);
|
|
530
1093
|
let toolResult;
|
|
531
1094
|
let success;
|
|
532
1095
|
try {
|
|
533
1096
|
const execToolFn = options?.execTool ?? tools_1.execTool;
|
|
534
|
-
toolResult = await execToolFn(tc.name, args, options?.toolContext);
|
|
1097
|
+
toolResult = await execToolFn(tc.name, args, augmentedToolContext ?? options?.toolContext);
|
|
535
1098
|
success = true;
|
|
536
1099
|
}
|
|
537
1100
|
catch (e) {
|
|
538
1101
|
toolResult = `error: ${e}`;
|
|
539
1102
|
success = false;
|
|
540
1103
|
}
|
|
541
|
-
|
|
1104
|
+
toolResult = (0, tool_friction_1.rewriteToolResultForModel)(tc.name, toolResult, toolFrictionLedger);
|
|
1105
|
+
(0, tool_loop_1.recordToolOutcome)(toolLoopState, tc.name, args, toolResult, success);
|
|
1106
|
+
callbacks.onToolEnd(tc.name, (0, tools_1.buildToolResultSummary)(tc.name, args, toolResult, success), success);
|
|
542
1107
|
messages.push({ role: "tool", tool_call_id: tc.id, content: toolResult });
|
|
543
1108
|
providerRuntime.appendToolOutput(tc.id, toolResult);
|
|
1109
|
+
callbacks.onToolResult?.(messages);
|
|
544
1110
|
}
|
|
545
1111
|
}
|
|
546
1112
|
}
|
|
547
1113
|
catch (e) {
|
|
548
1114
|
// Abort is not an error — just stop cleanly
|
|
549
|
-
if (signal?.aborted) {
|
|
1115
|
+
if (e instanceof provider_attempt_1.ProviderAttemptAbortError || signal?.aborted) {
|
|
550
1116
|
stripLastToolCalls(messages);
|
|
551
1117
|
outcome = "aborted";
|
|
552
1118
|
break;
|
|
553
1119
|
}
|
|
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;
|
|
1120
|
+
const errorForClassification = e instanceof Error ? e : /* v8 ignore next -- defensive @preserve */ new Error(String(e));
|
|
1121
|
+
let providerClassification;
|
|
1122
|
+
try {
|
|
1123
|
+
providerClassification = providerRuntime.classifyError(errorForClassification);
|
|
564
1124
|
}
|
|
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;
|
|
1125
|
+
catch {
|
|
1126
|
+
/* v8 ignore next -- defensive: classifyError should not throw @preserve */
|
|
1127
|
+
providerClassification = "unknown";
|
|
591
1128
|
}
|
|
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;
|
|
1129
|
+
finishTerminalProviderError(errorForClassification, providerClassification);
|
|
604
1130
|
}
|
|
605
1131
|
}
|
|
606
1132
|
(0, runtime_1.emitNervesEvent)({
|
|
@@ -608,7 +1134,12 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
608
1134
|
trace_id: traceId,
|
|
609
1135
|
component: "engine",
|
|
610
1136
|
message: "runAgent turn completed",
|
|
611
|
-
meta: { done },
|
|
1137
|
+
meta: { done, sawPonder, sawQuerySession, sawBridgeManage },
|
|
612
1138
|
});
|
|
613
|
-
return {
|
|
1139
|
+
return {
|
|
1140
|
+
usage: lastUsage,
|
|
1141
|
+
outcome,
|
|
1142
|
+
completion,
|
|
1143
|
+
...(terminalError ? { error: terminalError, errorClassification: terminalErrorClassification } : {}),
|
|
1144
|
+
};
|
|
614
1145
|
}
|