@orion-agents/orion-code 0.3.65 → 0.4.3
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/CHANGELOG.md +128 -2
- package/README.md +78 -361
- package/README.zh-CN.md +71 -263
- package/bin/orion +4 -1
- package/dist/acp/session-updates.d.ts +34 -0
- package/dist/acp/session-updates.js +162 -0
- package/dist/acp/sessions.d.ts +32 -0
- package/dist/acp/sessions.js +315 -0
- package/dist/acp/stdio.d.ts +3 -0
- package/dist/acp/stdio.js +59 -0
- package/dist/cli.js +136 -185
- package/dist/commands/context-tool-command-handlers.d.ts +1 -1
- package/dist/commands/context-tool-command-handlers.js +24 -3
- package/dist/commands/core-command-handlers.js +5 -1
- package/dist/commands/diagnostic-command-handlers.js +20 -6
- package/dist/commands/diagnostic-commands.js +0 -12
- package/dist/commands/init-command.d.ts +3 -0
- package/dist/commands/init-command.js +131 -0
- package/dist/commands/model-command-handlers.d.ts +1 -2
- package/dist/commands/model-command-handlers.js +15 -100
- package/dist/commands/model-commands.js +0 -11
- package/dist/commands/registry.js +0 -18
- package/dist/commands/rsi-command.d.ts +2 -0
- package/dist/commands/rsi-command.js +180 -0
- package/dist/commands/session-command-handlers.js +28 -19
- package/dist/commands/system-commands.js +0 -1
- package/dist/commands/tool-commands.js +1 -1
- package/dist/commands/types.d.ts +4 -10
- package/dist/commands/types.js +1 -21
- package/dist/commands/workflow-command-handlers.js +13 -4
- package/dist/framework/loop-budget-contract.d.ts +7 -2
- package/dist/framework/loop-budget-contract.js +4 -1
- package/dist/framework/loop-progress.d.ts +22 -0
- package/dist/framework/loop-progress.js +79 -0
- package/dist/framework/prompt.d.ts +0 -2
- package/dist/framework/prompt.js +9 -27
- package/dist/framework/query.d.ts +27 -20
- package/dist/framework/query.js +453 -153
- package/dist/framework/store.d.ts +6 -10
- package/dist/framework/store.js +2 -21
- package/dist/framework/tool-call-orchestrator.d.ts +7 -0
- package/dist/framework/tool-call-orchestrator.js +8 -3
- package/dist/framework/tool-state.d.ts +2 -0
- package/dist/framework/tool.d.ts +0 -23
- package/dist/framework/verification-command.d.ts +15 -0
- package/dist/framework/verification-command.js +32 -0
- package/dist/harness/assembler.d.ts +1 -0
- package/dist/harness/assembler.js +24 -0
- package/dist/harness/capsule.d.ts +1 -1
- package/dist/harness/capsule.js +33 -14
- package/dist/harness/context-harness.d.ts +31 -12
- package/dist/harness/context-harness.js +491 -35
- package/dist/harness/contract.js +1 -1
- package/dist/harness/drift-guard.d.ts +4 -0
- package/dist/harness/drift-guard.js +68 -16
- package/dist/harness/intent.js +21 -0
- package/dist/harness/ledger.d.ts +6 -11
- package/dist/harness/ledger.js +39 -9
- package/dist/harness/progress-controller.d.ts +12 -7
- package/dist/harness/progress-controller.js +66 -21
- package/dist/harness/state.js +9 -1
- package/dist/harness/task-checklist.d.ts +16 -0
- package/dist/harness/task-checklist.js +95 -0
- package/dist/harness/types.d.ts +73 -1
- package/dist/harness/verification.d.ts +19 -1
- package/dist/harness/verification.js +116 -29
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -3
- package/dist/print-ui/event-stream.d.ts +38 -0
- package/dist/print-ui/event-stream.js +187 -0
- package/dist/print-ui/launch.d.ts +12 -1
- package/dist/print-ui/launch.js +173 -11
- package/dist/product/environment.d.ts +1 -1
- package/dist/product/environment.js +1 -1
- package/dist/product/identity.d.ts +1 -1
- package/dist/product/identity.js +1 -1
- package/dist/product/paths.d.ts +3 -2
- package/dist/product/paths.js +6 -2
- package/dist/runtime/agent-loop.d.ts +11 -2
- package/dist/runtime/agent-loop.js +165 -25
- package/dist/runtime/agent-runtime-controller.d.ts +13 -3
- package/dist/runtime/agent-runtime-controller.js +347 -183
- package/dist/runtime/agent-runtime-protocol.d.ts +10 -18
- package/dist/runtime/agent-runtime-runner.d.ts +10 -0
- package/dist/runtime/builtin-tool-provider.js +5 -1
- package/dist/runtime/capability-receipt-journal.js +1 -0
- package/dist/runtime/durable-tool-receipt-reader.js +2 -1
- package/dist/runtime/first-party-tool-services.d.ts +1 -0
- package/dist/runtime/first-party-tool-services.js +2 -12
- package/dist/runtime/first-party-tool-universe.d.ts +1 -0
- package/dist/runtime/first-party-tool-universe.js +1 -1
- package/dist/runtime/followup-queue-store.d.ts +16 -0
- package/dist/runtime/followup-queue-store.js +75 -0
- package/dist/runtime/goal-lifecycle-v2.d.ts +11 -1
- package/dist/runtime/goal-lifecycle-v2.js +85 -15
- package/dist/runtime/goal-runtime-coordinator.d.ts +10 -1
- package/dist/runtime/goal-runtime-coordinator.js +81 -24
- package/dist/runtime/loop-budget.js +7 -5
- package/dist/runtime/mcp/first-party-mcp-adapter.d.ts +2 -0
- package/dist/runtime/mcp/first-party-mcp-adapter.js +23 -19
- package/dist/runtime/model-coordinator.js +2 -5
- package/dist/runtime/orion-runtime-v1.d.ts +18 -2
- package/dist/runtime/orion-runtime-v1.js +135 -39
- package/dist/runtime/orion-session-runner.d.ts +7 -0
- package/dist/runtime/orion-session-runner.js +82 -0
- package/dist/runtime/plan-review.d.ts +1 -0
- package/dist/runtime/plan-review.js +8 -4
- package/dist/runtime/product-bootstrap.d.ts +6 -0
- package/dist/runtime/product-bootstrap.js +41 -51
- package/dist/runtime/product-orion-runtime.js +128 -52
- package/dist/runtime/release-receipts.d.ts +24 -124
- package/dist/runtime/release-receipts.js +129 -683
- package/dist/runtime/rich-text/layout.js +108 -65
- package/dist/runtime/rsi/contracts.d.ts +50 -0
- package/dist/runtime/rsi/contracts.js +17 -0
- package/dist/runtime/rsi/diagnosis.d.ts +46 -0
- package/dist/runtime/rsi/diagnosis.js +98 -0
- package/dist/runtime/rsi/evaluation-suite.d.ts +25 -0
- package/dist/runtime/rsi/evaluation-suite.js +141 -0
- package/dist/runtime/rsi/evaluation-worker.d.ts +19 -0
- package/dist/runtime/rsi/evaluation-worker.js +64 -0
- package/dist/runtime/rsi/evaluation.d.ts +49 -0
- package/dist/runtime/rsi/evaluation.js +351 -0
- package/dist/runtime/rsi/lifecycle.d.ts +54 -0
- package/dist/runtime/rsi/lifecycle.js +279 -0
- package/dist/runtime/rsi/proposal.d.ts +39 -0
- package/dist/runtime/rsi/proposal.js +312 -0
- package/dist/runtime/rsi/receipt.d.ts +28 -0
- package/dist/runtime/rsi/receipt.js +138 -0
- package/dist/runtime/rsi/skill-state.d.ts +7 -0
- package/dist/runtime/rsi/skill-state.js +50 -0
- package/dist/runtime/rsi/trajectory.d.ts +19 -0
- package/dist/runtime/rsi/trajectory.js +314 -0
- package/dist/runtime/rsi/triage.d.ts +274 -0
- package/dist/runtime/rsi/triage.js +58 -0
- package/dist/runtime/session-composer-control.d.ts +5 -24
- package/dist/runtime/session-composer-control.js +27 -189
- package/dist/runtime/step-snapshot.d.ts +1 -0
- package/dist/runtime/subagents/policy.js +0 -1
- package/dist/runtime/subagents/production.js +1 -1
- package/dist/runtime/subagents/runtime-integration.js +2 -4
- package/dist/runtime/subagents/types.d.ts +0 -5
- package/dist/runtime/subagents/types.js +0 -2
- package/dist/runtime/task-context-recovery.d.ts +55 -0
- package/dist/runtime/task-context-recovery.js +342 -0
- package/dist/runtime/task-context-service.d.ts +16 -10
- package/dist/runtime/task-context-service.js +35 -4
- package/dist/runtime/thread-admission.d.ts +1 -1
- package/dist/runtime/thread-admission.js +12 -6
- package/dist/runtime/thread-event-store.d.ts +2 -2
- package/dist/runtime/thread-event-store.js +7 -2
- package/dist/runtime/thread-projection.js +4 -2
- package/dist/runtime/thread-runtime.d.ts +7 -0
- package/dist/runtime/thread-runtime.js +43 -0
- package/dist/runtime/thread-session-index.d.ts +8 -0
- package/dist/runtime/thread-session-index.js +50 -1
- package/dist/runtime/thread-session-view.d.ts +2 -1
- package/dist/runtime/thread-session-view.js +4 -0
- package/dist/runtime/thread-tool-journal.d.ts +1 -0
- package/dist/runtime/thread-tool-journal.js +6 -2
- package/dist/runtime/thread-ui-adapter.d.ts +1 -0
- package/dist/runtime/thread-ui-adapter.js +88 -11
- package/dist/runtime/tool-gateway.d.ts +7 -0
- package/dist/runtime/tool-gateway.js +20 -0
- package/dist/runtime/tool-transcript-entry.d.ts +16 -0
- package/dist/runtime/tool-transcript-entry.js +73 -0
- package/dist/runtime/turn-commit.d.ts +4 -1
- package/dist/runtime/turn-commit.js +19 -15
- package/dist/runtime/ui-events.d.ts +12 -0
- package/dist/runtime/ui-view-model.d.ts +6 -5
- package/dist/runtime/ui-view-model.js +33 -19
- package/dist/runtime/workspace-runtime-kernel.js +0 -1
- package/dist/services/atomic-write.d.ts +2 -0
- package/dist/services/atomic-write.js +12 -1
- package/dist/services/code-review/format.d.ts +4 -1
- package/dist/services/code-review/format.js +5 -1
- package/dist/services/code-review/runner.d.ts +2 -2
- package/dist/services/code-review/runner.js +86 -64
- package/dist/services/code-review/snapshot.d.ts +9 -9
- package/dist/services/code-review/snapshot.js +182 -166
- package/dist/services/compact/auto-compact.d.ts +21 -6
- package/dist/services/compact/auto-compact.js +148 -22
- package/dist/services/compact/background-candidate.d.ts +33 -0
- package/dist/services/compact/background-candidate.js +184 -0
- package/dist/services/compact/compact.d.ts +4 -1
- package/dist/services/compact/compact.js +30 -3
- package/dist/services/compact/coordinator.d.ts +10 -4
- package/dist/services/compact/coordinator.js +17 -7
- package/dist/services/compact/summary-generator.d.ts +4 -2
- package/dist/services/compact/summary-generator.js +17 -3
- package/dist/services/config.d.ts +5 -5
- package/dist/services/config.js +30 -45
- package/dist/services/doctor.js +85 -13
- package/dist/services/effort.d.ts +5 -5
- package/dist/services/effort.js +5 -11
- package/dist/services/file-lock.d.ts +9 -3
- package/dist/services/file-lock.js +92 -26
- package/dist/services/global-config.d.ts +26 -56
- package/dist/services/global-config.js +213 -183
- package/dist/services/llm.d.ts +40 -4
- package/dist/services/llm.js +164 -45
- package/dist/services/model-client-pool.d.ts +15 -9
- package/dist/services/model-client-pool.js +62 -33
- package/dist/services/model-context.d.ts +2 -1
- package/dist/services/model-context.js +15 -9
- package/dist/services/model-registry.d.ts +4 -15
- package/dist/services/model-registry.js +32 -101
- package/dist/services/provider-diagnostics.d.ts +7 -0
- package/dist/services/provider-diagnostics.js +9 -10
- package/dist/services/provider-resilience/coordinator.d.ts +1 -1
- package/dist/services/provider-resilience/coordinator.js +10 -6
- package/dist/services/provider-resilience/request-gate.d.ts +3 -0
- package/dist/services/provider-resilience/request-gate.js +29 -18
- package/dist/services/provider-resilience/types.d.ts +2 -0
- package/dist/services/session-storage.d.ts +7 -10
- package/dist/services/session-storage.js +57 -30
- package/dist/services/settings-coordinator.d.ts +0 -6
- package/dist/services/settings-coordinator.js +19 -56
- package/dist/services/settings-document-repository.d.ts +3 -10
- package/dist/services/settings-document-repository.js +7 -85
- package/dist/services/usage-state.d.ts +3 -3
- package/dist/services/usage-state.js +11 -42
- package/dist/terminal-ui/answer-format.d.ts +14 -0
- package/dist/terminal-ui/answer-format.js +119 -0
- package/dist/terminal-ui/launch.d.ts +7 -6
- package/dist/terminal-ui/launch.js +160 -70
- package/dist/terminal-ui/output-queue.d.ts +2 -1
- package/dist/terminal-ui/output-queue.js +1 -1
- package/dist/terminal-ui/raw-editor.d.ts +2 -1
- package/dist/terminal-ui/raw-editor.js +56 -15
- package/dist/tools/core/edit-file.js +2 -0
- package/dist/tools/core/write-file.js +5 -0
- package/dist/tools/lsp.d.ts +16 -1
- package/dist/tools/lsp.js +60 -19
- package/dist/tools/sandbox.d.ts +1 -1
- package/dist/tools/sandbox.js +3 -16
- package/dist/tools/todo.d.ts +4 -2
- package/dist/tools/todo.js +76 -31
- package/dist/tui-core/input-parser.d.ts +1 -0
- package/dist/tui-core/input-parser.js +6 -0
- package/dist/tui-core/style.d.ts +1 -8
- package/dist/tui-core/style.js +3 -110
- package/dist/tui-ui/chrome-view-model.d.ts +1 -1
- package/dist/tui-ui/chrome-view-model.js +22 -27
- package/dist/tui-ui/launch.js +14 -14
- package/dist/tui-ui/layout.d.ts +5 -7
- package/dist/tui-ui/layout.js +129 -124
- package/dist/tui-ui/runner.d.ts +11 -12
- package/dist/tui-ui/runner.js +88 -67
- package/dist/tui-ui/state.d.ts +0 -11
- package/dist/tui-ui/state.js +22 -33
- package/dist/tui-ui/terminal-image.js +22 -4
- package/dist/tui-ui/transcript-inspector-layout.js +6 -3
- package/dist/tui-ui/transcript-inspector.d.ts +1 -0
- package/dist/tui-ui/transcript-inspector.js +7 -1
- package/dist/tui-ui/transcript-layout.js +42 -6
- package/dist/utils/terminal-text.d.ts +11 -0
- package/dist/utils/terminal-text.js +114 -0
- package/docs/cli-guide.md +562 -0
- package/docs/orion.example.yaml +42 -0
- package/docs/readme.md +12 -57
- package/npm-shrinkwrap.json +484 -1855
- package/package.json +13 -63
- package/dist/migration/command.d.ts +0 -9
- package/dist/migration/command.js +0 -100
- package/dist/migration/index.d.ts +0 -7
- package/dist/migration/index.js +0 -14
- package/dist/migration/migrate.d.ts +0 -19
- package/dist/migration/migrate.js +0 -406
- package/dist/migration/types.d.ts +0 -55
- package/dist/migration/types.js +0 -6
- package/dist/services/tool-allowlist.d.ts +0 -110
- package/dist/services/tool-allowlist.js +0 -299
- package/dist/services/yaml-config.d.ts +0 -57
- package/dist/services/yaml-config.js +0 -178
- package/dist/web/cli-options.d.ts +0 -17
- package/dist/web/cli-options.js +0 -51
- package/dist/web/code-review-run-service.d.ts +0 -68
- package/dist/web/code-review-run-service.js +0 -228
- package/dist/web/context-text.d.ts +0 -17
- package/dist/web/context-text.js +0 -40
- package/dist/web/errors.d.ts +0 -6
- package/dist/web/errors.js +0 -13
- package/dist/web/event-hub.d.ts +0 -45
- package/dist/web/event-hub.js +0 -370
- package/dist/web/file-read-service.d.ts +0 -101
- package/dist/web/file-read-service.js +0 -593
- package/dist/web/file-write-service.d.ts +0 -16
- package/dist/web/file-write-service.js +0 -103
- package/dist/web/git-compare-service.d.ts +0 -45
- package/dist/web/git-compare-service.js +0 -160
- package/dist/web/git-diff-document.d.ts +0 -102
- package/dist/web/git-diff-document.js +0 -258
- package/dist/web/git-file-source.d.ts +0 -25
- package/dist/web/git-file-source.js +0 -21
- package/dist/web/git-history-service.d.ts +0 -151
- package/dist/web/git-history-service.js +0 -619
- package/dist/web/git-index-transaction.d.ts +0 -45
- package/dist/web/git-index-transaction.js +0 -174
- package/dist/web/git-patch-builder.d.ts +0 -30
- package/dist/web/git-patch-builder.js +0 -138
- package/dist/web/git-read-model-service.d.ts +0 -452
- package/dist/web/git-read-model-service.js +0 -1833
- package/dist/web/git-version-service.d.ts +0 -79
- package/dist/web/git-version-service.js +0 -279
- package/dist/web/host-daemon.d.ts +0 -70
- package/dist/web/host-daemon.js +0 -237
- package/dist/web/index.d.ts +0 -6
- package/dist/web/index.js +0 -28
- package/dist/web/launch.d.ts +0 -12
- package/dist/web/launch.js +0 -89
- package/dist/web/native-directory-picker.d.ts +0 -63
- package/dist/web/native-directory-picker.js +0 -169
- package/dist/web/protocol.d.ts +0 -705
- package/dist/web/protocol.js +0 -639
- package/dist/web/review-service.d.ts +0 -22
- package/dist/web/review-service.js +0 -68
- package/dist/web/server.d.ts +0 -20
- package/dist/web/server.js +0 -1453
- package/dist/web/session-runtime-registry.d.ts +0 -138
- package/dist/web/session-runtime-registry.js +0 -471
- package/dist/web/terminal-manager.d.ts +0 -156
- package/dist/web/terminal-manager.js +0 -779
- package/dist/web/terminal-server.d.ts +0 -8
- package/dist/web/terminal-server.js +0 -304
- package/dist/web/workbench-controller.d.ts +0 -395
- package/dist/web/workbench-controller.js +0 -3077
- package/dist/web/workspace-discovery.d.ts +0 -92
- package/dist/web/workspace-discovery.js +0 -324
- package/dist/web/workspace-mutation-arbiter.d.ts +0 -54
- package/dist/web/workspace-mutation-arbiter.js +0 -267
- package/dist/web/workspace-open-telemetry.d.ts +0 -55
- package/dist/web/workspace-open-telemetry.js +0 -73
- package/dist/web-client/assets/FilesPanel-iBYj9ZRf.js +0 -1
- package/dist/web-client/assets/GitPanel-D33R_bZr.js +0 -4
- package/dist/web-client/assets/ReviewPanel-C_0upsDk.js +0 -6
- package/dist/web-client/assets/TerminalPanel-C7A8dMNf.js +0 -23
- package/dist/web-client/assets/TerminalPanel-DLuoa74B.css +0 -1
- package/dist/web-client/assets/index-BaOxrwGB.css +0 -1
- package/dist/web-client/assets/index-CqCgJ2ov.js +0 -20
- package/dist/web-client/assets/useAutoNotice-C1qM-_Sg.js +0 -1
- package/dist/web-client/favicon.svg +0 -9
- package/dist/web-client/index.html +0 -17
- package/docs/architecture/agent-mode-permission-contract.md +0 -87
- package/docs/architecture/v0.3.0-web-api.yaml +0 -1340
- package/docs/architecture/v0.3.1-web-api.yaml +0 -2338
- package/docs/architecture/v0.3.2-web-api.yaml +0 -3029
- package/docs/architecture/v0.3.3-web-api.yaml +0 -3205
- package/docs/architecture/v0.3.4-stabilization-contract.md +0 -32
- package/docs/migration/v0.1.9-to-v0.2.0.md +0 -98
- package/docs/migration/v0.2.2-to-v0.3.0-settings.md +0 -114
- package/docs/migration/v0.2.2-to-v0.3.0.md +0 -55
- package/docs/migration/v0.3.0-to-v0.3.1.md +0 -88
- package/docs/migration/v0.3.1-to-v0.3.2.md +0 -94
- package/docs/migration/v0.3.2-to-v0.3.3.md +0 -62
- package/docs/migration/v0.3.3-to-v0.3.4.md +0 -36
- package/docs/orion.example.json +0 -86
- package/docs/plan/v0.2.0-dsh-harness-redesign-plan.md +0 -1234
- package/docs/plan/v0.2.0-release-checklist.md +0 -91
- package/docs/plan/v0.3.0-node-runtime-compatibility-plan.md +0 -57
- package/docs/plan/v0.3.0-settings-integration-plan.md +0 -740
- package/docs/plan/v0.3.0-web-workbench-plan.md +0 -376
- package/docs/plan/v0.3.1-web-workbench-professional-shell-plan.md +0 -848
- package/docs/plan/v0.3.2-web-workbench-layout-and-composer-plan.md +0 -869
- package/docs/plan/v0.3.3-plan.md +0 -1113
- package/docs/plan/v0.3.4-stabilization-plan.md +0 -89
- package/docs/test/v0.3.1-web-workbench-e2e-plan.md +0 -140
- package/docs/test/v0.3.2-web-workbench-e2e-plan.md +0 -100
- package/docs/test/v0.3.3-web-workbench-e2e-plan.md +0 -79
- package/docs/test/v0.3.4-stabilization-e2e-plan.md +0 -54
package/dist/framework/query.js
CHANGED
|
@@ -10,12 +10,13 @@
|
|
|
10
10
|
* chunks directly to stdout via the callback.
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.QueryLoopError = exports.DEFAULT_MAX_MODEL_VISIBLE_TOOL_RESULT_BYTES = exports.DEFAULT_LOOP_BUDGET = void 0;
|
|
13
|
+
exports.QueryLoopError = exports.MIN_MODEL_VISIBLE_TOOL_RESULT_BYTES = exports.DEFAULT_MAX_MODEL_VISIBLE_TOOL_RESULT_BYTES = exports.DEFAULT_LOOP_BUDGET = void 0;
|
|
14
14
|
exports.withLoopFinishReason = withLoopFinishReason;
|
|
15
15
|
exports.createLocalFastPathLoopStats = createLocalFastPathLoopStats;
|
|
16
16
|
exports.createFailedLoopStats = createFailedLoopStats;
|
|
17
17
|
exports.query = query;
|
|
18
18
|
const llm_1 = require("../services/llm");
|
|
19
|
+
const provider_diagnostics_1 = require("../services/provider-diagnostics");
|
|
19
20
|
const tool_1 = require("./tool");
|
|
20
21
|
const strategy_tracker_1 = require("../core/strategy-tracker");
|
|
21
22
|
const auto_compact_1 = require("../services/compact/auto-compact");
|
|
@@ -23,13 +24,17 @@ const fingerprint_1 = require("../services/compact/fingerprint");
|
|
|
23
24
|
const tool_call_groups_1 = require("../services/compact/tool-call-groups");
|
|
24
25
|
const tool_call_orchestrator_1 = require("./tool-call-orchestrator");
|
|
25
26
|
const token_estimate_1 = require("../utils/token-estimate");
|
|
27
|
+
const terminal_text_1 = require("../utils/terminal-text");
|
|
26
28
|
const tool_serializer_1 = require("./tool-serializer");
|
|
27
29
|
const model_context_1 = require("../services/model-context");
|
|
28
30
|
const stop_decision_1 = require("./stop-decision");
|
|
31
|
+
const loop_progress_1 = require("./loop-progress");
|
|
29
32
|
const loop_budget_contract_1 = require("./loop-budget-contract");
|
|
30
33
|
var loop_budget_contract_2 = require("./loop-budget-contract");
|
|
31
34
|
Object.defineProperty(exports, "DEFAULT_LOOP_BUDGET", { enumerable: true, get: function () { return loop_budget_contract_2.DEFAULT_LOOP_BUDGET; } });
|
|
32
35
|
exports.DEFAULT_MAX_MODEL_VISIBLE_TOOL_RESULT_BYTES = 4096;
|
|
36
|
+
/** Bounded recovery visibility after the shared compression allowance is spent. */
|
|
37
|
+
exports.MIN_MODEL_VISIBLE_TOOL_RESULT_BYTES = 2048;
|
|
33
38
|
/** Read-only tools eligible for the fragmentation hint; kept loop-local so Query has no tool registry. */
|
|
34
39
|
const BATCH_READ_ALLOWED_TOOLS = new Set(['git_status', 'list_files', 'glob', 'grep', 'read_file']);
|
|
35
40
|
function isAborted(signal) {
|
|
@@ -87,6 +92,7 @@ const COMPLEX_LOOP_BUDGET = {
|
|
|
87
92
|
maxToolCallsPerUserTurn: 180,
|
|
88
93
|
maxModelVisibleToolBytes: 96 * 1024,
|
|
89
94
|
};
|
|
95
|
+
const TOOL_PRESSURE_COMPACT_RATIO = 0.9;
|
|
90
96
|
class QueryLoopError extends Error {
|
|
91
97
|
constructor(error, stats, aggregateUsage) {
|
|
92
98
|
super(error instanceof Error ? error.message : String(error));
|
|
@@ -147,27 +153,41 @@ function stopDecisionForLoop(stats, finishReason) {
|
|
|
147
153
|
},
|
|
148
154
|
});
|
|
149
155
|
}
|
|
156
|
+
const budgetWithoutProgress = finishReason === 'budget_exceeded' && stats.budgetExhaustedWithoutProgress;
|
|
157
|
+
const missingOutput = finishReason === 'failed' ? stats.missingAssistantOutput : undefined;
|
|
158
|
+
const providerStop = finishReason === 'failed' ? stats.providerStop : undefined;
|
|
150
159
|
const status = finishReason === 'completed'
|
|
151
160
|
? 'completed'
|
|
152
161
|
: finishReason === 'cancelled'
|
|
153
162
|
? 'cancelled'
|
|
154
|
-
: finishReason === 'failed'
|
|
163
|
+
: finishReason === 'failed' || budgetWithoutProgress
|
|
155
164
|
? 'failed'
|
|
156
165
|
: finishReason === 'blocked'
|
|
157
166
|
? 'blocked'
|
|
158
167
|
: 'stopped';
|
|
159
|
-
const reasonCode =
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
+
const reasonCode = providerStop?.code ??
|
|
169
|
+
missingOutput ??
|
|
170
|
+
(finishReason === 'budget_exceeded' ? stats.adaptiveStop : undefined) ??
|
|
171
|
+
(budgetWithoutProgress
|
|
172
|
+
? 'budget_exhausted_without_progress'
|
|
173
|
+
: finishReason === 'budget_exceeded'
|
|
174
|
+
? /LLM request budget/iu.test(stats.budgetExceededReason ?? '')
|
|
175
|
+
? stats.budgetCompactPending
|
|
176
|
+
? 'budget_paused_compact_pending'
|
|
177
|
+
: stats.budgetCompaction === 'disabled'
|
|
178
|
+
? 'context_compact_disabled'
|
|
179
|
+
: 'llm_request_budget'
|
|
180
|
+
: /tool call budget/iu.test(stats.budgetExceededReason ?? '')
|
|
181
|
+
? 'tool_call_budget'
|
|
182
|
+
: /preflight|provider/iu.test(stats.budgetExceededReason ?? '')
|
|
183
|
+
? 'provider_preflight_budget'
|
|
184
|
+
: 'resource_budget'
|
|
185
|
+
: finishReason);
|
|
168
186
|
const resumable = finishReason === 'budget_exceeded' ||
|
|
169
187
|
finishReason === 'completion_gate' ||
|
|
170
|
-
finishReason === 'blocked'
|
|
188
|
+
finishReason === 'blocked' ||
|
|
189
|
+
missingOutput !== undefined ||
|
|
190
|
+
providerStop !== undefined;
|
|
171
191
|
const evidence = [];
|
|
172
192
|
if (finishReason === 'budget_exceeded') {
|
|
173
193
|
evidence.push({
|
|
@@ -176,6 +196,16 @@ function stopDecisionForLoop(stats, finishReason) {
|
|
|
176
196
|
detail: stats.budgetExceededReason ?? 'request resource budget reached',
|
|
177
197
|
});
|
|
178
198
|
}
|
|
199
|
+
if (missingOutput) {
|
|
200
|
+
evidence.push({
|
|
201
|
+
kind: 'provider',
|
|
202
|
+
source: 'query',
|
|
203
|
+
detail: 'The provider returned successfully without visible final assistant text.',
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
if (providerStop) {
|
|
207
|
+
evidence.push({ kind: 'provider', source: 'query', detail: providerStop.message });
|
|
208
|
+
}
|
|
179
209
|
if (stats.lastToolName) {
|
|
180
210
|
evidence.push({
|
|
181
211
|
kind: 'tool_boundary',
|
|
@@ -184,6 +214,24 @@ function stopDecisionForLoop(stats, finishReason) {
|
|
|
184
214
|
});
|
|
185
215
|
}
|
|
186
216
|
const nextActions = [];
|
|
217
|
+
if (providerStop) {
|
|
218
|
+
nextActions.push({ kind: 'resume', label: 'Continue after resolving the provider stop.' });
|
|
219
|
+
}
|
|
220
|
+
if (missingOutput) {
|
|
221
|
+
if (stats.toolCalls > 0) {
|
|
222
|
+
nextActions.push({
|
|
223
|
+
kind: 'inspect',
|
|
224
|
+
label: 'Inspect the tool results already saved for this turn',
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
nextActions.push({ kind: 'retry', label: 'Retry the request or select another model' });
|
|
229
|
+
}
|
|
230
|
+
nextActions.push({
|
|
231
|
+
kind: 'change_input',
|
|
232
|
+
label: 'Ask for a brief checkpoint or a narrower next step',
|
|
233
|
+
});
|
|
234
|
+
}
|
|
187
235
|
for (const action of stats.continuationActions ?? []) {
|
|
188
236
|
if (action === 'reply_continue') {
|
|
189
237
|
nextActions.push({ kind: 'continue', label: 'Continue the same objective', command: '继续' });
|
|
@@ -208,9 +256,14 @@ function stopDecisionForLoop(stats, finishReason) {
|
|
|
208
256
|
disposition: resumable ? 'resume_allowed' : 'finish_scope',
|
|
209
257
|
reason: {
|
|
210
258
|
code: reasonCode,
|
|
211
|
-
message:
|
|
212
|
-
|
|
213
|
-
|
|
259
|
+
message: providerStop?.message ??
|
|
260
|
+
(missingOutput
|
|
261
|
+
? missingAssistantOutputMessage(stats.toolCalls)
|
|
262
|
+
: budgetWithoutProgress
|
|
263
|
+
? (stats.adaptiveStop && stats.budgetExceededReason) || REQUEST_BUDGET_WITHOUT_PROGRESS
|
|
264
|
+
: finishReason === 'budget_exceeded'
|
|
265
|
+
? budgetStopReason(stats)
|
|
266
|
+
: `Request finished with ${finishReason}`),
|
|
214
267
|
},
|
|
215
268
|
evidence,
|
|
216
269
|
nextActions,
|
|
@@ -293,6 +346,10 @@ function resolveLoopBudget(partial) {
|
|
|
293
346
|
return {
|
|
294
347
|
...loop_budget_contract_1.DEFAULT_LOOP_BUDGET,
|
|
295
348
|
...numericOverrides,
|
|
349
|
+
requestPolicy: partial?.requestPolicy ??
|
|
350
|
+
(configOverride && numericOverrides.maxLlmRequestsPerUserTurn !== undefined
|
|
351
|
+
? 'fixed'
|
|
352
|
+
: 'adaptive'),
|
|
296
353
|
profile: isLoopBudgetSource(partial?.profile)
|
|
297
354
|
? partial.profile
|
|
298
355
|
: configOverride
|
|
@@ -306,16 +363,22 @@ function resolveLoopBudget(partial) {
|
|
|
306
363
|
}
|
|
307
364
|
function applyLoopBudgetStats(stats, budget) {
|
|
308
365
|
stats.loopBudgetSource = budget.profile ?? 'default';
|
|
366
|
+
stats.loopBudgetRequestPolicy = budget.requestPolicy;
|
|
309
367
|
stats.loopBudgetBaseProfile =
|
|
310
368
|
budget.baseProfile ?? (budget.profile === 'config' ? 'default' : (budget.profile ?? 'default'));
|
|
311
|
-
stats.loopBudgetMaxLlmRequests =
|
|
369
|
+
stats.loopBudgetMaxLlmRequests =
|
|
370
|
+
budget.requestPolicy === 'adaptive'
|
|
371
|
+
? loop_budget_contract_1.ADAPTIVE_REQUEST_SAFETY_LIMIT
|
|
372
|
+
: budget.maxLlmRequestsPerUserTurn;
|
|
312
373
|
stats.loopBudgetMaxToolCalls = budget.maxToolCallsPerUserTurn;
|
|
313
374
|
stats.loopBudgetMaxReadOnlyFragmentation = budget.maxReadOnlyFragmentation;
|
|
314
375
|
stats.loopBudgetMaxModelVisibleBytes = budget.maxModelVisibleToolBytes;
|
|
315
376
|
stats.loopBudgetConfigOverride = budget.configOverride === true;
|
|
316
377
|
}
|
|
317
378
|
function shouldPromoteDefaultBudget(stats, budget) {
|
|
318
|
-
if (budget.
|
|
379
|
+
if (budget.requestPolicy !== 'adaptive' ||
|
|
380
|
+
budget.configOverride === true ||
|
|
381
|
+
budget.profile !== 'default')
|
|
319
382
|
return false;
|
|
320
383
|
if (stats.llmRequests < budget.maxLlmRequestsPerUserTurn)
|
|
321
384
|
return false;
|
|
@@ -355,26 +418,45 @@ function applyLlmRequestDiagnostics(stats, diagnostics) {
|
|
|
355
418
|
stats.providerFallbackToModel = diagnostics.fallbackToModel;
|
|
356
419
|
}
|
|
357
420
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
'
|
|
362
|
-
'
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
421
|
+
const REQUEST_BUDGET_WITHOUT_PROGRESS = 'Agent loop exhausted its request budget without successful tool work.';
|
|
422
|
+
function missingAssistantOutputMessage(toolCalls) {
|
|
423
|
+
const recovery = toolCalls
|
|
424
|
+
? 'Inspect the recorded tool results and ask for a checkpoint before repeating work.'
|
|
425
|
+
: 'Retry the request, select another model, or ask for a brief checkpoint.';
|
|
426
|
+
return `Model returned no visible response. ${recovery}`;
|
|
427
|
+
}
|
|
428
|
+
function budgetStopReason(stats) {
|
|
429
|
+
const limit = stats.budgetExceededReason ?? 'Request resource budget reached';
|
|
430
|
+
if (stats.budgetCompactPending)
|
|
431
|
+
return `${limit}. A compact checkpoint is pending.`;
|
|
432
|
+
if (stats.budgetCompaction === 'disabled')
|
|
433
|
+
return `${limit}. Auto-compaction is disabled.`;
|
|
434
|
+
if (stats.budgetCompaction === 'unavailable')
|
|
435
|
+
return `${limit}. Compaction did not free enough context.`;
|
|
436
|
+
return limit;
|
|
437
|
+
}
|
|
438
|
+
function budgetExceededEvent(llm, stats, reason, withoutProgress = false) {
|
|
439
|
+
const continuationActions = withoutProgress
|
|
440
|
+
? ['inspect_loop_stats', 'narrow_instruction']
|
|
441
|
+
: ['reply_continue', 'narrow_instruction', 'inspect_loop_stats', 'raise_budget'];
|
|
442
|
+
const continuationHint = withoutProgress
|
|
443
|
+
? 'Inspect /usage and give a narrower next step or ask for a brief checkpoint.'
|
|
444
|
+
: 'Reply `继续` to continue the same objective, give a narrower next step, inspect /usage, or raise agentLoop.budget for intentional long work.';
|
|
366
445
|
return {
|
|
367
446
|
type: 'complete',
|
|
368
|
-
content:
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
447
|
+
content: withoutProgress
|
|
448
|
+
? `${stats.adaptiveStop ? reason : REQUEST_BUDGET_WITHOUT_PROGRESS} Session history was saved. ${continuationHint}`
|
|
449
|
+
: [
|
|
450
|
+
`Agent loop budget reached: ${reason}.`,
|
|
451
|
+
'I stopped this turn to avoid unnecessary model requests and preserved the current session state.',
|
|
452
|
+
'To continue the same objective, reply `继续` or provide the next concrete step.',
|
|
453
|
+
'Use /usage to inspect request/tool counts. For intentional long work, raise agentLoop.budget in orion.yaml.',
|
|
454
|
+
].join('\n'),
|
|
374
455
|
model: llm.getModel(),
|
|
375
456
|
stats: cloneLoopStats({
|
|
376
457
|
...stats,
|
|
377
458
|
budgetExceededReason: reason,
|
|
459
|
+
...(withoutProgress ? { budgetExhaustedWithoutProgress: true } : {}),
|
|
378
460
|
continuationActions,
|
|
379
461
|
continuationHint,
|
|
380
462
|
}, 'budget_exceeded'),
|
|
@@ -414,9 +496,16 @@ function takeUtf8Suffix(text, maxBytes) {
|
|
|
414
496
|
return '';
|
|
415
497
|
let result = '';
|
|
416
498
|
let bytes = 0;
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
499
|
+
for (let index = text.length; index > 0;) {
|
|
500
|
+
const end = index;
|
|
501
|
+
index--;
|
|
502
|
+
const unit = text.charCodeAt(index);
|
|
503
|
+
if (unit >= 0xdc00 && unit <= 0xdfff && index > 0) {
|
|
504
|
+
const previous = text.charCodeAt(index - 1);
|
|
505
|
+
if (previous >= 0xd800 && previous <= 0xdbff)
|
|
506
|
+
index--;
|
|
507
|
+
}
|
|
508
|
+
const char = text.slice(index, end);
|
|
420
509
|
const nextBytes = byteLength(char);
|
|
421
510
|
if (bytes + nextBytes > maxBytes)
|
|
422
511
|
break;
|
|
@@ -425,85 +514,94 @@ function takeUtf8Suffix(text, maxBytes) {
|
|
|
425
514
|
}
|
|
426
515
|
return result;
|
|
427
516
|
}
|
|
428
|
-
function truncateForModel(text, maxBytes) {
|
|
429
|
-
if (
|
|
517
|
+
function truncateForModel(text, maxBytes, fullBytes = byteLength(text)) {
|
|
518
|
+
if (fullBytes <= maxBytes)
|
|
430
519
|
return text;
|
|
431
520
|
const marker = '\n...[truncated]';
|
|
432
521
|
if (maxBytes <= 128) {
|
|
433
522
|
return `${takeUtf8Prefix(text, Math.max(0, maxBytes - byteLength(marker)))}${marker}`;
|
|
434
523
|
}
|
|
435
|
-
const middle = `\n...[truncated ${
|
|
524
|
+
const middle = `\n...[truncated ${fullBytes}B output for model context]...\n`;
|
|
436
525
|
const contentBudget = Math.max(0, maxBytes - byteLength(middle));
|
|
437
526
|
const headBytes = Math.floor(contentBudget * 0.65);
|
|
438
527
|
const tailBytes = contentBudget - headBytes;
|
|
439
528
|
return [takeUtf8Prefix(text, headBytes), middle, takeUtf8Suffix(text, tailBytes)].join('');
|
|
440
529
|
}
|
|
441
|
-
function
|
|
530
|
+
function truncateModelField(text, maxSerializedBytes) {
|
|
531
|
+
const fullBytes = byteLength(text);
|
|
532
|
+
let low = 0;
|
|
533
|
+
let high = Math.min(fullBytes, maxSerializedBytes);
|
|
534
|
+
let result = truncateForModel(text, 0, fullBytes);
|
|
535
|
+
while (low <= high) {
|
|
536
|
+
const middle = Math.floor((low + high) / 2);
|
|
537
|
+
const candidate = truncateForModel(text, middle, fullBytes);
|
|
538
|
+
if (byteLength(JSON.stringify(candidate)) <= maxSerializedBytes) {
|
|
539
|
+
result = candidate;
|
|
540
|
+
low = middle + 1;
|
|
541
|
+
}
|
|
542
|
+
else {
|
|
543
|
+
high = middle - 1;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
return result;
|
|
547
|
+
}
|
|
548
|
+
function summarizeModelVisibleToolResult(executed, maxBytes, budgetRemainingBytes, budgetLimitBytes) {
|
|
442
549
|
const rawBytes = byteLength(executed.result);
|
|
443
550
|
const fullOutputBytes = executed.outputBytes ?? rawBytes;
|
|
444
|
-
if (rawBytes <= maxBytes && !executed.artifactRef) {
|
|
445
|
-
return { result: executed.result, bytes: rawBytes, summarizedBytes: 0 };
|
|
446
|
-
}
|
|
447
551
|
const envelope = (0, tool_serializer_1.parseToolResultEnvelope)(executed.result);
|
|
448
552
|
const output = typeof envelope.output === 'string' ? envelope.output : executed.result;
|
|
449
553
|
const summary = executed.summary || envelope.summary;
|
|
450
|
-
const compactSummary = summary ? truncateForModel(summary, 192) : undefined;
|
|
451
554
|
const rawError = executed.error ?? envelope.error;
|
|
452
|
-
const
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
555
|
+
const budgetMetadata = {
|
|
556
|
+
budgetLimitBytes,
|
|
557
|
+
// This snapshot precedes this result, so its envelope overhead cannot make
|
|
558
|
+
// the diagnostic self-referential. Stats count the full serialized bytes.
|
|
559
|
+
budgetRemainingBytes,
|
|
560
|
+
budgetExhausted: budgetRemainingBytes === 0,
|
|
561
|
+
budgetSnapshot: 'before_result',
|
|
562
|
+
modelVisibleBudgetExceeded: budgetRemainingBytes < maxBytes,
|
|
563
|
+
};
|
|
564
|
+
const fullResult = (0, tool_serializer_1.serializeToolResult)({
|
|
565
|
+
...envelope,
|
|
566
|
+
success: executed.success,
|
|
567
|
+
metadata: { ...envelope.metadata, ...budgetMetadata },
|
|
568
|
+
});
|
|
569
|
+
if (byteLength(fullResult) <= maxBytes) {
|
|
570
|
+
return { result: fullResult, bytes: byteLength(fullResult), summarizedBytes: 0 };
|
|
571
|
+
}
|
|
572
|
+
// Keep a real excerpt, status and a budget signal even after exhaustion. An
|
|
573
|
+
// untrusted tool's arbitrarily large metadata must not displace the excerpt.
|
|
574
|
+
const compactError = rawError ? truncateModelField(rawError, 192) : undefined;
|
|
575
|
+
const minimalError = rawError ? truncateModelField(rawError, 64) : undefined;
|
|
576
|
+
const compactSummary = summary ? truncateModelField(summary, 192) : undefined;
|
|
577
|
+
const serializeCompact = (compactOutput, includeDetails) => (0, tool_serializer_1.serializeToolResult)({
|
|
457
578
|
success: executed.success,
|
|
458
579
|
output: compactOutput,
|
|
459
|
-
error: compactError,
|
|
460
|
-
summary: compactSummary,
|
|
580
|
+
error: includeDetails ? compactError : minimalError,
|
|
581
|
+
summary: includeDetails ? compactSummary : undefined,
|
|
461
582
|
outputBytes: fullOutputBytes,
|
|
462
|
-
artifactRef: executed.artifactRef ?? envelope.artifactRef,
|
|
583
|
+
artifactRef: includeDetails ? (executed.artifactRef ?? envelope.artifactRef) : undefined,
|
|
463
584
|
metadata: {
|
|
464
|
-
...(envelope.metadata ?? {}),
|
|
465
585
|
modelVisibleCompressed: true,
|
|
466
586
|
originalResultBytes: rawBytes,
|
|
587
|
+
...budgetMetadata,
|
|
467
588
|
},
|
|
468
589
|
});
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
outputBudget = Math.max(128, outputBudget - Math.max(compactBytes - maxBytes, 128));
|
|
485
|
-
}
|
|
486
|
-
if (byteLength(compact) > maxBytes) {
|
|
487
|
-
compact = serializeCompact([
|
|
488
|
-
compactSummary
|
|
489
|
-
? `Summary: ${compactSummary}`
|
|
490
|
-
: 'Tool output was summarized for model context.',
|
|
491
|
-
artifactText.trim(),
|
|
492
|
-
`Output body omitted from model context (${fullOutputBytes}B total).`,
|
|
493
|
-
]
|
|
494
|
-
.filter(Boolean)
|
|
495
|
-
.join('\n'));
|
|
496
|
-
}
|
|
497
|
-
if (byteLength(compact) > maxBytes) {
|
|
498
|
-
compact = (0, tool_serializer_1.serializeToolResult)({
|
|
499
|
-
success: executed.success,
|
|
500
|
-
output: `Tool result omitted from model context (${fullOutputBytes}B total).`,
|
|
501
|
-
outputBytes: fullOutputBytes,
|
|
502
|
-
metadata: {
|
|
503
|
-
modelVisibleCompressed: true,
|
|
504
|
-
originalResultBytes: rawBytes,
|
|
505
|
-
},
|
|
506
|
-
});
|
|
590
|
+
const includeDetails = byteLength(serializeCompact(truncateForModel(output, 128), true)) <= maxBytes;
|
|
591
|
+
const outputBytes = byteLength(output);
|
|
592
|
+
let low = 0;
|
|
593
|
+
let high = Math.min(outputBytes, maxBytes);
|
|
594
|
+
let compact = serializeCompact(truncateForModel(output, 0, outputBytes), includeDetails);
|
|
595
|
+
while (low <= high) {
|
|
596
|
+
const middle = Math.floor((low + high) / 2);
|
|
597
|
+
const candidate = serializeCompact(truncateForModel(output, middle, outputBytes), includeDetails);
|
|
598
|
+
if (byteLength(candidate) <= maxBytes) {
|
|
599
|
+
compact = candidate;
|
|
600
|
+
low = middle + 1;
|
|
601
|
+
}
|
|
602
|
+
else {
|
|
603
|
+
high = middle - 1;
|
|
604
|
+
}
|
|
507
605
|
}
|
|
508
606
|
const bytes = byteLength(compact);
|
|
509
607
|
return {
|
|
@@ -512,25 +610,6 @@ function summarizeModelVisibleToolResult(executed, maxBytes) {
|
|
|
512
610
|
summarizedBytes: Math.max(0, fullOutputBytes - bytes),
|
|
513
611
|
};
|
|
514
612
|
}
|
|
515
|
-
function omitModelVisibleToolResult(executed, maxAggregateBytes) {
|
|
516
|
-
const fullBytes = executed.outputBytes ?? byteLength(executed.result);
|
|
517
|
-
const compact = (0, tool_serializer_1.serializeToolResult)({
|
|
518
|
-
success: executed.success,
|
|
519
|
-
output: `Tool result omitted from model context because the per-turn model-visible tool budget (${maxAggregateBytes}B) was reached.`,
|
|
520
|
-
outputBytes: fullBytes,
|
|
521
|
-
artifactRef: executed.artifactRef,
|
|
522
|
-
metadata: {
|
|
523
|
-
modelVisibleCompressed: true,
|
|
524
|
-
modelVisibleBudgetExceeded: true,
|
|
525
|
-
},
|
|
526
|
-
});
|
|
527
|
-
const bytes = byteLength(compact);
|
|
528
|
-
return {
|
|
529
|
-
result: compact,
|
|
530
|
-
bytes,
|
|
531
|
-
summarizedBytes: Math.max(0, fullBytes - bytes),
|
|
532
|
-
};
|
|
533
|
-
}
|
|
534
613
|
function queryCompactCommit(mode, result, before, after, uncompactedHistory, prepareSource, semanticHarnessState) {
|
|
535
614
|
return {
|
|
536
615
|
mode,
|
|
@@ -578,6 +657,7 @@ function publishContextUsage(params, autoCompact, modelId, usedTokens, source =
|
|
|
578
657
|
usedTokens,
|
|
579
658
|
source,
|
|
580
659
|
outputReserveTokens: stats.outputReserveTokens,
|
|
660
|
+
contextWindow: params.llm.getContextWindow?.(),
|
|
581
661
|
warningThreshold: stats.preCompactThreshold,
|
|
582
662
|
autoCompactThreshold: stats.threshold,
|
|
583
663
|
autoCompactEnabled: stats.enabled,
|
|
@@ -672,6 +752,7 @@ async function* query(params) {
|
|
|
672
752
|
harness, input, maxParallelToolCalls = 6, } = params;
|
|
673
753
|
let turn = 0;
|
|
674
754
|
let consecutiveCompletionGateBlocks = 0;
|
|
755
|
+
let successfulToolCalls = 0;
|
|
675
756
|
const stats = createLoopStats();
|
|
676
757
|
let pendingCompact;
|
|
677
758
|
const uncompactedMessages = messages.map(message => ({ ...message }));
|
|
@@ -705,12 +786,30 @@ async function* query(params) {
|
|
|
705
786
|
let loopBudget = resolveLoopBudget({
|
|
706
787
|
...params.loopBudget,
|
|
707
788
|
...(params.loopBudget?.maxLlmRequestsPerUserTurn === undefined && legacyRequestBudget
|
|
708
|
-
? { maxLlmRequestsPerUserTurn: legacyRequestBudget }
|
|
789
|
+
? { maxLlmRequestsPerUserTurn: legacyRequestBudget, requestPolicy: 'fixed' }
|
|
709
790
|
: {}),
|
|
710
791
|
});
|
|
792
|
+
if (params.allowBudgetRecovery === false)
|
|
793
|
+
loopBudget = { ...loopBudget, requestPolicy: 'fixed' };
|
|
711
794
|
applyLoopBudgetStats(stats, loopBudget);
|
|
795
|
+
const progress = loopBudget.requestPolicy === 'adaptive'
|
|
796
|
+
? new loop_progress_1.LoopProgress(params.toolContext?.cwd ?? process.cwd())
|
|
797
|
+
: undefined;
|
|
798
|
+
let nextProgressCheckpoint = loopBudget.maxLlmRequestsPerUserTurn;
|
|
712
799
|
const maxModelVisibleToolResultBytes = Math.max(512, params.maxModelVisibleToolResultBytes ?? exports.DEFAULT_MAX_MODEL_VISIBLE_TOOL_RESULT_BYTES);
|
|
713
800
|
const fragmentedReadOnlyTools = new Set(BATCH_READ_ALLOWED_TOOLS);
|
|
801
|
+
function goalTokenBudgetStop() {
|
|
802
|
+
if (params.remainingGoalTokens === undefined)
|
|
803
|
+
return undefined;
|
|
804
|
+
const usage = aggregateUsage ?? { promptTokens: 0, completionTokens: 0 };
|
|
805
|
+
const used = usage.promptTokens + usage.completionTokens;
|
|
806
|
+
if (used < params.remainingGoalTokens)
|
|
807
|
+
return undefined;
|
|
808
|
+
return attachCompactCommit(budgetExceededEvent(llm, stats, 'Goal token allowance reached'), pendingCompact, messages, usage);
|
|
809
|
+
}
|
|
810
|
+
function requestBudgetStop() {
|
|
811
|
+
return attachCompactCommit(budgetExceededEvent(llm, { ...stats, ...(pendingCompact ? { budgetCompactPending: true } : {}) }, `LLM request budget ${loopBudget.maxLlmRequestsPerUserTurn} reached`, successfulToolCalls === 0 && consecutiveCompletionGateBlocks === 0), pendingCompact, messages, aggregateUsage);
|
|
812
|
+
}
|
|
714
813
|
// 无限循环,依赖安全机制停止
|
|
715
814
|
while (true) {
|
|
716
815
|
turn++;
|
|
@@ -719,12 +818,85 @@ async function* query(params) {
|
|
|
719
818
|
yield attachCompactCommit(cancelledCompleteEvent(llm, stats), pendingCompact, messages, aggregateUsage);
|
|
720
819
|
return;
|
|
721
820
|
}
|
|
722
|
-
|
|
821
|
+
const goalBudgetBeforeRequest = goalTokenBudgetStop();
|
|
822
|
+
if (goalBudgetBeforeRequest) {
|
|
823
|
+
yield goalBudgetBeforeRequest;
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
const planStop = params.checkTaskPlanStop?.();
|
|
827
|
+
if (planStop) {
|
|
828
|
+
const finish = cloneLoopStats(stats, 'completion_gate');
|
|
829
|
+
const decision = finish.stopDecision;
|
|
830
|
+
finish.stopDecision = {
|
|
831
|
+
...decision,
|
|
832
|
+
status: planStop.code === 'task_step_blocked' ? 'blocked' : 'stopped',
|
|
833
|
+
reason: { code: planStop.code, message: planStop.message },
|
|
834
|
+
nextActions: [
|
|
835
|
+
{ kind: 'inspect', label: 'Inspect the current checklist', command: '/harness explain' },
|
|
836
|
+
{ kind: 'continue', label: 'Continue the current task', command: '继续' },
|
|
837
|
+
],
|
|
838
|
+
};
|
|
839
|
+
yield attachCompactCommit({ type: 'complete', content: planStop.message, model: llm.getModel(), stats: finish }, pendingCompact, messages, aggregateUsage);
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
if (progress?.recentlyAdvanced(stats.llmRequests) &&
|
|
843
|
+
shouldPromoteDefaultBudget(stats, loopBudget)) {
|
|
723
844
|
loopBudget = promoteDefaultBudgetToComplex(loopBudget);
|
|
724
845
|
applyLoopBudgetStats(stats, loopBudget);
|
|
725
846
|
}
|
|
726
|
-
if (
|
|
727
|
-
|
|
847
|
+
if (progress) {
|
|
848
|
+
const checkpoint = progress.checkpoint(stats.llmRequests);
|
|
849
|
+
const activeStep = checkpoint !== 'working' && params.checkTaskPlanStop
|
|
850
|
+
? harness?.toJSON().taskTodos?.find(todo => todo.status === 'in_progress')?.content
|
|
851
|
+
: undefined;
|
|
852
|
+
const safetyLimitReached = stats.llmRequests >= loop_budget_contract_1.ADAPTIVE_REQUEST_SAFETY_LIMIT;
|
|
853
|
+
if (safetyLimitReached || checkpoint === 'stop') {
|
|
854
|
+
const adaptiveStop = safetyLimitReached
|
|
855
|
+
? 'request_safety_limit'
|
|
856
|
+
: 'no_progress_after_recovery';
|
|
857
|
+
const reason = safetyLimitReached
|
|
858
|
+
? `Adaptive loop reached its emergency ceiling of ${loop_budget_contract_1.ADAPTIVE_REQUEST_SAFETY_LIMIT} model requests`
|
|
859
|
+
: activeStep
|
|
860
|
+
? `The checklist step “${activeStep}” did not produce new evidence after a recovery attempt.`
|
|
861
|
+
: 'No new tool evidence was observed after attempting a narrower recovery step.';
|
|
862
|
+
yield attachCompactCommit(budgetExceededEvent(llm, { ...stats, adaptiveStop }, reason, !safetyLimitReached), pendingCompact, messages, aggregateUsage);
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
865
|
+
if (checkpoint === 'recover') {
|
|
866
|
+
appendMessage({
|
|
867
|
+
role: 'system',
|
|
868
|
+
content: activeStep
|
|
869
|
+
? `[Orion Code loop] The current checklist step is “${activeStep}”. Try a materially different, bounded action that addresses this step and report the observed blocker if it remains.`
|
|
870
|
+
: '[Orion Code loop] No new tool evidence was observed recently. Try one materially different, bounded check that advances the user objective, or report the verified blocker without repeating earlier calls.',
|
|
871
|
+
});
|
|
872
|
+
yield {
|
|
873
|
+
type: 'budget_recovery',
|
|
874
|
+
additionalRequests: loop_progress_1.ADAPTIVE_CHECKPOINT_REQUESTS,
|
|
875
|
+
reason: 'recovery',
|
|
876
|
+
};
|
|
877
|
+
}
|
|
878
|
+
else if (stats.llmRequests >= nextProgressCheckpoint &&
|
|
879
|
+
progress.recentlyAdvanced(stats.llmRequests)) {
|
|
880
|
+
yield {
|
|
881
|
+
type: 'budget_recovery',
|
|
882
|
+
additionalRequests: loop_progress_1.ADAPTIVE_CHECKPOINT_REQUESTS,
|
|
883
|
+
reason: 'progress',
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
if (stats.llmRequests >= nextProgressCheckpoint) {
|
|
887
|
+
nextProgressCheckpoint = stats.llmRequests + loop_progress_1.ADAPTIVE_CHECKPOINT_REQUESTS;
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
const requestLimitReached = !progress && stats.llmRequests >= loopBudget.maxLlmRequestsPerUserTurn;
|
|
891
|
+
const toolOutputPressure = params.allowBudgetRecovery === true &&
|
|
892
|
+
successfulToolCalls > 0 &&
|
|
893
|
+
consecutiveCompletionGateBlocks === 0 &&
|
|
894
|
+
stats.toolCalls < loopBudget.maxToolCallsPerUserTurn &&
|
|
895
|
+
stats.modelVisibleToolBytes >=
|
|
896
|
+
Math.ceil(loopBudget.maxModelVisibleToolBytes * TOOL_PRESSURE_COMPACT_RATIO);
|
|
897
|
+
const shouldTryBudgetCompact = toolOutputPressure && !pendingCompact && stats.budgetCompaction === undefined;
|
|
898
|
+
if (requestLimitReached && !shouldTryBudgetCompact) {
|
|
899
|
+
yield requestBudgetStop();
|
|
728
900
|
return;
|
|
729
901
|
}
|
|
730
902
|
const resolvedStep = params.resolveStep
|
|
@@ -741,13 +913,15 @@ async function* query(params) {
|
|
|
741
913
|
harness?.updateCapabilityProfile?.({
|
|
742
914
|
modelId: llm.getModel(),
|
|
743
915
|
contextWindow: (0, model_context_1.getModelContextWindow)(llm.getModel()),
|
|
744
|
-
permissionMode:
|
|
745
|
-
toolConfirmation:
|
|
916
|
+
permissionMode: 'default',
|
|
917
|
+
toolConfirmation: 'allow',
|
|
746
918
|
tools: tools.map(tool => tool.name),
|
|
747
919
|
});
|
|
748
920
|
// Request start
|
|
749
|
-
|
|
750
|
-
|
|
921
|
+
if (!requestLimitReached) {
|
|
922
|
+
yield { type: 'request_start', model: llm.getModel(), turn };
|
|
923
|
+
stats.turnsStarted = turn;
|
|
924
|
+
}
|
|
751
925
|
const coordinator = params.compactCoordinator;
|
|
752
926
|
coordinator?.configure({
|
|
753
927
|
modelId: llm.getModel(),
|
|
@@ -766,32 +940,56 @@ async function* query(params) {
|
|
|
766
940
|
});
|
|
767
941
|
// Stream the LLM response. Harness context is injected into a cloned
|
|
768
942
|
// request payload so the durable conversation history stays clean.
|
|
769
|
-
let requestMessages = harness
|
|
770
|
-
? harness.assembleMessages(messages, {
|
|
771
|
-
input,
|
|
772
|
-
tools: tools.map(tool => ({ name: tool.name, description: tool.description })),
|
|
773
|
-
})
|
|
774
|
-
: messages;
|
|
775
|
-
let requestEstimatedTokens = (0, token_estimate_1.estimateMessagesTokens)(requestMessages);
|
|
776
|
-
const predictedTokens = autoCompact.adjustTokenEstimate(requestEstimatedTokens, llm.getModel());
|
|
777
|
-
const contextBeforePredictiveCompact = publishContextUsage(params, autoCompact, llm.getModel(), predictedTokens, autoCompact.hasProviderCalibration(llm.getModel()) ? 'provider_adjusted' : 'estimated');
|
|
778
|
-
const preCompactObjective = harness?.getCapsule()?.contract?.objective;
|
|
779
943
|
const compactToolDescriptions = tools.map(tool => ({
|
|
780
944
|
name: tool.name,
|
|
781
945
|
description: tool.description,
|
|
782
946
|
}));
|
|
947
|
+
const assembleRequest = () => harness?.assembleMessages(messages, { input, tools: compactToolDescriptions }) ?? messages;
|
|
948
|
+
let requestMessages = assembleRequest();
|
|
949
|
+
let requestEstimatedTokens = (0, token_estimate_1.estimateMessagesTokens)(requestMessages);
|
|
950
|
+
const predictedTokens = autoCompact.adjustTokenEstimate(requestEstimatedTokens, llm.getModel());
|
|
951
|
+
const contextBeforePredictiveCompact = publishContextUsage(params, autoCompact, llm.getModel(), predictedTokens, autoCompact.hasProviderCalibration(llm.getModel()) ? 'provider_adjusted' : 'estimated');
|
|
952
|
+
const preCompactObjective = harness?.getCapsule()?.contract?.objective;
|
|
783
953
|
const predictiveStats = autoCompact.getStats();
|
|
784
|
-
|
|
954
|
+
const predictiveCompactDue = predictiveStats.enabled &&
|
|
785
955
|
predictedTokens / Math.max(1, predictiveStats.safeInputBudget) >=
|
|
786
|
-
predictiveStats.predictiveCompactThreshold
|
|
956
|
+
predictiveStats.predictiveCompactThreshold;
|
|
957
|
+
const budgetCompactDue = shouldTryBudgetCompact && predictiveStats.enabled && !predictiveCompactDue;
|
|
958
|
+
if (predictiveCompactDue || budgetCompactDue)
|
|
787
959
|
captureCompactPrepareSource();
|
|
960
|
+
if (shouldTryBudgetCompact && !predictiveStats.enabled)
|
|
961
|
+
stats.budgetCompaction = 'disabled';
|
|
962
|
+
let candidatePromptAssembled = false;
|
|
963
|
+
const validatePreCompact = (result) => {
|
|
964
|
+
candidatePromptAssembled = true;
|
|
965
|
+
return validateFinalCompactRequest(result, autoCompact, llm.getModel(), harness, compactToolDescriptions, input);
|
|
966
|
+
};
|
|
967
|
+
const preCompactAttempt = budgetCompactDue
|
|
968
|
+
? await autoCompact.compactForToolPressure(messages, predictedTokens, validatePreCompact, abortSignal)
|
|
969
|
+
: await autoCompact.checkPredictiveCompactOutcome(messages, predictedTokens, validatePreCompact, abortSignal);
|
|
970
|
+
if (budgetCompactDue) {
|
|
971
|
+
stats.budgetCompaction =
|
|
972
|
+
preCompactAttempt.status === 'compacted' ? 'compacted' : 'unavailable';
|
|
973
|
+
if (stats.budgetCompaction === 'unavailable') {
|
|
974
|
+
compactPrepareSource = undefined;
|
|
975
|
+
// The speculative validator may have written diagnostics for a prompt
|
|
976
|
+
// the provider will never receive. Restore the original assembly.
|
|
977
|
+
if (candidatePromptAssembled && harness && !requestLimitReached) {
|
|
978
|
+
requestMessages = assembleRequest();
|
|
979
|
+
requestEstimatedTokens = (0, token_estimate_1.estimateMessagesTokens)(requestMessages);
|
|
980
|
+
}
|
|
981
|
+
}
|
|
788
982
|
}
|
|
789
|
-
|
|
790
|
-
|
|
983
|
+
if (isAborted(abortSignal)) {
|
|
984
|
+
yield attachCompactCommit(cancelledCompleteEvent(llm, stats), pendingCompact, messages, aggregateUsage);
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
if (!budgetCompactDue && preCompactAttempt.status === 'paused') {
|
|
791
988
|
yield attachCompactCommit(compactPausedEvent(llm, stats, preCompactAttempt.failure), pendingCompact, messages, aggregateUsage);
|
|
792
989
|
return;
|
|
793
990
|
}
|
|
794
|
-
if (
|
|
991
|
+
if (!budgetCompactDue &&
|
|
992
|
+
(preCompactAttempt.status === 'duplicate' || preCompactAttempt.status === 'rejected')) {
|
|
795
993
|
yield attachCompactCommit(compactPausedEvent(llm, stats, failureForUnchangedCompactAttempt(preCompactAttempt, autoCompact)), pendingCompact, messages, aggregateUsage);
|
|
796
994
|
return;
|
|
797
995
|
}
|
|
@@ -800,12 +998,7 @@ async function* query(params) {
|
|
|
800
998
|
stats.compactTrigger = 'pre_turn';
|
|
801
999
|
messages.length = 0;
|
|
802
1000
|
messages.push(...preCompacted);
|
|
803
|
-
requestMessages =
|
|
804
|
-
? harness.assembleMessages(messages, {
|
|
805
|
-
input,
|
|
806
|
-
tools: tools.map(tool => ({ name: tool.name, description: tool.description })),
|
|
807
|
-
})
|
|
808
|
-
: messages;
|
|
1001
|
+
requestMessages = assembleRequest();
|
|
809
1002
|
const postCompactObjective = harness?.getCapsule()?.contract?.objective;
|
|
810
1003
|
if (preCompactObjective &&
|
|
811
1004
|
postCompactObjective &&
|
|
@@ -826,6 +1019,10 @@ async function* query(params) {
|
|
|
826
1019
|
after: contextAfterPredictiveCompact,
|
|
827
1020
|
});
|
|
828
1021
|
}
|
|
1022
|
+
if (requestLimitReached) {
|
|
1023
|
+
yield requestBudgetStop();
|
|
1024
|
+
return;
|
|
1025
|
+
}
|
|
829
1026
|
const assemblyStats = harness?.toJSON().promptAssemblyStats;
|
|
830
1027
|
if (assemblyStats) {
|
|
831
1028
|
yield {
|
|
@@ -875,11 +1072,18 @@ async function* query(params) {
|
|
|
875
1072
|
toolExecutor = bound.toolExecutor;
|
|
876
1073
|
}
|
|
877
1074
|
let response;
|
|
1075
|
+
let sawReasoning = false;
|
|
1076
|
+
const holdAssistant = params.holdAssistantUntilCompletionCheck?.() === true;
|
|
878
1077
|
try {
|
|
879
1078
|
stats.llmRequests++;
|
|
880
|
-
response = await llm.chatStream(requestMessages,
|
|
881
|
-
|
|
882
|
-
|
|
1079
|
+
response = await llm.chatStream(requestMessages, {
|
|
1080
|
+
...streamCallbacks,
|
|
1081
|
+
...(holdAssistant ? { onChunk: undefined } : {}),
|
|
1082
|
+
onThinkingText: text => {
|
|
1083
|
+
sawReasoning || (sawReasoning = text.trim().length > 0);
|
|
1084
|
+
streamCallbacks?.onThinkingText?.(text);
|
|
1085
|
+
},
|
|
1086
|
+
}, openaiTools, { abortSignal });
|
|
883
1087
|
applyLlmRequestDiagnostics(stats, getLlmRequestDiagnostics(llm));
|
|
884
1088
|
if (response.usage) {
|
|
885
1089
|
autoCompact.recordProviderUsage(requestEstimatedTokens, response.usage.promptTokens, response.model || llm.getModel());
|
|
@@ -887,11 +1091,31 @@ async function* query(params) {
|
|
|
887
1091
|
}
|
|
888
1092
|
catch (error) {
|
|
889
1093
|
applyLlmRequestDiagnostics(stats, getLlmRequestDiagnostics(llm));
|
|
1094
|
+
if (isAborted(abortSignal)) {
|
|
1095
|
+
yield attachCompactCommit(cancelledCompleteEvent(llm, stats), pendingCompact, messages, aggregateUsage);
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
890
1098
|
if (error instanceof llm_1.ProviderRequestPreflightError) {
|
|
891
1099
|
stats.llmRequests = Math.max(0, stats.llmRequests - 1);
|
|
892
1100
|
yield attachCompactCommit(budgetExceededEvent(llm, stats, error.message), pendingCompact, messages, aggregateUsage);
|
|
893
1101
|
return;
|
|
894
1102
|
}
|
|
1103
|
+
if (error instanceof provider_diagnostics_1.LLMProviderError) {
|
|
1104
|
+
stats.providerStop = {
|
|
1105
|
+
code: `provider_${error.diagnostic.type}`,
|
|
1106
|
+
message: (0, provider_diagnostics_1.formatProviderErrorMessage)({
|
|
1107
|
+
...error.diagnostic,
|
|
1108
|
+
code: undefined,
|
|
1109
|
+
}),
|
|
1110
|
+
};
|
|
1111
|
+
yield attachCompactCommit({
|
|
1112
|
+
type: 'complete',
|
|
1113
|
+
content: stats.providerStop.message,
|
|
1114
|
+
model: llm.getModel(),
|
|
1115
|
+
stats: cloneLoopStats(stats, 'failed'),
|
|
1116
|
+
}, pendingCompact, messages, aggregateUsage);
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
895
1119
|
throw new QueryLoopError(error, cloneLoopStats(stats, 'failed'), aggregateUsage);
|
|
896
1120
|
}
|
|
897
1121
|
// Account every successful model request. Tool-calling turns are billable
|
|
@@ -912,6 +1136,38 @@ async function* query(params) {
|
|
|
912
1136
|
yield attachCompactCommit(cancelledCompleteEvent(llm, stats), pendingCompact, messages, aggregateUsage);
|
|
913
1137
|
return;
|
|
914
1138
|
}
|
|
1139
|
+
const visibleContent = (0, terminal_text_1.hasVisibleAssistantText)(response.content) ? response.content : '';
|
|
1140
|
+
if (response.finishReason === 'length' || response.finishReason === 'content_filter') {
|
|
1141
|
+
if (visibleContent) {
|
|
1142
|
+
appendMessage({ role: 'assistant', content: visibleContent });
|
|
1143
|
+
if (holdAssistant)
|
|
1144
|
+
streamCallbacks?.onChunk?.(visibleContent);
|
|
1145
|
+
yield { type: 'message', role: 'assistant', content: visibleContent };
|
|
1146
|
+
}
|
|
1147
|
+
stats.providerStop =
|
|
1148
|
+
response.finishReason === 'length'
|
|
1149
|
+
? {
|
|
1150
|
+
code: 'provider_output_limit',
|
|
1151
|
+
message: 'The provider reached its output token limit. Continue with a narrower request.',
|
|
1152
|
+
}
|
|
1153
|
+
: {
|
|
1154
|
+
code: 'provider_content_filter',
|
|
1155
|
+
message: 'The provider stopped generation at its content filter.',
|
|
1156
|
+
};
|
|
1157
|
+
yield attachCompactCommit({
|
|
1158
|
+
type: 'complete',
|
|
1159
|
+
content: stats.providerStop.message,
|
|
1160
|
+
model: response.model || llm.getModel(),
|
|
1161
|
+
stats: cloneLoopStats(stats, 'failed'),
|
|
1162
|
+
}, pendingCompact, messages, aggregateUsage);
|
|
1163
|
+
return;
|
|
1164
|
+
}
|
|
1165
|
+
const goalBudgetAfterRequest = goalTokenBudgetStop();
|
|
1166
|
+
if (goalBudgetAfterRequest) {
|
|
1167
|
+
// The crossing response is billable, but its proposed tools were never admitted.
|
|
1168
|
+
yield goalBudgetAfterRequest;
|
|
1169
|
+
return;
|
|
1170
|
+
}
|
|
915
1171
|
// Handle tool calls
|
|
916
1172
|
if (response.toolCalls && response.toolCalls.length > 0) {
|
|
917
1173
|
const toolCalls = response.toolCalls;
|
|
@@ -923,14 +1179,16 @@ async function* query(params) {
|
|
|
923
1179
|
// requests never inherit unresolved tool calls if this turn is stopped.
|
|
924
1180
|
const assistantMsg = {
|
|
925
1181
|
role: 'assistant',
|
|
926
|
-
content:
|
|
1182
|
+
content: visibleContent,
|
|
927
1183
|
tool_calls: toolCalls,
|
|
928
1184
|
};
|
|
929
1185
|
appendMessage(assistantMsg);
|
|
930
|
-
harness?.recordAssistantResponse(response);
|
|
1186
|
+
harness?.recordAssistantResponse({ ...response, content: visibleContent });
|
|
1187
|
+
if (holdAssistant && visibleContent)
|
|
1188
|
+
streamCallbacks?.onChunk?.(visibleContent);
|
|
931
1189
|
yield {
|
|
932
1190
|
type: 'assistant_tool_calls',
|
|
933
|
-
content:
|
|
1191
|
+
content: visibleContent,
|
|
934
1192
|
toolCalls,
|
|
935
1193
|
};
|
|
936
1194
|
const preparedCalls = (0, tool_call_orchestrator_1.prepareToolCalls)({
|
|
@@ -982,10 +1240,9 @@ async function* query(params) {
|
|
|
982
1240
|
}
|
|
983
1241
|
const { prepared } = executed;
|
|
984
1242
|
const { tc, args, attemptId } = prepared;
|
|
985
|
-
const remainingModelVisibleBytes = loopBudget.maxModelVisibleToolBytes - stats.modelVisibleToolBytes;
|
|
986
|
-
const
|
|
987
|
-
|
|
988
|
-
: summarizeModelVisibleToolResult(executed, Math.min(maxModelVisibleToolResultBytes, remainingModelVisibleBytes));
|
|
1243
|
+
const remainingModelVisibleBytes = Math.max(0, loopBudget.maxModelVisibleToolBytes - stats.modelVisibleToolBytes);
|
|
1244
|
+
const visibilityFloor = Math.min(exports.MIN_MODEL_VISIBLE_TOOL_RESULT_BYTES, maxModelVisibleToolResultBytes);
|
|
1245
|
+
const modelVisible = summarizeModelVisibleToolResult(executed, Math.max(visibilityFloor, Math.min(maxModelVisibleToolResultBytes, remainingModelVisibleBytes)), remainingModelVisibleBytes, loopBudget.maxModelVisibleToolBytes);
|
|
989
1246
|
stats.toolResultBytes += executed.outputBytes ?? byteLength(executed.result);
|
|
990
1247
|
stats.modelVisibleToolBytes += modelVisible.bytes;
|
|
991
1248
|
stats.summarizedBytes += modelVisible.summarizedBytes;
|
|
@@ -995,6 +1252,8 @@ async function* query(params) {
|
|
|
995
1252
|
.trim()
|
|
996
1253
|
.slice(0, 240);
|
|
997
1254
|
stats.lastToolSuccess = executed.success;
|
|
1255
|
+
if (executed.success)
|
|
1256
|
+
successfulToolCalls++;
|
|
998
1257
|
strategyTracker.recordResult(attemptId, executed.strategyResult, executed.strategyError, executed.duration);
|
|
999
1258
|
harness?.recordToolResult({
|
|
1000
1259
|
name: tc.function.name,
|
|
@@ -1004,10 +1263,31 @@ async function* query(params) {
|
|
|
1004
1263
|
success: executed.success,
|
|
1005
1264
|
error: executed.error,
|
|
1006
1265
|
summary: executed.summary,
|
|
1266
|
+
verification: executed.verification,
|
|
1267
|
+
toolReceiptDigest: executed.toolReceiptDigest,
|
|
1268
|
+
changedFile: executed.changedFile,
|
|
1269
|
+
readOnly: prepared.tool?.isReadOnly?.(args) === true,
|
|
1007
1270
|
});
|
|
1008
|
-
if (
|
|
1271
|
+
if (progress &&
|
|
1272
|
+
prepared.tool &&
|
|
1273
|
+
executed.resultTrust === 'structured' &&
|
|
1274
|
+
executed.success &&
|
|
1275
|
+
tc.function.name !== 'batch_read' &&
|
|
1276
|
+
(!executed.toolReceiptDigest || !prepared.tool.isFileEdit?.(args) || executed.changedFile)) {
|
|
1277
|
+
progress.observe({
|
|
1278
|
+
name: tc.function.name,
|
|
1279
|
+
args,
|
|
1280
|
+
output: (0, tool_serializer_1.parseToolResultEnvelope)(executed.result).output ?? '',
|
|
1281
|
+
fileEdit: prepared.tool.isFileEdit?.(args) === true,
|
|
1282
|
+
assertion: executed.externalAssertion,
|
|
1283
|
+
}, stats.llmRequests);
|
|
1284
|
+
}
|
|
1285
|
+
if ((harness || progress) && tc.function.name === 'batch_read' && prepared.tool) {
|
|
1009
1286
|
for (const step of parseBatchReadEvidenceSteps(executed.result)) {
|
|
1010
|
-
|
|
1287
|
+
if (step.success) {
|
|
1288
|
+
progress?.observe({ name: step.tool, args: step.args, output: step.output }, stats.llmRequests);
|
|
1289
|
+
}
|
|
1290
|
+
harness?.recordToolResult({
|
|
1011
1291
|
name: step.tool,
|
|
1012
1292
|
args: step.args,
|
|
1013
1293
|
result: JSON.stringify({
|
|
@@ -1132,12 +1412,27 @@ async function* query(params) {
|
|
|
1132
1412
|
// Continue to next turn
|
|
1133
1413
|
continue;
|
|
1134
1414
|
}
|
|
1415
|
+
// A clean provider stop may consist entirely of reasoning or invisible text.
|
|
1416
|
+
// Do not persist it or hand it to the completion gate as a final answer.
|
|
1417
|
+
if (!visibleContent) {
|
|
1418
|
+
stats.missingAssistantOutput =
|
|
1419
|
+
response.content.length === 0 && !sawReasoning ? 'empty_output' : 'no_visible_output';
|
|
1420
|
+
yield attachCompactCommit({
|
|
1421
|
+
type: 'complete',
|
|
1422
|
+
content: missingAssistantOutputMessage(stats.toolCalls),
|
|
1423
|
+
model: response.model || llm.getModel(),
|
|
1424
|
+
stats: cloneLoopStats(stats, 'failed'),
|
|
1425
|
+
}, pendingCompact, messages, aggregateUsage);
|
|
1426
|
+
return;
|
|
1427
|
+
}
|
|
1135
1428
|
const assistantMsg = {
|
|
1136
1429
|
role: 'assistant',
|
|
1137
1430
|
content: response.content,
|
|
1138
1431
|
};
|
|
1139
|
-
|
|
1140
|
-
|
|
1432
|
+
if (!holdAssistant) {
|
|
1433
|
+
appendMessage(assistantMsg);
|
|
1434
|
+
harness?.recordAssistantResponse(response);
|
|
1435
|
+
}
|
|
1141
1436
|
// No tool calls — done, unless the harness requires one more pass.
|
|
1142
1437
|
const completionGate = harness?.beforeComplete();
|
|
1143
1438
|
if (completionGate && !completionGate.canComplete) {
|
|
@@ -1163,6 +1458,11 @@ async function* query(params) {
|
|
|
1163
1458
|
continue;
|
|
1164
1459
|
}
|
|
1165
1460
|
consecutiveCompletionGateBlocks = 0;
|
|
1461
|
+
if (holdAssistant) {
|
|
1462
|
+
appendMessage(assistantMsg);
|
|
1463
|
+
harness?.recordAssistantResponse(response);
|
|
1464
|
+
streamCallbacks?.onChunk?.(response.content);
|
|
1465
|
+
}
|
|
1166
1466
|
yield { type: 'message', role: 'assistant', content: response.content };
|
|
1167
1467
|
// Keep the next request safe by compacting the current durable history at
|
|
1168
1468
|
// 95%. This uses current-message context, not cumulative session tokens.
|
|
@@ -1185,8 +1485,8 @@ async function* query(params) {
|
|
|
1185
1485
|
captureCompactPrepareSource();
|
|
1186
1486
|
}
|
|
1187
1487
|
const postCompactAttempt = pendingCompact
|
|
1188
|
-
? await autoCompact.ensureHeadroomAndCompactOutcome(messages, currentContextTokens, validatePostCompact)
|
|
1189
|
-
: await autoCompact.checkAndCompactOutcome(messages, currentContextTokens, validatePostCompact);
|
|
1488
|
+
? await autoCompact.ensureHeadroomAndCompactOutcome(messages, currentContextTokens, validatePostCompact, abortSignal)
|
|
1489
|
+
: await autoCompact.checkAndCompactOutcome(messages, currentContextTokens, validatePostCompact, abortSignal);
|
|
1190
1490
|
if (postCompactAttempt.status === 'paused') {
|
|
1191
1491
|
yield attachCompactCommit(compactPausedEvent(llm, stats, postCompactAttempt.failure, response.content), pendingCompact, messages, aggregateUsage);
|
|
1192
1492
|
return;
|