@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
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FileWriteServiceV1 = void 0;
|
|
4
|
-
const fs_1 = require("fs");
|
|
5
|
-
const errors_1 = require("./errors");
|
|
6
|
-
const file_read_service_1 = require("./file-read-service");
|
|
7
|
-
const MAX_WRITE_BYTES = 512 * 1024;
|
|
8
|
-
const WRITE_SAMPLE_BYTES = 8192;
|
|
9
|
-
/**
|
|
10
|
-
* v0.3.14 — bounded, CAS-guarded writes for an existing in-root text file.
|
|
11
|
-
*
|
|
12
|
-
* Safety stack mirrors the read path: the file id resolves through the read
|
|
13
|
-
* service's fenced registry (workspace escape, symlink escape and sensitive
|
|
14
|
-
* paths fail closed there), the payload must be valid UTF-8 text without NULs
|
|
15
|
-
* within 512 KiB, and the write commits only when the on-disk revision still
|
|
16
|
-
* matches the caller's `expectedRevision` (compare-and-swap against the same
|
|
17
|
-
* stat fingerprint the read path returns).
|
|
18
|
-
*/
|
|
19
|
-
/**
|
|
20
|
-
* A bounded sample can end inside one UTF-8 code point (very likely for CJK
|
|
21
|
-
* text at an 8 KiB boundary); drop the trailing partial byte before judging the
|
|
22
|
-
* file as binary, mirroring the read path's `validUtf8Prefix`.
|
|
23
|
-
*/
|
|
24
|
-
function completeUtf8Tail(buffer) {
|
|
25
|
-
for (let trim = 0; trim <= Math.min(3, Math.max(0, buffer.length - 1)); trim += 1) {
|
|
26
|
-
const candidate = buffer.subarray(0, buffer.length - trim);
|
|
27
|
-
if (!(0, file_read_service_1.isBinary)(candidate))
|
|
28
|
-
return candidate;
|
|
29
|
-
}
|
|
30
|
-
return buffer;
|
|
31
|
-
}
|
|
32
|
-
class FileWriteServiceV1 {
|
|
33
|
-
constructor(fileService) {
|
|
34
|
-
this.fileService = fileService;
|
|
35
|
-
}
|
|
36
|
-
writeContent(input) {
|
|
37
|
-
const content = input.content;
|
|
38
|
-
if (typeof content !== 'string') {
|
|
39
|
-
throw new errors_1.WebWorkbenchError(400, 'File content must be a string.', 'file_content_invalid');
|
|
40
|
-
}
|
|
41
|
-
if (content.includes('\0')) {
|
|
42
|
-
throw new errors_1.WebWorkbenchError(415, 'Files containing NUL bytes are not editable in the Web Workbench.', 'file_binary');
|
|
43
|
-
}
|
|
44
|
-
const byteLength = Buffer.byteLength(content, 'utf8');
|
|
45
|
-
if (byteLength > MAX_WRITE_BYTES) {
|
|
46
|
-
throw new errors_1.WebWorkbenchError(413, 'Edited file content exceeds the 512 KiB Web editor limit.', 'file_too_large');
|
|
47
|
-
}
|
|
48
|
-
if (!/^[0-9a-f]{64}$/u.test(input.expectedRevision)) {
|
|
49
|
-
throw new errors_1.WebWorkbenchError(400, 'expectedRevision is invalid.', 'file_revision_invalid');
|
|
50
|
-
}
|
|
51
|
-
const preflight = this.fileService.writePreflight(input.fileId);
|
|
52
|
-
if (preflight.sizeBytes > MAX_WRITE_BYTES) {
|
|
53
|
-
throw new errors_1.WebWorkbenchError(413, 'Target file exceeds the 512 KiB Web editor limit.', 'file_too_large');
|
|
54
|
-
}
|
|
55
|
-
const payload = Buffer.from(content, 'utf8');
|
|
56
|
-
// Phase 1 (read descriptor): CAS + binary re-check. An O_WRONLY descriptor
|
|
57
|
-
// cannot readSync, so the preflight opens its own read handle first.
|
|
58
|
-
const readDescriptor = (0, fs_1.openSync)(preflight.canonicalPath, fs_1.constants.O_RDONLY);
|
|
59
|
-
let beforeSize;
|
|
60
|
-
try {
|
|
61
|
-
const before = (0, fs_1.fstatSync)(readDescriptor, { bigint: true });
|
|
62
|
-
beforeSize = before.size;
|
|
63
|
-
const sample = Buffer.alloc(Math.min(WRITE_SAMPLE_BYTES, Number(before.size)));
|
|
64
|
-
if (sample.length > 0) {
|
|
65
|
-
(0, fs_1.readSync)(readDescriptor, sample, 0, sample.length, 0);
|
|
66
|
-
if ((0, file_read_service_1.isBinary)(completeUtf8Tail(sample))) {
|
|
67
|
-
throw new errors_1.WebWorkbenchError(415, 'Target file is not UTF-8 text.', 'file_binary');
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if ((0, file_read_service_1.fingerprintStat)(before) !== input.expectedRevision) {
|
|
71
|
-
throw new errors_1.WebWorkbenchError(409, 'The file changed on disk before the save could run; reload it first.', 'file_revision_conflict');
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
finally {
|
|
75
|
-
(0, fs_1.closeSync)(readDescriptor);
|
|
76
|
-
}
|
|
77
|
-
// Phase 2 (write descriptor): CAS is re-checked by the kernel fingerprint
|
|
78
|
-
// window being as short as possible between the two handles.
|
|
79
|
-
const writeDescriptor = (0, fs_1.openSync)(preflight.canonicalPath, fs_1.constants.O_WRONLY);
|
|
80
|
-
try {
|
|
81
|
-
const before = (0, fs_1.fstatSync)(writeDescriptor, { bigint: true });
|
|
82
|
-
if ((0, file_read_service_1.fingerprintStat)(before) !== input.expectedRevision) {
|
|
83
|
-
throw new errors_1.WebWorkbenchError(409, 'The file changed on disk before the save could run; reload it first.', 'file_revision_conflict');
|
|
84
|
-
}
|
|
85
|
-
(0, fs_1.writeSync)(writeDescriptor, payload, 0, payload.length, 0);
|
|
86
|
-
// Shrink keeps the file exactly as long as the payload.
|
|
87
|
-
if (beforeSize > BigInt(payload.length)) {
|
|
88
|
-
(0, fs_1.truncateSync)(preflight.canonicalPath, payload.length);
|
|
89
|
-
}
|
|
90
|
-
const after = (0, fs_1.statSync)(preflight.canonicalPath, { bigint: true });
|
|
91
|
-
return Object.freeze({
|
|
92
|
-
fileId: input.fileId,
|
|
93
|
-
revision: (0, file_read_service_1.fingerprintStat)(after),
|
|
94
|
-
sizeBytes: Number(after.size),
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
finally {
|
|
98
|
-
(0, fs_1.closeSync)(writeDescriptor);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
exports.FileWriteServiceV1 = FileWriteServiceV1;
|
|
103
|
-
//# sourceMappingURL=file-write-service.js.map
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
export type GitCompareModeV1 = 'snapshot' | 'merge-base';
|
|
2
|
-
export interface GitCompareFileV1 {
|
|
3
|
-
readonly path: string;
|
|
4
|
-
readonly renamedFrom: string | null;
|
|
5
|
-
readonly additions: number;
|
|
6
|
-
readonly deletions: number;
|
|
7
|
-
readonly binary: boolean;
|
|
8
|
-
readonly sensitive: boolean;
|
|
9
|
-
}
|
|
10
|
-
export interface GitCompareResultV1 {
|
|
11
|
-
readonly mode: GitCompareModeV1;
|
|
12
|
-
readonly requestedBaseRef: string;
|
|
13
|
-
readonly requestedHeadRef: string;
|
|
14
|
-
/** The commits the comparison actually used; the UI freezes the result against these. */
|
|
15
|
-
readonly baseOid: string;
|
|
16
|
-
readonly headOid: string;
|
|
17
|
-
readonly baseLabel: string;
|
|
18
|
-
readonly headLabel: string;
|
|
19
|
-
/** Set only in merge-base mode: the divergence point that was used. */
|
|
20
|
-
readonly mergeBaseOid: string | null;
|
|
21
|
-
readonly files: readonly GitCompareFileV1[];
|
|
22
|
-
readonly additions: number;
|
|
23
|
-
readonly deletions: number;
|
|
24
|
-
readonly truncated: boolean;
|
|
25
|
-
}
|
|
26
|
-
export interface GitCompareReaderOptions {
|
|
27
|
-
readonly runGit: (args: readonly string[]) => Promise<string>;
|
|
28
|
-
}
|
|
29
|
-
export declare function createGitCompareReader(options: GitCompareReaderOptions): {
|
|
30
|
-
/** Validates a pair of refs and returns their commits, without computing anything yet. */
|
|
31
|
-
resolvePair(baseRef: string, headRef: string): Promise<Readonly<{
|
|
32
|
-
baseRef: string;
|
|
33
|
-
headRef: string;
|
|
34
|
-
baseOid: string;
|
|
35
|
-
headOid: string;
|
|
36
|
-
baseLabel: string;
|
|
37
|
-
headLabel: string;
|
|
38
|
-
}>>;
|
|
39
|
-
compare(input: {
|
|
40
|
-
readonly baseRef: string;
|
|
41
|
-
readonly headRef: string;
|
|
42
|
-
readonly mode: GitCompareModeV1;
|
|
43
|
-
}): Promise<GitCompareResultV1>;
|
|
44
|
-
};
|
|
45
|
-
//# sourceMappingURL=git-compare-service.d.ts.map
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createGitCompareReader = createGitCompareReader;
|
|
4
|
-
/**
|
|
5
|
-
* v0.3.17 S5 — branch and version comparison (plan G5).
|
|
6
|
-
*
|
|
7
|
-
* Two modes, and the difference between them is the whole point:
|
|
8
|
-
* - `snapshot`: the tree difference between A and B;
|
|
9
|
-
* - `merge-base`: what B introduced since the branches diverged.
|
|
10
|
-
*
|
|
11
|
-
* Semantics this module is responsible for:
|
|
12
|
-
* - refs are resolved to **commits** before anything else, and the resolved OIDs are part of
|
|
13
|
-
* the result, so the UI can detect that a ref moved and freeze the opened result instead
|
|
14
|
-
* of silently comparing against a different tree (plan G5);
|
|
15
|
-
* - `merge-base --all` with more than one answer is refused — picking one candidate would
|
|
16
|
-
* present an arbitrary choice as if it were the unique divergence point, so the caller is
|
|
17
|
-
* told to use the two-endpoint mode instead (plan G5);
|
|
18
|
-
* - no common ancestor and a shallow clone with missing objects produce distinct, explicit
|
|
19
|
-
* errors rather than an empty file list that looks like a legitimate answer;
|
|
20
|
-
* - a ref name is validated before it ever reaches argv: revision expressions, ranges and
|
|
21
|
-
* pathspec magic are refused.
|
|
22
|
-
*/
|
|
23
|
-
const redaction_1 = require("../services/redaction");
|
|
24
|
-
const errors_1 = require("./errors");
|
|
25
|
-
const REF_NAME_PATTERN = /^[0-9A-Za-z](?:[0-9A-Za-z._/-]{0,250}[0-9A-Za-z])?$/u;
|
|
26
|
-
const COMPARE_FILE_LIMIT = 2000;
|
|
27
|
-
/** Resolves a ref-ish name to a commit, refusing anything that is not a plain ref name. */
|
|
28
|
-
function assertRefName(value, name) {
|
|
29
|
-
if (typeof value !== 'string' || !REF_NAME_PATTERN.test(value) || value.includes('..')) {
|
|
30
|
-
throw new errors_1.WebWorkbenchError(400, `${name} must be a branch, tag or commit hash.`, 'git_ref_invalid');
|
|
31
|
-
}
|
|
32
|
-
return value;
|
|
33
|
-
}
|
|
34
|
-
async function resolveCommit(runGit, ref) {
|
|
35
|
-
const resolved = (await runGit(['rev-parse', '--verify', '--quiet', `${ref}^{commit}`]).catch(() => ''))
|
|
36
|
-
.toString()
|
|
37
|
-
.trim();
|
|
38
|
-
if (!/^[0-9a-f]{7,64}$/iu.test(resolved)) {
|
|
39
|
-
throw new errors_1.WebWorkbenchError(404, `The ref ${ref} could not be resolved to a commit.`, 'git_ref_not_found');
|
|
40
|
-
}
|
|
41
|
-
return resolved;
|
|
42
|
-
}
|
|
43
|
-
function createGitCompareReader(options) {
|
|
44
|
-
const { runGit } = options;
|
|
45
|
-
const numstat = async (base, head) => {
|
|
46
|
-
const raw = await runGit([
|
|
47
|
-
'diff',
|
|
48
|
-
'--numstat',
|
|
49
|
-
'-z',
|
|
50
|
-
'--no-ext-diff',
|
|
51
|
-
'--no-textconv',
|
|
52
|
-
base,
|
|
53
|
-
head,
|
|
54
|
-
]);
|
|
55
|
-
const files = [];
|
|
56
|
-
const fields = raw.split('\0');
|
|
57
|
-
let index = 0;
|
|
58
|
-
while (index < fields.length) {
|
|
59
|
-
const record = fields[index];
|
|
60
|
-
index += 1;
|
|
61
|
-
if (!record)
|
|
62
|
-
continue;
|
|
63
|
-
const [added, deleted, inlinePath] = record.split('\t');
|
|
64
|
-
let path = inlinePath ?? '';
|
|
65
|
-
let renamedFrom = null;
|
|
66
|
-
if (path === '' && index + 1 < fields.length) {
|
|
67
|
-
renamedFrom = fields[index];
|
|
68
|
-
path = fields[index + 1];
|
|
69
|
-
index += 2;
|
|
70
|
-
}
|
|
71
|
-
if (!path)
|
|
72
|
-
continue;
|
|
73
|
-
const binary = added === '-' || deleted === '-';
|
|
74
|
-
files.push(Object.freeze({
|
|
75
|
-
path,
|
|
76
|
-
renamedFrom: renamedFrom || null,
|
|
77
|
-
additions: binary ? 0 : Number(added) || 0,
|
|
78
|
-
deletions: binary ? 0 : Number(deleted) || 0,
|
|
79
|
-
binary,
|
|
80
|
-
sensitive: (0, redaction_1.isSensitiveFilePath)(path),
|
|
81
|
-
}));
|
|
82
|
-
if (files.length >= COMPARE_FILE_LIMIT)
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
return Object.freeze({
|
|
86
|
-
files,
|
|
87
|
-
additions: files.reduce((sum, file) => sum + file.additions, 0),
|
|
88
|
-
deletions: files.reduce((sum, file) => sum + file.deletions, 0),
|
|
89
|
-
truncated: files.length >= COMPARE_FILE_LIMIT,
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
|
-
return {
|
|
93
|
-
/** Validates a pair of refs and returns their commits, without computing anything yet. */
|
|
94
|
-
async resolvePair(baseRef, headRef) {
|
|
95
|
-
const base = assertRefName(baseRef, 'base');
|
|
96
|
-
const head = assertRefName(headRef, 'head');
|
|
97
|
-
const [baseOid, headOid] = await Promise.all([
|
|
98
|
-
resolveCommit(runGit, base),
|
|
99
|
-
resolveCommit(runGit, head),
|
|
100
|
-
]);
|
|
101
|
-
return Object.freeze({
|
|
102
|
-
baseRef: base,
|
|
103
|
-
headRef: head,
|
|
104
|
-
baseOid,
|
|
105
|
-
headOid,
|
|
106
|
-
baseLabel: base,
|
|
107
|
-
headLabel: head,
|
|
108
|
-
});
|
|
109
|
-
},
|
|
110
|
-
async compare(input) {
|
|
111
|
-
const pair = await this.resolvePair(input.baseRef, input.headRef);
|
|
112
|
-
const mode = input.mode === 'merge-base' ? 'merge-base' : 'snapshot';
|
|
113
|
-
let baseOid = pair.baseOid;
|
|
114
|
-
let mergeBaseOid = null;
|
|
115
|
-
if (mode === 'merge-base') {
|
|
116
|
-
// `--all` is the honest way to ask: a single answer means one divergence point, and
|
|
117
|
-
// more than one means the question has no unique answer.
|
|
118
|
-
const raw = await runGit(['merge-base', '--all', pair.baseOid, pair.headOid]).catch(error => {
|
|
119
|
-
const message = error instanceof Error ? error.message : '';
|
|
120
|
-
if (/missing|bad object/iu.test(message)) {
|
|
121
|
-
throw new errors_1.WebWorkbenchError(409, 'The repository does not contain the objects needed for this comparison (a shallow clone?).', 'git_shallow_history');
|
|
122
|
-
}
|
|
123
|
-
// git exits non-zero with no candidates when the histories are unrelated, and with
|
|
124
|
-
// a diagnostic when objects are missing — those are different failures.
|
|
125
|
-
throw new errors_1.WebWorkbenchError(409, 'The two refs have no common ancestor; use the two-endpoint comparison instead.', 'git_merge_base_missing');
|
|
126
|
-
});
|
|
127
|
-
const candidates = raw
|
|
128
|
-
.split('\n')
|
|
129
|
-
.map(line => line.trim())
|
|
130
|
-
.filter(line => /^[0-9a-f]{7,64}$/iu.test(line));
|
|
131
|
-
if (candidates.length === 0) {
|
|
132
|
-
throw new errors_1.WebWorkbenchError(409, 'The two refs have no common ancestor; use the two-endpoint comparison instead.', 'git_merge_base_missing');
|
|
133
|
-
}
|
|
134
|
-
if (candidates.length > 1) {
|
|
135
|
-
throw new errors_1.WebWorkbenchError(409, `These refs have ${candidates.length} merge bases, so there is no unique divergence point. Use the two-endpoint comparison instead.`, 'git_merge_base_multiple');
|
|
136
|
-
}
|
|
137
|
-
mergeBaseOid = candidates[0];
|
|
138
|
-
baseOid = mergeBaseOid;
|
|
139
|
-
}
|
|
140
|
-
const stats = await numstat(baseOid, pair.headOid);
|
|
141
|
-
return Object.freeze({
|
|
142
|
-
mode,
|
|
143
|
-
requestedBaseRef: pair.baseRef,
|
|
144
|
-
requestedHeadRef: pair.headRef,
|
|
145
|
-
baseOid,
|
|
146
|
-
headOid: pair.headOid,
|
|
147
|
-
baseLabel: mode === 'merge-base' && mergeBaseOid !== null
|
|
148
|
-
? `共同祖先 ${mergeBaseOid.slice(0, 10)}`
|
|
149
|
-
: pair.baseLabel,
|
|
150
|
-
headLabel: pair.headLabel,
|
|
151
|
-
mergeBaseOid,
|
|
152
|
-
files: stats.files,
|
|
153
|
-
additions: stats.additions,
|
|
154
|
-
deletions: stats.deletions,
|
|
155
|
-
truncated: stats.truncated,
|
|
156
|
-
});
|
|
157
|
-
},
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
//# sourceMappingURL=git-compare-service.js.map
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* v0.3.17 S2 — structured Git diff document.
|
|
3
|
-
*
|
|
4
|
-
* The v1 diff page exposed raw unified-diff text lines and a `## Staged` style section
|
|
5
|
-
* banner. That shape made line numbers, side-by-side rendering, hunk folding and the
|
|
6
|
-
* "jump to next change" navigation impossible without re-parsing text in the browser.
|
|
7
|
-
*
|
|
8
|
-
* This module parses the raw lines the Host already produces into a hunk/line model with
|
|
9
|
-
* real old/new line numbers, a stable line id, per-hunk completeness, and the write
|
|
10
|
-
* capabilities that apply to the selected comparison source.
|
|
11
|
-
*
|
|
12
|
-
* Deliberate limits for S2:
|
|
13
|
-
* - No hunk or line level writes. `capabilities.stageHunk` / `stageLines` are always
|
|
14
|
-
* false and carry a reason; staging granularity is S3 (plan §10).
|
|
15
|
-
* - Word level highlighting and ignore-whitespace views are S5. This model preserves the
|
|
16
|
-
* original text so those can be computed later without a protocol change.
|
|
17
|
-
*/
|
|
18
|
-
import type { WebGitFileSourceV1 } from './git-file-source';
|
|
19
|
-
export type GitDiffLineKindV2 = 'context' | 'addition' | 'deletion' | 'meta';
|
|
20
|
-
export interface GitDiffLineV2 {
|
|
21
|
-
/** Stable inside one document: `<hunkId>#<index>`. */
|
|
22
|
-
readonly lineId: string;
|
|
23
|
-
readonly kind: GitDiffLineKindV2;
|
|
24
|
-
readonly oldLineNumber: number | null;
|
|
25
|
-
readonly newLineNumber: number | null;
|
|
26
|
-
/** Content without the leading `+`/`-`/space marker. */
|
|
27
|
-
readonly text: string;
|
|
28
|
-
/** The original line including its marker, so copy never loses fidelity. */
|
|
29
|
-
readonly raw: string;
|
|
30
|
-
}
|
|
31
|
-
export interface GitHunkV2 {
|
|
32
|
-
readonly hunkId: string;
|
|
33
|
-
readonly header: string;
|
|
34
|
-
readonly oldStart: number;
|
|
35
|
-
readonly oldLines: number;
|
|
36
|
-
readonly newStart: number;
|
|
37
|
-
readonly newLines: number;
|
|
38
|
-
readonly contextLabel: string;
|
|
39
|
-
readonly lines: readonly GitDiffLineV2[];
|
|
40
|
-
/** False when pagination cut this hunk; partial hunks must not be written (plan G3). */
|
|
41
|
-
readonly complete: boolean;
|
|
42
|
-
}
|
|
43
|
-
export type GitDiffDocumentKindV2 = 'text' | 'binary' | 'symlink' | 'submodule' | 'metadata';
|
|
44
|
-
/**
|
|
45
|
-
* v0.3.26 #275 — parser state for a hunk that a page boundary split. Carried in
|
|
46
|
-
* the continuation cursor so the next page re-opens the hunk with its stable
|
|
47
|
-
* identity (`index:oldStart:newStart`) and correct running line cursors instead
|
|
48
|
-
* of demoting the continuation rows to document meta.
|
|
49
|
-
*/
|
|
50
|
-
export interface GitDiffHunkResumeV1 {
|
|
51
|
-
readonly header: string;
|
|
52
|
-
readonly index: number;
|
|
53
|
-
readonly oldCursor: number;
|
|
54
|
-
readonly newCursor: number;
|
|
55
|
-
}
|
|
56
|
-
export interface GitDiffCapabilitiesV2 {
|
|
57
|
-
readonly stageFile: boolean;
|
|
58
|
-
readonly unstageFile: boolean;
|
|
59
|
-
readonly stageHunk: boolean;
|
|
60
|
-
readonly unstageHunk: boolean;
|
|
61
|
-
readonly stageLines: boolean;
|
|
62
|
-
readonly reason?: string;
|
|
63
|
-
}
|
|
64
|
-
export interface GitDiffDocumentV2 {
|
|
65
|
-
readonly schemaVersion: 2;
|
|
66
|
-
readonly fileToken: string;
|
|
67
|
-
readonly path: string;
|
|
68
|
-
readonly source: WebGitFileSourceV1;
|
|
69
|
-
/** Set only for a historical comparison: the base tree and how it was chosen. */
|
|
70
|
-
readonly baseOid?: string;
|
|
71
|
-
readonly baseLabel?: string;
|
|
72
|
-
readonly repositoryRevision: string;
|
|
73
|
-
readonly kind: GitDiffDocumentKindV2;
|
|
74
|
-
readonly binary: boolean;
|
|
75
|
-
readonly hunks: readonly GitHunkV2[];
|
|
76
|
-
/** Metadata lines that are not part of any hunk (file headers, mode changes, …). */
|
|
77
|
-
readonly meta: readonly string[];
|
|
78
|
-
/**
|
|
79
|
-
* v0.3.26 #275 — the hunk still open when this page ended, for the
|
|
80
|
-
* continuation cursor. Null when the page ends on a hunk boundary.
|
|
81
|
-
*/
|
|
82
|
-
readonly pendingHunk: GitDiffHunkResumeV1 | null;
|
|
83
|
-
readonly completeness: 'complete' | 'paged' | 'limited';
|
|
84
|
-
readonly additions: number;
|
|
85
|
-
readonly deletions: number;
|
|
86
|
-
readonly lineCount: number;
|
|
87
|
-
readonly nextCursor: string | null;
|
|
88
|
-
readonly capabilities: GitDiffCapabilitiesV2;
|
|
89
|
-
}
|
|
90
|
-
export declare function parseGitDiffDocument(input: {
|
|
91
|
-
readonly fileToken: string;
|
|
92
|
-
readonly path: string;
|
|
93
|
-
readonly source: WebGitFileSourceV1;
|
|
94
|
-
readonly repositoryRevision: string;
|
|
95
|
-
readonly lines: readonly string[];
|
|
96
|
-
readonly hasMore: boolean;
|
|
97
|
-
/** Host-signed continuation cursor, or null. Never synthesised here. */
|
|
98
|
-
readonly nextCursor: string | null;
|
|
99
|
-
/** v0.3.26 #275 — hunk state from the previous page's `pendingHunk`. */
|
|
100
|
-
readonly resume?: GitDiffHunkResumeV1 | null;
|
|
101
|
-
}): GitDiffDocumentV2;
|
|
102
|
-
//# sourceMappingURL=git-diff-document.d.ts.map
|
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseGitDiffDocument = parseGitDiffDocument;
|
|
4
|
-
const HUNK_HEADER = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)$/u;
|
|
5
|
-
const NO_NEWLINE = '\';
|
|
6
|
-
/** Document level header lines Git emits before the first hunk. */
|
|
7
|
-
function isMetaLine(line) {
|
|
8
|
-
return (line.startsWith('## ') ||
|
|
9
|
-
line.startsWith('diff --git ') ||
|
|
10
|
-
line.startsWith('index ') ||
|
|
11
|
-
line.startsWith('--- ') ||
|
|
12
|
-
line.startsWith('+++ ') ||
|
|
13
|
-
line.startsWith('new file mode ') ||
|
|
14
|
-
line.startsWith('deleted file mode ') ||
|
|
15
|
-
line.startsWith('old mode ') ||
|
|
16
|
-
line.startsWith('new mode ') ||
|
|
17
|
-
line.startsWith('similarity index ') ||
|
|
18
|
-
line.startsWith('dissimilarity index ') ||
|
|
19
|
-
line.startsWith('rename from ') ||
|
|
20
|
-
line.startsWith('rename to ') ||
|
|
21
|
-
line.startsWith('copy from ') ||
|
|
22
|
-
line.startsWith('copy to ') ||
|
|
23
|
-
line.startsWith('Binary files ') ||
|
|
24
|
-
line.startsWith('GIT binary patch') ||
|
|
25
|
-
line.startsWith('Submodule '));
|
|
26
|
-
}
|
|
27
|
-
function detectKind(lines) {
|
|
28
|
-
if (lines.some(line => line.startsWith('Binary files ') || line.startsWith('GIT binary patch'))) {
|
|
29
|
-
return 'binary';
|
|
30
|
-
}
|
|
31
|
-
if (lines.some(line => line.startsWith('Submodule ')))
|
|
32
|
-
return 'submodule';
|
|
33
|
-
if (lines.some(line => line.startsWith('old mode ') || line.startsWith('new mode '))) {
|
|
34
|
-
return 'metadata';
|
|
35
|
-
}
|
|
36
|
-
return 'text';
|
|
37
|
-
}
|
|
38
|
-
/** Write capabilities implied by the comparison source. */
|
|
39
|
-
function capabilitiesFor(source) {
|
|
40
|
-
const hunkWritesUnavailable = 'Hunk 与选中行级写入将在 S3 提供。';
|
|
41
|
-
if (source === 'staged') {
|
|
42
|
-
return Object.freeze({
|
|
43
|
-
stageFile: false,
|
|
44
|
-
unstageFile: true,
|
|
45
|
-
stageHunk: false,
|
|
46
|
-
unstageHunk: false,
|
|
47
|
-
stageLines: false,
|
|
48
|
-
reason: hunkWritesUnavailable,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
if (source === 'unstaged' || source === 'untracked') {
|
|
52
|
-
return Object.freeze({
|
|
53
|
-
stageFile: true,
|
|
54
|
-
unstageFile: false,
|
|
55
|
-
stageHunk: false,
|
|
56
|
-
unstageHunk: false,
|
|
57
|
-
stageLines: false,
|
|
58
|
-
reason: hunkWritesUnavailable,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
return Object.freeze({
|
|
62
|
-
stageFile: false,
|
|
63
|
-
unstageFile: false,
|
|
64
|
-
stageHunk: false,
|
|
65
|
-
unstageHunk: false,
|
|
66
|
-
stageLines: false,
|
|
67
|
-
reason: '冲突文件本版不提供一键解决,请在 Files 打开处理。',
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
function parseGitDiffDocument(input) {
|
|
71
|
-
const kind = detectKind(input.lines);
|
|
72
|
-
const binary = kind === 'binary';
|
|
73
|
-
const meta = [];
|
|
74
|
-
const hunks = [];
|
|
75
|
-
let additions = 0;
|
|
76
|
-
let deletions = 0;
|
|
77
|
-
let current;
|
|
78
|
-
const openHunk = (header, index, oldCursor, newCursor) => {
|
|
79
|
-
const headerMatch = HUNK_HEADER.exec(header);
|
|
80
|
-
if (!headerMatch)
|
|
81
|
-
return;
|
|
82
|
-
const oldStart = Number(headerMatch[1]);
|
|
83
|
-
const newStart = Number(headerMatch[3]);
|
|
84
|
-
current = {
|
|
85
|
-
header,
|
|
86
|
-
oldStart,
|
|
87
|
-
oldLines: headerMatch[2] === undefined ? 1 : Number(headerMatch[2]),
|
|
88
|
-
newStart,
|
|
89
|
-
newLines: headerMatch[4] === undefined ? 1 : Number(headerMatch[4]),
|
|
90
|
-
contextLabel: (headerMatch[5] ?? '').trim(),
|
|
91
|
-
lines: [],
|
|
92
|
-
oldCursor,
|
|
93
|
-
newCursor,
|
|
94
|
-
index,
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
// v0.3.26 #275 — a continuation page starts mid-hunk: re-open it from the
|
|
98
|
-
// resume state before the first line is classified. A page that happens to
|
|
99
|
-
// start with its own `@@` header simply ignores the resume state.
|
|
100
|
-
if (input.resume && !HUNK_HEADER.test(input.lines[0] ?? '')) {
|
|
101
|
-
openHunk(input.resume.header, input.resume.index, input.resume.oldCursor, input.resume.newCursor);
|
|
102
|
-
}
|
|
103
|
-
const closeHunk = () => {
|
|
104
|
-
if (!current)
|
|
105
|
-
return;
|
|
106
|
-
const hunkId = `${current.index}:${current.oldStart}:${current.newStart}`;
|
|
107
|
-
// A hunk is complete when it accounts for every line its header promised. The final
|
|
108
|
-
// hunk of a paged read is reported incomplete so callers cannot write a partial patch.
|
|
109
|
-
const consumedOld = current.oldCursor - current.oldStart;
|
|
110
|
-
const consumedNew = current.newCursor - current.newStart;
|
|
111
|
-
const reached = consumedOld >= current.oldLines && consumedNew >= current.newLines;
|
|
112
|
-
hunks.push(Object.freeze({
|
|
113
|
-
hunkId,
|
|
114
|
-
header: current.header,
|
|
115
|
-
oldStart: current.oldStart,
|
|
116
|
-
oldLines: current.oldLines,
|
|
117
|
-
newStart: current.newStart,
|
|
118
|
-
newLines: current.newLines,
|
|
119
|
-
contextLabel: current.contextLabel,
|
|
120
|
-
lines: Object.freeze(current.lines),
|
|
121
|
-
complete: reached,
|
|
122
|
-
}));
|
|
123
|
-
current = undefined;
|
|
124
|
-
};
|
|
125
|
-
for (const raw of input.lines) {
|
|
126
|
-
const headerMatch = HUNK_HEADER.exec(raw);
|
|
127
|
-
if (headerMatch) {
|
|
128
|
-
closeHunk();
|
|
129
|
-
const oldStart = Number(headerMatch[1]);
|
|
130
|
-
const newStart = Number(headerMatch[3]);
|
|
131
|
-
current = {
|
|
132
|
-
header: raw,
|
|
133
|
-
oldStart,
|
|
134
|
-
oldLines: headerMatch[2] === undefined ? 1 : Number(headerMatch[2]),
|
|
135
|
-
newStart,
|
|
136
|
-
newLines: headerMatch[4] === undefined ? 1 : Number(headerMatch[4]),
|
|
137
|
-
contextLabel: (headerMatch[5] ?? '').trim(),
|
|
138
|
-
lines: [],
|
|
139
|
-
oldCursor: oldStart,
|
|
140
|
-
newCursor: newStart,
|
|
141
|
-
index: hunks.length,
|
|
142
|
-
};
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
if (!current) {
|
|
146
|
-
// Everything before the first hunk is document metadata.
|
|
147
|
-
if (raw)
|
|
148
|
-
meta.push(raw);
|
|
149
|
-
continue;
|
|
150
|
-
}
|
|
151
|
-
if (raw === NO_NEWLINE) {
|
|
152
|
-
current.lines.push(Object.freeze({
|
|
153
|
-
lineId: `${current.index}:${current.oldStart}:${current.newStart}#${current.lines.length}`,
|
|
154
|
-
kind: 'meta',
|
|
155
|
-
oldLineNumber: null,
|
|
156
|
-
newLineNumber: null,
|
|
157
|
-
text: raw,
|
|
158
|
-
raw,
|
|
159
|
-
}));
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
|
-
// v0.3.26 #274 — the body marker decides first. A deletion of a line that
|
|
163
|
-
// itself starts with `-- ` produces the body row `--- old comment`, which a
|
|
164
|
-
// header-first check mistook for the old-file header, closing the hunk and
|
|
165
|
-
// demoting the remaining body to document meta. Genuine document-level lines
|
|
166
|
-
// carry no body marker by construction: context rows start with a space,
|
|
167
|
-
// additions with `+`, deletions with `-`, and file boundaries are announced
|
|
168
|
-
// by a markerless `diff --git` line.
|
|
169
|
-
const marker = raw[0];
|
|
170
|
-
const isBodyRow = marker === '+' || marker === '-' || marker === ' ' || raw === '';
|
|
171
|
-
if (!isBodyRow && isMetaLine(raw)) {
|
|
172
|
-
// A file boundary inside one page (multi-command reads) closes the current hunk.
|
|
173
|
-
closeHunk();
|
|
174
|
-
if (raw)
|
|
175
|
-
meta.push(raw);
|
|
176
|
-
continue;
|
|
177
|
-
}
|
|
178
|
-
const text = raw.length > 0 ? raw.slice(1) : '';
|
|
179
|
-
let lineKind;
|
|
180
|
-
let oldLineNumber = null;
|
|
181
|
-
let newLineNumber = null;
|
|
182
|
-
if (marker === '+') {
|
|
183
|
-
lineKind = 'addition';
|
|
184
|
-
newLineNumber = current.newCursor;
|
|
185
|
-
current.newCursor += 1;
|
|
186
|
-
additions += 1;
|
|
187
|
-
}
|
|
188
|
-
else if (marker === '-') {
|
|
189
|
-
lineKind = 'deletion';
|
|
190
|
-
oldLineNumber = current.oldCursor;
|
|
191
|
-
current.oldCursor += 1;
|
|
192
|
-
deletions += 1;
|
|
193
|
-
}
|
|
194
|
-
else if (marker === ' ') {
|
|
195
|
-
lineKind = 'context';
|
|
196
|
-
oldLineNumber = current.oldCursor;
|
|
197
|
-
newLineNumber = current.newCursor;
|
|
198
|
-
current.oldCursor += 1;
|
|
199
|
-
current.newCursor += 1;
|
|
200
|
-
}
|
|
201
|
-
else if (raw === '') {
|
|
202
|
-
// An empty line in a hunk body is a context line for an empty source line.
|
|
203
|
-
lineKind = 'context';
|
|
204
|
-
oldLineNumber = current.oldCursor;
|
|
205
|
-
newLineNumber = current.newCursor;
|
|
206
|
-
current.oldCursor += 1;
|
|
207
|
-
current.newCursor += 1;
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
lineKind = 'meta';
|
|
211
|
-
}
|
|
212
|
-
current.lines.push(Object.freeze({
|
|
213
|
-
lineId: `${current.index}:${current.oldStart}:${current.newStart}#${current.lines.length}`,
|
|
214
|
-
kind: lineKind,
|
|
215
|
-
oldLineNumber,
|
|
216
|
-
newLineNumber,
|
|
217
|
-
text,
|
|
218
|
-
raw,
|
|
219
|
-
}));
|
|
220
|
-
}
|
|
221
|
-
// v0.3.26 #275 — a page that ends inside a hunk publishes the hunk state for
|
|
222
|
-
// the continuation cursor; a page ending on a boundary has nothing to resume.
|
|
223
|
-
const pendingHunk = input.hasMore && current
|
|
224
|
-
? Object.freeze({
|
|
225
|
-
header: current.header,
|
|
226
|
-
index: current.index,
|
|
227
|
-
oldCursor: current.oldCursor,
|
|
228
|
-
newCursor: current.newCursor,
|
|
229
|
-
})
|
|
230
|
-
: null;
|
|
231
|
-
closeHunk();
|
|
232
|
-
const frozenHunks = Object.freeze(hunks);
|
|
233
|
-
let completeness = 'complete';
|
|
234
|
-
if (input.hasMore)
|
|
235
|
-
completeness = 'paged';
|
|
236
|
-
else if (frozenHunks.some(hunk => !hunk.complete))
|
|
237
|
-
completeness = 'limited';
|
|
238
|
-
return Object.freeze({
|
|
239
|
-
schemaVersion: 2,
|
|
240
|
-
fileToken: input.fileToken,
|
|
241
|
-
// A digest keeps the document self-describing without leaking the raw path shape.
|
|
242
|
-
path: input.path,
|
|
243
|
-
source: input.source,
|
|
244
|
-
repositoryRevision: input.repositoryRevision,
|
|
245
|
-
kind,
|
|
246
|
-
binary,
|
|
247
|
-
hunks: frozenHunks,
|
|
248
|
-
meta: Object.freeze(meta),
|
|
249
|
-
pendingHunk,
|
|
250
|
-
completeness,
|
|
251
|
-
additions,
|
|
252
|
-
deletions,
|
|
253
|
-
lineCount: input.lines.length,
|
|
254
|
-
nextCursor: input.nextCursor,
|
|
255
|
-
capabilities: capabilitiesFor(input.source),
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
//# sourceMappingURL=git-diff-document.js.map
|