@orion-agents/orion-code 0.3.66 → 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 +81 -0
- package/README.md +78 -361
- package/README.zh-CN.md +71 -262
- 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 -133
- package/dist/runtime/release-receipts.js +129 -693
- 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-CPDovK_K.js +0 -1
- package/dist/web-client/assets/GitPanel-DtU_TD61.js +0 -4
- package/dist/web-client/assets/ReviewPanel-vMO7BEA3.js +0 -6
- package/dist/web-client/assets/TerminalPanel-C9vDTAlS.js +0 -23
- package/dist/web-client/assets/TerminalPanel-DLuoa74B.css +0 -1
- package/dist/web-client/assets/index-CABdwh4l.css +0 -1
- package/dist/web-client/assets/index-KvshfEbl.js +0 -20
- package/dist/web-client/assets/useAutoNotice-IE1g2wcb.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
|
@@ -37,6 +37,7 @@ const ui_events_1 = require("../runtime/ui-events");
|
|
|
37
37
|
const ui_view_model_1 = require("../runtime/ui-view-model");
|
|
38
38
|
const format_1 = require("../services/format");
|
|
39
39
|
const redaction_1 = require("../services/redaction");
|
|
40
|
+
const answer_format_1 = require("./answer-format");
|
|
40
41
|
const completion_1 = require("./completion");
|
|
41
42
|
const editor_1 = require("./editor");
|
|
42
43
|
const raw_editor_1 = require("./raw-editor");
|
|
@@ -165,6 +166,9 @@ function resolveTerminalModelPickerInput(input, request) {
|
|
|
165
166
|
};
|
|
166
167
|
}
|
|
167
168
|
function formatTranscriptEntry(entry) {
|
|
169
|
+
if (entry.role === 'assistant' && entry.title === 'reasoning') {
|
|
170
|
+
return entry.content.trim() ? DIM('· Thinking') : '';
|
|
171
|
+
}
|
|
168
172
|
const content = (0, style_1.sanitizeTerminalText)(stripTrailingNewlines(entry.content));
|
|
169
173
|
if (!content)
|
|
170
174
|
return '';
|
|
@@ -174,6 +178,10 @@ function formatTranscriptEntry(entry) {
|
|
|
174
178
|
case 'user':
|
|
175
179
|
return `${ACCENT('›')} ${content}`;
|
|
176
180
|
case 'tool':
|
|
181
|
+
if (entry.toolActivity?.callId) {
|
|
182
|
+
const { name, state, seq, command } = entry.toolActivity;
|
|
183
|
+
return formatTerminalToolRecord(state === 'error' ? 'Failed' : state === 'skipped' ? 'Skipped' : 'Completed', name, { sequence: seq, command });
|
|
184
|
+
}
|
|
177
185
|
return TOOL(content);
|
|
178
186
|
case 'error':
|
|
179
187
|
return ERROR(formatTerminalErrorMessage(content, entry.errorLayer));
|
|
@@ -183,10 +191,35 @@ function formatTranscriptEntry(entry) {
|
|
|
183
191
|
case 'system':
|
|
184
192
|
return content;
|
|
185
193
|
case 'assistant':
|
|
194
|
+
return stripTrailingNewlines(new answer_format_1.TerminalAnswerFormatter().push(content, true, terminalContentWidth()));
|
|
186
195
|
default:
|
|
187
196
|
return content;
|
|
188
197
|
}
|
|
189
198
|
}
|
|
199
|
+
function formatTerminalToolRecord(state, name, metadata) {
|
|
200
|
+
const { command, details, duration, sequence } = metadata;
|
|
201
|
+
const elapsed = duration === undefined ? '' : ` (${Math.round(duration)}ms)`;
|
|
202
|
+
const invocation = sequence === undefined ? '' : ` #${sequence}`;
|
|
203
|
+
const prefix = `Tool · ${state} `;
|
|
204
|
+
const title = command
|
|
205
|
+
? (0, style_1.sanitizeTerminalText)(command).replace(/\n/gu, ' ').trim()
|
|
206
|
+
: (0, style_1.sanitizeTerminalText)(name).replace(/\n/gu, ' ').trim();
|
|
207
|
+
const heading = prefix +
|
|
208
|
+
truncateTerminalText(title, Math.max(1, terminalContentWidth(120) - visibleLength(prefix + elapsed + invocation)));
|
|
209
|
+
const lines = details
|
|
210
|
+
? (0, style_1.sanitizeTerminalText)((0, redaction_1.redactTraceText)(details))
|
|
211
|
+
.split('\n')
|
|
212
|
+
.map(line => line.trim())
|
|
213
|
+
.filter(Boolean)
|
|
214
|
+
: [];
|
|
215
|
+
const maxSummaryLines = 8;
|
|
216
|
+
const summaryLines = lines.slice(0, maxSummaryLines).map(line => truncateTerminalText(line, 200));
|
|
217
|
+
if (lines.length > maxSummaryLines) {
|
|
218
|
+
summaryLines.push(`... (${lines.length - maxSummaryLines} more lines)`);
|
|
219
|
+
}
|
|
220
|
+
const summary = summaryLines.join('\n ');
|
|
221
|
+
return `${state === 'Failed' ? ERROR(heading) : TOOL(heading)}${elapsed}${invocation}${summary ? `\n ${summary}` : ''}`;
|
|
222
|
+
}
|
|
190
223
|
const TERMINAL_ERROR_LAYERS = [
|
|
191
224
|
'renderer',
|
|
192
225
|
'runtime',
|
|
@@ -247,6 +280,54 @@ function inferTerminalErrorLayer(message) {
|
|
|
247
280
|
function shouldShowStatus(message) {
|
|
248
281
|
return Boolean(message.trim());
|
|
249
282
|
}
|
|
283
|
+
const TURN_OUTCOME_LABELS = Object.freeze({
|
|
284
|
+
completed: 'Completed',
|
|
285
|
+
blocked: 'Blocked',
|
|
286
|
+
cancelled: 'Interrupted',
|
|
287
|
+
failed: 'Turn failed',
|
|
288
|
+
budget_exceeded: 'Stopped: budget limit reached',
|
|
289
|
+
completion_gate: 'Stopped: completion checks still pending',
|
|
290
|
+
compact_paused: 'Paused: context compaction needs attention',
|
|
291
|
+
tool_limit: 'Stopped: tool limit reached',
|
|
292
|
+
});
|
|
293
|
+
function describeTurnOutcome(message, elapsedMs) {
|
|
294
|
+
if (!message.startsWith('{"finishReason"')) {
|
|
295
|
+
return message;
|
|
296
|
+
}
|
|
297
|
+
try {
|
|
298
|
+
const outcome = JSON.parse(message);
|
|
299
|
+
if (typeof outcome.finishReason !== 'string')
|
|
300
|
+
return message;
|
|
301
|
+
const label = Object.prototype.hasOwnProperty.call(TURN_OUTCOME_LABELS, outcome.finishReason)
|
|
302
|
+
? TURN_OUTCOME_LABELS[outcome.finishReason]
|
|
303
|
+
: 'Turn stopped';
|
|
304
|
+
const resourceElapsed = outcome.stopDecision?.resources?.elapsedMs?.used;
|
|
305
|
+
const elapsed = elapsedMs ??
|
|
306
|
+
(typeof resourceElapsed === 'number' &&
|
|
307
|
+
Number.isFinite(resourceElapsed) &&
|
|
308
|
+
resourceElapsed >= 0
|
|
309
|
+
? resourceElapsed
|
|
310
|
+
: undefined);
|
|
311
|
+
const duration = elapsed === undefined ? '' : ` · ${formatTurnDuration(elapsed)}`;
|
|
312
|
+
const explanation = outcome.stopDecision?.reason?.message;
|
|
313
|
+
return (label +
|
|
314
|
+
duration +
|
|
315
|
+
(outcome.finishReason !== 'completed' && typeof explanation === 'string'
|
|
316
|
+
? ` — ${(0, redaction_1.redactTraceText)(explanation)}`
|
|
317
|
+
: ''));
|
|
318
|
+
}
|
|
319
|
+
catch {
|
|
320
|
+
return message;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
function formatTurnDuration(milliseconds) {
|
|
324
|
+
if (milliseconds < 1000)
|
|
325
|
+
return `${Math.round(milliseconds)}ms`;
|
|
326
|
+
if (milliseconds < 60000)
|
|
327
|
+
return `${(milliseconds / 1000).toFixed(1)}s`;
|
|
328
|
+
const seconds = Math.floor(milliseconds / 1000);
|
|
329
|
+
return `${Math.floor(seconds / 60)}m ${seconds % 60}s`;
|
|
330
|
+
}
|
|
250
331
|
function formatTerminalStatusMessage(message, width = terminalContentWidth(120)) {
|
|
251
332
|
return truncateTerminalText((0, style_1.sanitizeTerminalText)(message).replace(/\s+/g, ' ').trim(), Math.max(1, width));
|
|
252
333
|
}
|
|
@@ -453,7 +534,7 @@ class TerminalEventSink {
|
|
|
453
534
|
this.writer = writer;
|
|
454
535
|
this.entries = new Map();
|
|
455
536
|
this.printedContent = new Map();
|
|
456
|
-
this.
|
|
537
|
+
this.answerFormatters = new Map();
|
|
457
538
|
this.finalizedEntryIds = new Set();
|
|
458
539
|
this.idCounter = 0;
|
|
459
540
|
this.pendingPicker = null;
|
|
@@ -524,28 +605,23 @@ class TerminalEventSink {
|
|
|
524
605
|
remove(id) {
|
|
525
606
|
this.entries.delete(id);
|
|
526
607
|
this.printedContent.delete(id);
|
|
527
|
-
this.
|
|
608
|
+
this.answerFormatters.delete(id);
|
|
528
609
|
this.finalizedEntryIds.delete(id);
|
|
529
610
|
}
|
|
530
611
|
replaceTranscript(entries) {
|
|
531
612
|
this.entries.clear();
|
|
532
613
|
this.printedContent.clear();
|
|
533
|
-
this.
|
|
614
|
+
this.answerFormatters.clear();
|
|
534
615
|
if (entries.length === 0)
|
|
535
616
|
return;
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
const formatted = formatTranscriptEntry(entry);
|
|
540
|
-
if (formatted) {
|
|
541
|
-
this.writer.write(`${formatted}\n\n`);
|
|
542
|
-
}
|
|
543
|
-
}
|
|
617
|
+
const divider = BORDER('─'.repeat(terminalContentWidth(80)));
|
|
618
|
+
const lines = entries.map(formatTranscriptEntry).filter(Boolean).join('\n');
|
|
619
|
+
this.writer.write(`\n${divider}\n${DIM('Restored conversation')}\n\n${lines}\n`);
|
|
544
620
|
}
|
|
545
621
|
clearTranscript() {
|
|
546
622
|
this.entries.clear();
|
|
547
623
|
this.printedContent.clear();
|
|
548
|
-
this.
|
|
624
|
+
this.answerFormatters.clear();
|
|
549
625
|
this.writer.write(`${DIM('View marker reset. Terminal scrollback is preserved.')}\n`);
|
|
550
626
|
}
|
|
551
627
|
clearView() {
|
|
@@ -557,7 +633,7 @@ class TerminalEventSink {
|
|
|
557
633
|
if (message === this.lastStatusMessage)
|
|
558
634
|
return;
|
|
559
635
|
this.lastStatusMessage = message;
|
|
560
|
-
this.writer.write(`${DIM(formatTerminalStatusMessage(message))}\n`);
|
|
636
|
+
this.writer.write(`${DIM(formatTerminalStatusMessage(describeTurnOutcome(message, this.elapsedTurnMs)))}\n`);
|
|
561
637
|
}
|
|
562
638
|
showSessionPicker(request) {
|
|
563
639
|
this.pendingPicker = request;
|
|
@@ -593,15 +669,29 @@ class TerminalEventSink {
|
|
|
593
669
|
this.setStatus((0, presentation_1.formatGoalRuntimeEvent)(event));
|
|
594
670
|
}
|
|
595
671
|
toolStarted(event) {
|
|
596
|
-
this.writer.write(`${
|
|
672
|
+
this.writer.write(`${formatTerminalToolRecord('Running', event.name, {
|
|
673
|
+
command: event.command,
|
|
674
|
+
sequence: event.sequence,
|
|
675
|
+
})}\n`);
|
|
597
676
|
}
|
|
598
677
|
toolFinished(event) {
|
|
599
|
-
const state = event.success ? 'Completed' : 'Failed';
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
678
|
+
const state = event.skipped ? 'Skipped' : event.success ? 'Completed' : 'Failed';
|
|
679
|
+
this.writer.write(`${formatTerminalToolRecord(state, event.name, {
|
|
680
|
+
command: event.command,
|
|
681
|
+
details: event.error ?? event.summary,
|
|
682
|
+
duration: event.duration,
|
|
683
|
+
sequence: event.sequence,
|
|
684
|
+
})}\n`);
|
|
685
|
+
}
|
|
686
|
+
setProcessing(processing) {
|
|
687
|
+
if (processing && this.turnStartedAt === undefined) {
|
|
688
|
+
this.turnStartedAt = performance.now();
|
|
689
|
+
this.elapsedTurnMs = undefined;
|
|
690
|
+
}
|
|
691
|
+
else if (!processing && this.turnStartedAt !== undefined) {
|
|
692
|
+
this.elapsedTurnMs = performance.now() - this.turnStartedAt;
|
|
693
|
+
this.turnStartedAt = undefined;
|
|
694
|
+
}
|
|
605
695
|
}
|
|
606
696
|
consumePendingSelection(input) {
|
|
607
697
|
const picker = this.pendingPicker;
|
|
@@ -750,15 +840,24 @@ class TerminalEventSink {
|
|
|
750
840
|
this.printModelPickerPage();
|
|
751
841
|
}
|
|
752
842
|
printEntry(entry, finalized) {
|
|
843
|
+
// Live tool events already write to this renderer. Restored rows go through
|
|
844
|
+
// replaceTranscript and can be printed without duplicating those events.
|
|
845
|
+
if (entry.role === 'tool' && entry.toolActivity?.callId)
|
|
846
|
+
return;
|
|
847
|
+
if (entry.role === 'user' && !finalized)
|
|
848
|
+
return;
|
|
753
849
|
if (!entry.content)
|
|
754
850
|
return;
|
|
755
|
-
if (entry.role === 'assistant') {
|
|
851
|
+
if (entry.role === 'assistant' && entry.title !== 'reasoning') {
|
|
756
852
|
return this.printAssistantDelta(entry, finalized);
|
|
757
853
|
}
|
|
758
854
|
const previous = this.printedContent.get(entry.id);
|
|
855
|
+
// Reasoning is progress metadata. Emit one label for the item.
|
|
856
|
+
if (entry.role === 'assistant' && previous !== undefined)
|
|
857
|
+
return;
|
|
759
858
|
if (previous === entry.content && !finalized)
|
|
760
859
|
return;
|
|
761
|
-
this.printedContent.set(entry.id, entry.content);
|
|
860
|
+
this.printedContent.set(entry.id, entry.role === 'assistant' ? '' : entry.content);
|
|
762
861
|
// v0.2.23: bound printed content.
|
|
763
862
|
this.evictIfNeeded(this.printedContent, TerminalEventSink.MAX_PRINTED_CONTENT);
|
|
764
863
|
const formatted = formatTranscriptEntry(entry);
|
|
@@ -780,27 +879,26 @@ class TerminalEventSink {
|
|
|
780
879
|
const delta = safeNext.startsWith(safePrevious)
|
|
781
880
|
? safeNext.slice(safePrevious.length)
|
|
782
881
|
: `\n${safeNext}`;
|
|
783
|
-
const pending = `${this.pendingAssistantOutput.get(entry.id) ?? ''}${delta}`;
|
|
784
882
|
this.printedContent.set(entry.id, next);
|
|
785
883
|
// v0.2.23: bound printed content.
|
|
786
884
|
this.evictIfNeeded(this.printedContent, TerminalEventSink.MAX_PRINTED_CONTENT);
|
|
787
|
-
const
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
else if (finalized && next && !next.endsWith('\n')) {
|
|
794
|
-
return this.writeWithAcknowledgement('\n');
|
|
795
|
-
}
|
|
796
|
-
return;
|
|
885
|
+
const end = finalized && safeNext && !safeNext.endsWith('\n') ? '\n' : '';
|
|
886
|
+
let formatter = this.answerFormatters.get(entry.id);
|
|
887
|
+
if (!formatter) {
|
|
888
|
+
formatter = new answer_format_1.TerminalAnswerFormatter();
|
|
889
|
+
this.answerFormatters.set(entry.id, formatter);
|
|
890
|
+
this.evictIfNeeded(this.answerFormatters, TerminalEventSink.MAX_PRINTED_CONTENT);
|
|
797
891
|
}
|
|
798
|
-
|
|
892
|
+
const visible = formatter.push(delta + end, finalized, terminalContentWidth());
|
|
893
|
+
if (finalized)
|
|
894
|
+
this.answerFormatters.delete(entry.id);
|
|
895
|
+
if (visible)
|
|
896
|
+
return this.writeWithAcknowledgement(visible, true);
|
|
799
897
|
}
|
|
800
|
-
writeWithAcknowledgement(text) {
|
|
898
|
+
writeWithAcknowledgement(text, stream) {
|
|
801
899
|
if (this.writer.writeAsync)
|
|
802
|
-
return this.writer.writeAsync(text);
|
|
803
|
-
this.writer.write(text);
|
|
900
|
+
return this.writer.writeAsync(text, stream);
|
|
901
|
+
this.writer.write(text, stream);
|
|
804
902
|
}
|
|
805
903
|
/**
|
|
806
904
|
* R8: consume the typed subagent event into the shared timeline view-model.
|
|
@@ -859,7 +957,7 @@ class TerminalEventSink {
|
|
|
859
957
|
content: `[scrollback:${entry.role} posted ${entry.content.length} chars]`,
|
|
860
958
|
});
|
|
861
959
|
this.printedContent.delete(id);
|
|
862
|
-
this.
|
|
960
|
+
this.answerFormatters.delete(id);
|
|
863
961
|
this.finalizedEntryIds.delete(id);
|
|
864
962
|
this.finalizedEntryIds.add(id);
|
|
865
963
|
while (this.finalizedEntryIds.size > TerminalEventSink.MAX_FINALIZED_METADATA) {
|
|
@@ -944,7 +1042,7 @@ function formatTerminalPermissionPrompt(request, cwd) {
|
|
|
944
1042
|
const width = terminalContentWidth(120);
|
|
945
1043
|
const budget = Math.max(1, width);
|
|
946
1044
|
const base = `${ACCENT('?')} Allow tool ${ACCENT(state.toolName)}?`;
|
|
947
|
-
const options = DIM(`[${state.options.once} ${state.options.
|
|
1045
|
+
const options = DIM(`[${state.options.once} ${state.options.deny}]`);
|
|
948
1046
|
const scope = DIM(formatTerminalPermissionScope(state));
|
|
949
1047
|
const cwdLabel = DIM(`cwd=${compactPermissionValue(state.cwd, Math.max(8, width - 4))}`);
|
|
950
1048
|
const risk = DIM(`risk=${compactPermissionValue((0, ui_view_model_1.permissionRiskDisplayValue)(state.risk), Math.max(8, width - 5))}`);
|
|
@@ -960,14 +1058,6 @@ function parseTerminalPermissionAnswer(answer) {
|
|
|
960
1058
|
case 'yes':
|
|
961
1059
|
case 'once':
|
|
962
1060
|
return { approved: true, scope: 'once' };
|
|
963
|
-
case '2':
|
|
964
|
-
case 'p':
|
|
965
|
-
case 'project':
|
|
966
|
-
return { approved: true, scope: 'project' };
|
|
967
|
-
case '3':
|
|
968
|
-
case 'g':
|
|
969
|
-
case 'global':
|
|
970
|
-
return { approved: true, scope: 'global' };
|
|
971
1061
|
case 'n':
|
|
972
1062
|
case 'no':
|
|
973
1063
|
case 'deny':
|
|
@@ -1172,7 +1262,7 @@ async function launchTerminalUI(runtime) {
|
|
|
1172
1262
|
},
|
|
1173
1263
|
});
|
|
1174
1264
|
const outputAdapter = {
|
|
1175
|
-
write: text => editor.writeExternalBatch([text]),
|
|
1265
|
+
write: (text, stream) => editor.writeExternalBatch([text], stream),
|
|
1176
1266
|
on: (event, listener) => {
|
|
1177
1267
|
process.stdout.on(event, listener);
|
|
1178
1268
|
},
|
|
@@ -1182,26 +1272,29 @@ async function launchTerminalUI(runtime) {
|
|
|
1182
1272
|
};
|
|
1183
1273
|
const outputQueue = new output_queue_1.TerminalOutputQueue(outputAdapter);
|
|
1184
1274
|
let outputBatchSequence = 0;
|
|
1275
|
+
const enqueueOutput = (text, stream) => outputQueue
|
|
1276
|
+
.enqueue({
|
|
1277
|
+
id: `terminal-output-${++outputBatchSequence}`,
|
|
1278
|
+
chunks: [text],
|
|
1279
|
+
releaseEntryIds: [],
|
|
1280
|
+
stream,
|
|
1281
|
+
})
|
|
1282
|
+
.then(() => true, () => false);
|
|
1185
1283
|
writer = {
|
|
1186
|
-
write: text =>
|
|
1187
|
-
|
|
1188
|
-
.enqueue({
|
|
1189
|
-
id: `terminal-output-${++outputBatchSequence}`,
|
|
1190
|
-
chunks: [text],
|
|
1191
|
-
releaseEntryIds: [],
|
|
1192
|
-
})
|
|
1193
|
-
.catch(() => undefined);
|
|
1194
|
-
},
|
|
1195
|
-
writeAsync: text => outputQueue
|
|
1196
|
-
.enqueue({
|
|
1197
|
-
id: `terminal-output-${++outputBatchSequence}`,
|
|
1198
|
-
chunks: [text],
|
|
1199
|
-
releaseEntryIds: [],
|
|
1200
|
-
})
|
|
1201
|
-
.then(() => true, () => false),
|
|
1284
|
+
write: (text, stream) => void enqueueOutput(text, stream),
|
|
1285
|
+
writeAsync: enqueueOutput,
|
|
1202
1286
|
};
|
|
1203
1287
|
const events = new TerminalEventSink(runtime, writer);
|
|
1204
1288
|
let stopping = false;
|
|
1289
|
+
let lastCompactStatus = '';
|
|
1290
|
+
const unsubscribeCompactStatus = runtime.store.subscribe(snapshot => {
|
|
1291
|
+
if (stopping)
|
|
1292
|
+
return;
|
|
1293
|
+
const next = (0, ui_view_model_1.backgroundCompactStatusText)(snapshot.backgroundCompact);
|
|
1294
|
+
if (next && next !== lastCompactStatus)
|
|
1295
|
+
events.setStatus(next);
|
|
1296
|
+
lastCompactStatus = next;
|
|
1297
|
+
});
|
|
1205
1298
|
let settled = false;
|
|
1206
1299
|
let resolveLaunch = null;
|
|
1207
1300
|
const composer = new TerminalInputComposer();
|
|
@@ -1227,7 +1320,7 @@ async function launchTerminalUI(runtime) {
|
|
|
1227
1320
|
const decision = parseTerminalPermissionAnswer(answer);
|
|
1228
1321
|
if (decision)
|
|
1229
1322
|
return decision;
|
|
1230
|
-
writer.write(`${WARNING('
|
|
1323
|
+
writer.write(`${WARNING('Choose 1 to allow once or n to deny.')}\n`);
|
|
1231
1324
|
}
|
|
1232
1325
|
return { approved: false, scope: 'once' };
|
|
1233
1326
|
};
|
|
@@ -1263,11 +1356,7 @@ async function launchTerminalUI(runtime) {
|
|
|
1263
1356
|
uiRenderer: 'terminal',
|
|
1264
1357
|
useRuntimeToolPermissions: true,
|
|
1265
1358
|
echoSubmittedInput: false,
|
|
1266
|
-
|
|
1267
|
-
afterTurnLoop: () => {
|
|
1268
|
-
writer.write('\n');
|
|
1269
|
-
prompt();
|
|
1270
|
-
},
|
|
1359
|
+
afterTurnLoop: () => prompt(),
|
|
1271
1360
|
onTurnError: error => {
|
|
1272
1361
|
const message = error instanceof Error ? error.message : String(error);
|
|
1273
1362
|
events.append({ role: 'error', content: message });
|
|
@@ -1407,6 +1496,7 @@ async function launchTerminalUI(runtime) {
|
|
|
1407
1496
|
});
|
|
1408
1497
|
}
|
|
1409
1498
|
finally {
|
|
1499
|
+
unsubscribeCompactStatus();
|
|
1410
1500
|
if (!stopping) {
|
|
1411
1501
|
stopping = true;
|
|
1412
1502
|
try {
|
|
@@ -9,11 +9,12 @@
|
|
|
9
9
|
export interface TerminalOutputBatch {
|
|
10
10
|
id: string;
|
|
11
11
|
chunks: readonly string[];
|
|
12
|
+
stream?: boolean;
|
|
12
13
|
/** Entry IDs whose heavy state can be released after this batch is written. */
|
|
13
14
|
releaseEntryIds: readonly string[];
|
|
14
15
|
}
|
|
15
16
|
export interface TerminalOutputWriter {
|
|
16
|
-
write(text: string): boolean;
|
|
17
|
+
write(text: string, stream?: boolean): boolean;
|
|
17
18
|
on(event: 'drain', listener: () => void): void;
|
|
18
19
|
off(event: 'drain', listener: () => void): void;
|
|
19
20
|
on(event: 'error', listener: (error: Error) => void): void;
|
|
@@ -107,7 +107,7 @@ class TerminalOutputQueue {
|
|
|
107
107
|
while (chunkIndex < batch.chunks.length) {
|
|
108
108
|
const chunk = batch.chunks[chunkIndex];
|
|
109
109
|
chunkIndex += 1;
|
|
110
|
-
const ok = this.writer.write(chunk);
|
|
110
|
+
const ok = this.writer.write(chunk, batch.stream);
|
|
111
111
|
if (!ok) {
|
|
112
112
|
// Backpressure: wait for drain before writing more.
|
|
113
113
|
drainListener = () => {
|
|
@@ -48,6 +48,7 @@ export declare class RawTerminalEditor {
|
|
|
48
48
|
private resizeListenerAttached;
|
|
49
49
|
private renderedRows;
|
|
50
50
|
private renderedCursorRow;
|
|
51
|
+
private streamTail;
|
|
51
52
|
private inputLimitNoticeShown;
|
|
52
53
|
private inputSoftNoticeShown;
|
|
53
54
|
private renderTimer;
|
|
@@ -61,7 +62,7 @@ export declare class RawTerminalEditor {
|
|
|
61
62
|
cancelQuestion(): void;
|
|
62
63
|
writeExternal(text: string): void;
|
|
63
64
|
/** Write one external batch with a single prompt clear/redraw transaction. */
|
|
64
|
-
writeExternalBatch(chunks: readonly string[]): boolean;
|
|
65
|
+
writeExternalBatch(chunks: readonly string[], stream?: boolean): boolean;
|
|
65
66
|
feed(chunk: Buffer | string): TuiInputEvent[];
|
|
66
67
|
getBuffer(): {
|
|
67
68
|
value: string;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.RawTerminalEditor = void 0;
|
|
7
7
|
const readline_1 = __importDefault(require("readline"));
|
|
8
8
|
const string_width_1 = __importDefault(require("string-width"));
|
|
9
|
+
const grapheme_1 = require("../runtime/composer/grapheme");
|
|
9
10
|
const input_parser_1 = require("../tui-core/input-parser");
|
|
10
11
|
const completion_1 = require("./completion");
|
|
11
12
|
const BRACKETED_PASTE_ENABLE = '\x1b[?2004h';
|
|
@@ -36,6 +37,7 @@ class RawTerminalEditor {
|
|
|
36
37
|
this.resizeListenerAttached = false;
|
|
37
38
|
this.renderedRows = 0;
|
|
38
39
|
this.renderedCursorRow = 0;
|
|
40
|
+
this.streamTail = '';
|
|
39
41
|
this.inputLimitNoticeShown = false;
|
|
40
42
|
this.inputSoftNoticeShown = false;
|
|
41
43
|
this.renderTimer = null;
|
|
@@ -143,14 +145,22 @@ class RawTerminalEditor {
|
|
|
143
145
|
this.writeExternalBatch([text]);
|
|
144
146
|
}
|
|
145
147
|
/** Write one external batch with a single prompt clear/redraw transaction. */
|
|
146
|
-
writeExternalBatch(chunks) {
|
|
147
|
-
const text = chunks.
|
|
148
|
+
writeExternalBatch(chunks, stream = false) {
|
|
149
|
+
const text = chunks.join('');
|
|
148
150
|
if (!text)
|
|
149
151
|
return true;
|
|
152
|
+
if (stream) {
|
|
153
|
+
if (this.output.isTTY === false)
|
|
154
|
+
return this.output.write(text);
|
|
155
|
+
this.streamTail += text;
|
|
156
|
+
return this.render();
|
|
157
|
+
}
|
|
150
158
|
this.clearPromptLine();
|
|
151
|
-
const
|
|
152
|
-
this.
|
|
153
|
-
|
|
159
|
+
const block = this.streamTail ? `${this.streamTail}\n${text}` : text;
|
|
160
|
+
this.streamTail = '';
|
|
161
|
+
const accepted = this.output.write(block.endsWith('\n') ? block : `${block}\n`);
|
|
162
|
+
const rendered = this.render();
|
|
163
|
+
return accepted !== false && rendered;
|
|
154
164
|
}
|
|
155
165
|
feed(chunk) {
|
|
156
166
|
const events = this.parser.feed(chunk, { detectUnbracketedMultilinePaste: true });
|
|
@@ -364,8 +374,16 @@ class RawTerminalEditor {
|
|
|
364
374
|
}
|
|
365
375
|
submit() {
|
|
366
376
|
const submitted = this.value;
|
|
367
|
-
this.
|
|
368
|
-
|
|
377
|
+
if (this.questionPrompt) {
|
|
378
|
+
this.render();
|
|
379
|
+
this.commitRenderedEditor();
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
// The runtime owns the complete submitted message in scrollback.
|
|
383
|
+
// Clear the editor viewport, which may only show the end of a long draft.
|
|
384
|
+
this.cancelScheduledRender();
|
|
385
|
+
this.clearPromptLine();
|
|
386
|
+
}
|
|
369
387
|
this.value = '';
|
|
370
388
|
this.cursor = 0;
|
|
371
389
|
this.historyIndex = null;
|
|
@@ -491,26 +509,28 @@ class RawTerminalEditor {
|
|
|
491
509
|
const prompt = this.questionPrompt ?? this.promptValue;
|
|
492
510
|
const width = Math.max(20, this.output.columns || 80);
|
|
493
511
|
const terminalRows = Math.max(4, this.output.rows || 24);
|
|
512
|
+
const { committed, tail } = splitTerminalStream(this.streamTail, this.output.columns || width);
|
|
513
|
+
this.streamTail = tail;
|
|
494
514
|
const frame = layoutEditorFrame({
|
|
495
515
|
prompt,
|
|
496
516
|
value: this.value,
|
|
497
517
|
cursor: this.cursor,
|
|
498
518
|
width,
|
|
499
|
-
maxRows: Math.min(MAX_EDITOR_ROWS, Math.max(1, terminalRows - 3)),
|
|
519
|
+
maxRows: Math.min(MAX_EDITOR_ROWS, Math.max(1, terminalRows - 3 - Number(Boolean(tail)))),
|
|
500
520
|
});
|
|
501
521
|
this.clearPromptLine();
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
}
|
|
522
|
+
// Keep only the unfinished visual row editable above the draft. Committed
|
|
523
|
+
// rows are written once and stay in native scrollback.
|
|
524
|
+
const liveRows = tail ? [tail, ...frame.rows] : frame.rows;
|
|
525
|
+
const accepted = this.output.write(committed + liveRows.join('\r\n'));
|
|
507
526
|
const rowsBelowCursor = frame.rows.length - 1 - frame.cursorRow;
|
|
508
527
|
if (rowsBelowCursor > 0 && this.output.isTTY !== false) {
|
|
509
528
|
readline_1.default.moveCursor(this.output, 0, -rowsBelowCursor);
|
|
510
529
|
}
|
|
511
530
|
readline_1.default.cursorTo(this.output, frame.cursorColumn);
|
|
512
|
-
this.renderedRows =
|
|
513
|
-
this.renderedCursorRow = frame.cursorRow;
|
|
531
|
+
this.renderedRows = liveRows.length;
|
|
532
|
+
this.renderedCursorRow = frame.cursorRow + Number(Boolean(tail));
|
|
533
|
+
return accepted !== false;
|
|
514
534
|
}
|
|
515
535
|
clearPromptLine() {
|
|
516
536
|
if (this.output.isTTY === false)
|
|
@@ -547,11 +567,32 @@ class RawTerminalEditor {
|
|
|
547
567
|
readline_1.default.cursorTo(this.output, 0);
|
|
548
568
|
}
|
|
549
569
|
this.output.write('\r\n');
|
|
570
|
+
this.streamTail = '';
|
|
550
571
|
this.renderedRows = 0;
|
|
551
572
|
this.renderedCursorRow = 0;
|
|
552
573
|
}
|
|
553
574
|
}
|
|
554
575
|
exports.RawTerminalEditor = RawTerminalEditor;
|
|
576
|
+
function splitTerminalStream(text, width) {
|
|
577
|
+
const end = text.lastIndexOf('\n') + 1;
|
|
578
|
+
let committed = text.slice(0, end);
|
|
579
|
+
let tail = text.slice(end);
|
|
580
|
+
if ((0, string_width_1.default)(tail) <= width)
|
|
581
|
+
return { committed, tail };
|
|
582
|
+
let cells = 0;
|
|
583
|
+
tail = '';
|
|
584
|
+
for (const { segment: grapheme } of (0, grapheme_1.segmentGraphemes)(text.slice(end))) {
|
|
585
|
+
const size = (0, string_width_1.default)(grapheme);
|
|
586
|
+
if (tail && cells + size > width) {
|
|
587
|
+
committed += `${tail}\n`;
|
|
588
|
+
tail = '';
|
|
589
|
+
cells = 0;
|
|
590
|
+
}
|
|
591
|
+
tail += grapheme;
|
|
592
|
+
cells += size;
|
|
593
|
+
}
|
|
594
|
+
return { committed, tail };
|
|
595
|
+
}
|
|
555
596
|
function layoutEditorFrame(input) {
|
|
556
597
|
const safeCursor = clampCursor(input.value, input.cursor);
|
|
557
598
|
const promptCells = (0, string_width_1.default)(stripAnsi(input.prompt));
|
|
@@ -264,6 +264,7 @@ async function editFile_(path, old_string, new_string, replace_all, fuzzy_match,
|
|
|
264
264
|
return {
|
|
265
265
|
success: true,
|
|
266
266
|
output: `Fuzzy edited ${normalizedPath} (matched by ${fuzzyResult.strategy}, "${match.slice(0, 50)}...")`,
|
|
267
|
+
...(newContent !== content ? { metadata: { workspaceWritePath: normalizedPath } } : {}),
|
|
267
268
|
};
|
|
268
269
|
}
|
|
269
270
|
// If not replace_all, require unique match
|
|
@@ -288,6 +289,7 @@ async function editFile_(path, old_string, new_string, replace_all, fuzzy_match,
|
|
|
288
289
|
return {
|
|
289
290
|
success: true,
|
|
290
291
|
output: `Replaced ${count} occurrence(s) of old_string with new_string in ${normalizedPath}`,
|
|
292
|
+
...(newContent !== content ? { metadata: { workspaceWritePath: normalizedPath } } : {}),
|
|
291
293
|
};
|
|
292
294
|
}
|
|
293
295
|
catch (err) {
|
|
@@ -51,11 +51,16 @@ async function writeFileSync_(path, content, cwd) {
|
|
|
51
51
|
error: `Refusing to write outside the workspace: ${normalizedPath}`,
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
+
const previous = (0, common_1.safeStatSync)(resolved);
|
|
55
|
+
const bytes = Buffer.byteLength(content, 'utf8');
|
|
56
|
+
const previousText = previous && previous.size === bytes && previous.isFile() ? (0, common_1.safeReadFileSync)(resolved) : null;
|
|
57
|
+
const changed = !previous || previous.size !== bytes || (previousText !== null && previousText !== content);
|
|
54
58
|
(0, fs_1.mkdirSync)((0, path_1.dirname)(resolved), { recursive: true });
|
|
55
59
|
(0, fs_1.writeFileSync)(resolved, content, 'utf-8');
|
|
56
60
|
return {
|
|
57
61
|
success: true,
|
|
58
62
|
output: `Wrote ${content.split('\n').length} lines to ${normalizedPath}`,
|
|
63
|
+
...(changed ? { metadata: { workspaceWritePath: normalizedPath } } : {}),
|
|
59
64
|
};
|
|
60
65
|
}
|
|
61
66
|
catch (err) {
|
package/dist/tools/lsp.d.ts
CHANGED
|
@@ -22,6 +22,14 @@ interface LspLocation {
|
|
|
22
22
|
end: LspPosition;
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
+
interface LspLocationLink {
|
|
26
|
+
targetUri: string;
|
|
27
|
+
targetSelectionRange: {
|
|
28
|
+
start: LspPosition;
|
|
29
|
+
end: LspPosition;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
type LspDefinition = LspLocation[] | LspLocation | LspLocationLink[] | null;
|
|
25
33
|
interface LspDiagnostic {
|
|
26
34
|
range: {
|
|
27
35
|
start: LspPosition;
|
|
@@ -54,6 +62,7 @@ export declare class LspClient extends EventEmitter {
|
|
|
54
62
|
private buffer;
|
|
55
63
|
private initialized;
|
|
56
64
|
private lspCommand;
|
|
65
|
+
private readonly openedDocuments;
|
|
57
66
|
constructor(language: string, projectRoot: string);
|
|
58
67
|
/**
|
|
59
68
|
* Probe whether a binary exists in PATH.
|
|
@@ -67,8 +76,14 @@ export declare class LspClient extends EventEmitter {
|
|
|
67
76
|
* Used when start() fails to avoid caching a broken client.
|
|
68
77
|
*/
|
|
69
78
|
dispose(): void;
|
|
70
|
-
getDefinition(uri: string, position: LspPosition): Promise<
|
|
79
|
+
getDefinition(uri: string, position: LspPosition): Promise<LspDefinition>;
|
|
71
80
|
getReferences(uri: string, position: LspPosition, includeDeclaration?: boolean): Promise<LspLocation[] | null>;
|
|
81
|
+
/**
|
|
82
|
+
* Synchronize the current on-disk snapshot before querying a document.
|
|
83
|
+
* Open once per server lifetime; subsequent edits are full-content changes
|
|
84
|
+
* with monotonically increasing document versions.
|
|
85
|
+
*/
|
|
86
|
+
openDocument(uri: string, languageId: string, text: string): void;
|
|
72
87
|
getHover(uri: string, position: LspPosition): Promise<LspHover | null>;
|
|
73
88
|
getDiagnostics(uri: string): Promise<LspDiagnostic[]>;
|
|
74
89
|
private getLspCommand;
|