@jmoyers/harness 0.1.10 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -35
- package/package.json +31 -11
- package/packages/harness-ai/src/anthropic-protocol.ts +68 -68
- package/packages/harness-ai/src/stream-text.ts +13 -91
- package/packages/harness-ui/src/frame-primitives.ts +158 -0
- package/packages/harness-ui/src/index.ts +18 -0
- package/packages/harness-ui/src/interaction/conversation-input-forwarder.ts +221 -0
- package/packages/harness-ui/src/interaction/conversation-selection-input.ts +213 -0
- package/packages/harness-ui/src/interaction/global-shortcut-input.ts +172 -0
- package/{src/ui → packages/harness-ui/src/interaction}/input-preflight.ts +10 -12
- package/{src/ui → packages/harness-ui/src/interaction}/input-token-router.ts +120 -69
- package/packages/harness-ui/src/interaction/input.ts +420 -0
- package/packages/harness-ui/src/interaction/left-nav-input.ts +166 -0
- package/{src/ui → packages/harness-ui/src/interaction}/main-pane-pointer-input.ts +91 -23
- package/{src/ui → packages/harness-ui/src/interaction}/pointer-routing-input.ts +112 -48
- package/packages/harness-ui/src/interaction/rail-pointer-input.ts +62 -0
- package/packages/harness-ui/src/interaction/repository-fold-input.ts +118 -0
- package/packages/harness-ui/src/kit.ts +476 -0
- package/packages/harness-ui/src/layout.ts +238 -0
- package/{src/ui/modals/manager.ts → packages/harness-ui/src/modal-manager.ts} +94 -64
- package/{src/ui → packages/harness-ui/src}/screen.ts +53 -26
- package/packages/harness-ui/src/surface.ts +252 -0
- package/packages/harness-ui/src/text-layout.ts +210 -0
- package/packages/nim-core/src/contracts.ts +239 -0
- package/packages/nim-core/src/event-store.ts +299 -0
- package/packages/nim-core/src/events.ts +53 -0
- package/packages/nim-core/src/index.ts +9 -0
- package/packages/nim-core/src/provider-router.ts +129 -0
- package/packages/nim-core/src/providers/anthropic-driver.ts +291 -0
- package/packages/nim-core/src/runtime-factory.ts +49 -0
- package/packages/nim-core/src/runtime.ts +1797 -0
- package/packages/nim-core/src/session-store.ts +516 -0
- package/packages/nim-core/src/telemetry.ts +48 -0
- package/packages/nim-test-tui/src/index.ts +150 -0
- package/packages/nim-ui-core/src/index.ts +1 -0
- package/packages/nim-ui-core/src/projection.ts +87 -0
- package/scripts/codex-live-mux-runtime.ts +2 -3721
- package/scripts/control-plane-daemon.ts +24 -2
- package/scripts/harness-bin.js +5 -0
- package/scripts/harness-commands.ts +300 -0
- package/scripts/harness-runtime.ts +82 -0
- package/scripts/harness.ts +33 -3007
- package/scripts/nim-tui-smoke.ts +748 -0
- package/src/cli/auth/runtime.ts +948 -0
- package/src/cli/default-gateway-pointer.ts +193 -0
- package/src/cli/gateway/runtime.ts +1872 -0
- package/src/cli/parsing/flags.ts +23 -0
- package/src/cli/parsing/session.ts +42 -0
- package/src/cli/runtime/context.ts +193 -0
- package/src/cli/runtime-app/application.ts +392 -0
- package/src/cli/runtime-infra/gateway-control.ts +729 -0
- package/{scripts/harness-inspector.ts → src/cli/workflows/inspector.ts} +14 -11
- package/src/cli/workflows/runtime.ts +965 -0
- package/src/clients/tui/left-rail-interactions.ts +519 -0
- package/src/clients/tui/main-pane-interactions.ts +509 -0
- package/src/clients/tui/modal-input-routing.ts +71 -0
- package/src/clients/tui/render-snapshot-adapter.ts +88 -0
- package/src/clients/web/synced-selectors.ts +132 -0
- package/src/codex/live-session.ts +82 -29
- package/src/config/config-core.ts +361 -10
- package/src/config/harness-paths.ts +4 -7
- package/src/config/harness-runtime-migration.ts +142 -19
- package/src/config/harness.config.template.jsonc +33 -0
- package/src/config/secrets-core.ts +92 -4
- package/src/control-plane/agent-realtime-api.ts +82 -427
- package/src/control-plane/prompt/thread-title-namer.ts +49 -23
- package/src/control-plane/session-summary.ts +10 -81
- package/src/control-plane/status/reducer-base.ts +12 -12
- package/src/control-plane/status/reducers/claude-status-reducer.ts +3 -3
- package/src/control-plane/status/reducers/codex-status-reducer.ts +4 -4
- package/src/control-plane/status/reducers/cursor-status-reducer.ts +3 -3
- package/src/control-plane/stream-client.ts +12 -2
- package/src/control-plane/stream-command-parser.ts +83 -143
- package/src/control-plane/stream-protocol.ts +53 -37
- package/src/control-plane/stream-server-background.ts +18 -2
- package/src/control-plane/stream-server-command.ts +376 -69
- package/src/control-plane/stream-server-session-runtime.ts +3 -2
- package/src/control-plane/stream-server.ts +943 -80
- package/src/control-plane/stream-session-runtime-types.ts +41 -0
- package/src/{mux/live-mux/control-plane-records.ts → core/contracts/records.ts} +24 -97
- package/src/core/state/observed-stream-cursor.ts +43 -0
- package/src/core/state/synced-observed-state.ts +273 -0
- package/src/core/store/harness-synced-store.ts +81 -0
- package/src/diff/budget.ts +136 -0
- package/src/diff/build.ts +289 -0
- package/src/diff/chunker.ts +146 -0
- package/src/diff/git-invoke.ts +315 -0
- package/src/diff/git-parse.ts +472 -0
- package/src/diff/hash.ts +70 -0
- package/src/diff/index.ts +24 -0
- package/src/diff/normalize.ts +134 -0
- package/src/diff/types.ts +178 -0
- package/src/diff-ui/args.ts +346 -0
- package/src/diff-ui/commands.ts +123 -0
- package/src/diff-ui/finder.ts +94 -0
- package/src/diff-ui/highlight.ts +127 -0
- package/src/diff-ui/index.ts +2 -0
- package/src/diff-ui/model.ts +141 -0
- package/src/diff-ui/pager.ts +412 -0
- package/src/diff-ui/render.ts +337 -0
- package/src/diff-ui/runtime.ts +379 -0
- package/src/diff-ui/state.ts +224 -0
- package/src/diff-ui/types.ts +236 -0
- package/src/domain/conversations.ts +11 -7
- package/src/domain/workspace.ts +76 -4
- package/src/mux/control-plane-op-queue.ts +93 -7
- package/src/mux/conversation-rail.ts +28 -71
- package/src/mux/dual-pane-core.ts +13 -13
- package/src/mux/harness-core-ui.ts +313 -42
- package/src/mux/input-shortcuts.ts +22 -112
- package/src/mux/keybinding-catalog.ts +340 -0
- package/src/mux/keybinding-registry.ts +103 -0
- package/src/mux/live-mux/command-menu-open-in.ts +280 -0
- package/src/mux/live-mux/command-menu.ts +167 -4
- package/src/mux/live-mux/conversation-state.ts +13 -0
- package/src/mux/live-mux/directory-resolution.ts +1 -1
- package/src/mux/live-mux/git-parsing.ts +16 -0
- package/src/mux/live-mux/git-snapshot.ts +33 -2
- package/src/mux/live-mux/global-shortcut-handlers.ts +6 -0
- package/src/mux/live-mux/home-pane-drop.ts +1 -1
- package/src/mux/live-mux/home-pane-pointer.ts +10 -0
- package/src/mux/live-mux/input-forwarding.ts +59 -2
- package/src/mux/live-mux/left-nav-activation.ts +124 -7
- package/src/mux/live-mux/left-nav.ts +35 -0
- package/src/mux/live-mux/link-click.ts +292 -0
- package/src/mux/live-mux/modal-command-menu-handler.ts +46 -9
- package/src/mux/live-mux/modal-conversation-handlers.ts +5 -1
- package/src/mux/live-mux/modal-input-reducers.ts +106 -8
- package/src/mux/live-mux/modal-overlays.ts +210 -31
- package/src/mux/live-mux/modal-pointer.ts +3 -7
- package/src/mux/live-mux/modal-prompt-handlers.ts +107 -1
- package/src/mux/live-mux/modal-release-notes-handler.ts +111 -0
- package/src/mux/live-mux/modal-task-editor-handler.ts +16 -11
- package/src/mux/live-mux/pointer-routing.ts +5 -2
- package/src/mux/live-mux/project-pane-pointer.ts +8 -0
- package/src/mux/live-mux/rail-layout.ts +33 -30
- package/src/mux/live-mux/release-notes.ts +383 -0
- package/src/mux/live-mux/render-trace-analysis.ts +52 -7
- package/src/mux/live-mux/repository-folding.ts +3 -0
- package/src/mux/live-mux/selection.ts +0 -4
- package/src/mux/live-mux/session-diagnostics-paths.ts +21 -0
- package/src/mux/project-pane-github-review.ts +271 -0
- package/src/mux/render-frame.ts +4 -0
- package/src/mux/runtime-app/codex-live-mux-runtime.ts +5191 -0
- package/src/mux/task-composer.ts +21 -14
- package/src/mux/task-focused-pane.ts +118 -117
- package/src/mux/task-screen-keybindings.ts +19 -82
- package/src/mux/workspace-rail-model.ts +270 -104
- package/src/mux/workspace-rail.ts +45 -22
- package/src/pty/session-broker.ts +1 -1
- package/{scripts → src/recording}/terminal-recording-gif-lib.ts +2 -2
- package/src/services/control-plane.ts +50 -32
- package/src/services/conversation-lifecycle.ts +118 -87
- package/src/services/conversation-startup-hydration.ts +20 -12
- package/src/services/directory-hydration.ts +21 -16
- package/src/services/event-persistence.ts +7 -0
- package/src/services/left-rail-pointer-handler.ts +329 -0
- package/src/services/mux-ui-state-persistence.ts +5 -1
- package/src/services/recording.ts +34 -26
- package/src/services/runtime-command-menu-agent-tools.ts +1 -1
- package/src/services/runtime-control-actions.ts +79 -61
- package/src/services/runtime-control-plane-ops.ts +122 -83
- package/src/services/runtime-conversation-actions.ts +40 -26
- package/src/services/runtime-conversation-activation.ts +82 -30
- package/src/services/runtime-conversation-starter.ts +80 -48
- package/src/services/runtime-conversation-title-edit.ts +91 -80
- package/src/services/runtime-envelope-handler.ts +107 -105
- package/src/services/runtime-git-state.ts +42 -29
- package/src/services/runtime-layout-resize.ts +3 -1
- package/src/services/runtime-left-rail-render.ts +99 -63
- package/src/services/runtime-nim-cli-session.ts +438 -0
- package/src/services/runtime-nim-session.ts +705 -0
- package/src/services/runtime-nim-tool-bridge.ts +141 -0
- package/src/services/runtime-observed-event-projection-pipeline.ts +45 -0
- package/src/services/runtime-process-wiring.ts +29 -36
- package/src/services/runtime-project-pane-github-review-cache.ts +164 -0
- package/src/services/runtime-render-flush.ts +63 -70
- package/src/services/runtime-render-lifecycle.ts +65 -64
- package/src/services/runtime-render-orchestrator.ts +55 -45
- package/src/services/runtime-render-pipeline.ts +106 -103
- package/src/services/runtime-render-state.ts +62 -49
- package/src/services/runtime-repository-actions.ts +97 -70
- package/src/services/runtime-right-pane-render.ts +80 -53
- package/src/services/runtime-shutdown.ts +38 -35
- package/src/services/runtime-stream-subscriptions.ts +35 -27
- package/src/services/runtime-task-composer-persistence.ts +71 -59
- package/src/services/runtime-task-composer-snapshot.ts +14 -0
- package/src/services/runtime-task-editor-actions.ts +46 -29
- package/src/services/runtime-task-pane-actions.ts +220 -134
- package/src/services/runtime-task-pane-shortcuts.ts +323 -123
- package/src/services/runtime-workspace-observed-effect-queue.ts +25 -0
- package/src/services/runtime-workspace-observed-events.ts +33 -184
- package/src/services/runtime-workspace-observed-transition-policy.ts +228 -0
- package/src/services/session-diagnostics-store.ts +217 -0
- package/src/services/startup-background-resume.ts +26 -21
- package/src/services/startup-orchestrator.ts +16 -13
- package/src/services/startup-paint-tracker.ts +29 -21
- package/src/services/startup-persisted-conversation-queue.ts +19 -13
- package/src/services/startup-settled-gate.ts +25 -15
- package/src/services/startup-shutdown.ts +18 -22
- package/src/services/startup-state-hydration.ts +44 -34
- package/src/services/startup-visibility.ts +12 -4
- package/src/services/task-pane-selection-actions.ts +89 -72
- package/src/services/task-planning-hydration.ts +24 -18
- package/src/services/task-planning-observed-events.ts +50 -52
- package/src/services/workspace-observed-events.ts +66 -63
- package/src/storage/storage-lifecycle-core.ts +438 -0
- package/src/store/control-plane-store-normalize.ts +33 -242
- package/src/store/control-plane-store-types.ts +1 -35
- package/src/store/control-plane-store.ts +396 -56
- package/src/store/event-store.ts +397 -3
- package/src/terminal/snapshot-oracle.ts +207 -94
- package/src/ui/mux-theme.ts +112 -8
- package/src/ui/panes/home-gridfire.ts +40 -31
- package/src/ui/panes/home.ts +10 -2
- package/src/ui/panes/nim.ts +315 -0
- package/src/mux/live-mux/actions-task.ts +0 -115
- package/src/mux/live-mux/left-rail-actions.ts +0 -118
- package/src/mux/live-mux/left-rail-conversation-click.ts +0 -82
- package/src/mux/live-mux/left-rail-pointer.ts +0 -74
- package/src/mux/live-mux/task-pane-shortcuts.ts +0 -206
- package/src/services/runtime-directory-actions.ts +0 -164
- package/src/services/runtime-input-pipeline.ts +0 -50
- package/src/services/runtime-input-router.ts +0 -189
- package/src/services/runtime-main-pane-input.ts +0 -230
- package/src/services/runtime-modal-input.ts +0 -119
- package/src/services/runtime-navigation-input.ts +0 -197
- package/src/services/runtime-rail-input.ts +0 -278
- package/src/services/runtime-task-pane.ts +0 -62
- package/src/services/runtime-workspace-actions.ts +0 -158
- package/src/ui/conversation-input-forwarder.ts +0 -114
- package/src/ui/conversation-selection-input.ts +0 -103
- package/src/ui/global-shortcut-input.ts +0 -89
- package/src/ui/input.ts +0 -238
- package/src/ui/kit.ts +0 -509
- package/src/ui/left-nav-input.ts +0 -80
- package/src/ui/left-rail-pointer-input.ts +0 -148
- package/src/ui/repository-fold-input.ts +0 -91
- package/src/ui/surface.ts +0 -224
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import type { Screen, ScreenWriter } from '../../packages/harness-ui/src/screen.ts';
|
|
2
|
+
import { renderDiffUiViewport, resolveDiffUiTheme } from './render.ts';
|
|
3
|
+
import { reduceDiffUiState } from './state.ts';
|
|
4
|
+
import type {
|
|
5
|
+
DiffUiCliOptions,
|
|
6
|
+
DiffUiCommand,
|
|
7
|
+
DiffUiEvent,
|
|
8
|
+
DiffUiModel,
|
|
9
|
+
DiffUiState,
|
|
10
|
+
} from './types.ts';
|
|
11
|
+
import { diffUiCommandToStateAction } from './commands.ts';
|
|
12
|
+
|
|
13
|
+
const TOP_BOTTOM_SCROLL_DELTA = 1_000_000;
|
|
14
|
+
|
|
15
|
+
type DiffUiPagerEvent =
|
|
16
|
+
| {
|
|
17
|
+
readonly type: 'input';
|
|
18
|
+
readonly input: Buffer;
|
|
19
|
+
}
|
|
20
|
+
| {
|
|
21
|
+
readonly type: 'resize';
|
|
22
|
+
readonly width: number;
|
|
23
|
+
readonly height: number;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
interface DiffUiPagerEventSource {
|
|
27
|
+
readEvent: () => Promise<DiffUiPagerEvent | null>;
|
|
28
|
+
close: () => void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface DiffUiPagerInputStream {
|
|
32
|
+
readonly isTTY: boolean | undefined;
|
|
33
|
+
setRawMode?: (mode: boolean) => void;
|
|
34
|
+
resume: () => void;
|
|
35
|
+
pause: () => void;
|
|
36
|
+
on: (event: 'data' | 'end', listener: (chunk?: unknown) => void) => void;
|
|
37
|
+
off: (event: 'data' | 'end', listener: (chunk?: unknown) => void) => void;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface DiffUiPagerOutputStream {
|
|
41
|
+
readonly isTTY: boolean | undefined;
|
|
42
|
+
readonly columns: number | undefined;
|
|
43
|
+
readonly rows: number | undefined;
|
|
44
|
+
on: (event: 'resize', listener: () => void) => void;
|
|
45
|
+
off: (event: 'resize', listener: () => void) => void;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface RunDiffUiPagerSessionInput {
|
|
49
|
+
readonly model: DiffUiModel;
|
|
50
|
+
readonly options: DiffUiCliOptions;
|
|
51
|
+
readonly initialState: DiffUiState;
|
|
52
|
+
readonly initialWidth: number;
|
|
53
|
+
readonly initialHeight: number;
|
|
54
|
+
readonly eventSource: DiffUiPagerEventSource;
|
|
55
|
+
readonly writeStdout: (text: string) => void;
|
|
56
|
+
readonly writeStderr: (text: string) => void;
|
|
57
|
+
readonly createScreen: (writer: ScreenWriter) => Pick<Screen, 'markDirty' | 'flush'>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface DiffUiPagerSessionResult {
|
|
61
|
+
readonly events: readonly DiffUiEvent[];
|
|
62
|
+
readonly renderedLines: readonly string[];
|
|
63
|
+
readonly state: DiffUiState;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function clampWidth(value: number): number {
|
|
67
|
+
return Math.max(40, Math.floor(value));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function clampHeight(value: number): number {
|
|
71
|
+
return Math.max(6, Math.floor(value));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function pushEvent(events: DiffUiEvent[], event: DiffUiEvent): void {
|
|
75
|
+
events.push(event);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function pushRenderEvents(input: {
|
|
79
|
+
readonly events: DiffUiEvent[];
|
|
80
|
+
readonly state: DiffUiState;
|
|
81
|
+
readonly renderedLines: readonly string[];
|
|
82
|
+
readonly width: number;
|
|
83
|
+
readonly height: number;
|
|
84
|
+
}): void {
|
|
85
|
+
pushEvent(input.events, {
|
|
86
|
+
type: 'state.changed',
|
|
87
|
+
state: input.state,
|
|
88
|
+
});
|
|
89
|
+
pushEvent(input.events, {
|
|
90
|
+
type: 'render.completed',
|
|
91
|
+
rows: input.renderedLines.length,
|
|
92
|
+
width: input.width,
|
|
93
|
+
height: input.height,
|
|
94
|
+
view: input.state.effectiveViewMode,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function normalizeInputBuffer(input: Buffer): string {
|
|
99
|
+
return input.toString('utf8');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function decodeDiffUiPagerInput(input: Buffer): readonly DiffUiCommand[] {
|
|
103
|
+
const text = normalizeInputBuffer(input);
|
|
104
|
+
if (text === '\u0003' || text === 'q' || text === 'Q') {
|
|
105
|
+
return [{ type: 'session.quit' }];
|
|
106
|
+
}
|
|
107
|
+
if (text === '\u001b') {
|
|
108
|
+
return [{ type: 'finder.close' }];
|
|
109
|
+
}
|
|
110
|
+
if (text === '\u001b[A' || text === 'k') {
|
|
111
|
+
return [{ type: 'nav.scroll', delta: -1 }];
|
|
112
|
+
}
|
|
113
|
+
if (text === '\u001b[B' || text === 'j') {
|
|
114
|
+
return [{ type: 'nav.scroll', delta: 1 }];
|
|
115
|
+
}
|
|
116
|
+
if (text === '\u001b[5~' || text === 'b') {
|
|
117
|
+
return [{ type: 'nav.page', delta: -1 }];
|
|
118
|
+
}
|
|
119
|
+
if (text === '\u001b[6~' || text === ' ') {
|
|
120
|
+
return [{ type: 'nav.page', delta: 1 }];
|
|
121
|
+
}
|
|
122
|
+
if (text === '\u001b[H' || text === '\u001b[1~' || text === 'g') {
|
|
123
|
+
return [{ type: 'nav.scroll', delta: -TOP_BOTTOM_SCROLL_DELTA }];
|
|
124
|
+
}
|
|
125
|
+
if (text === '\u001b[F' || text === '\u001b[4~' || text === 'G') {
|
|
126
|
+
return [{ type: 'nav.scroll', delta: TOP_BOTTOM_SCROLL_DELTA }];
|
|
127
|
+
}
|
|
128
|
+
if (text === 'u') {
|
|
129
|
+
return [{ type: 'view.setMode', mode: 'unified' }];
|
|
130
|
+
}
|
|
131
|
+
if (text === 's') {
|
|
132
|
+
return [{ type: 'view.setMode', mode: 'split' }];
|
|
133
|
+
}
|
|
134
|
+
if (text === 'a') {
|
|
135
|
+
return [{ type: 'view.setMode', mode: 'auto' }];
|
|
136
|
+
}
|
|
137
|
+
if (text === '/') {
|
|
138
|
+
return [{ type: 'finder.open' }];
|
|
139
|
+
}
|
|
140
|
+
if (text === '\r' || text === '\n') {
|
|
141
|
+
return [{ type: 'finder.accept' }];
|
|
142
|
+
}
|
|
143
|
+
return [];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export async function runDiffUiPagerSession(
|
|
147
|
+
input: RunDiffUiPagerSessionInput,
|
|
148
|
+
): Promise<DiffUiPagerSessionResult> {
|
|
149
|
+
const theme = resolveDiffUiTheme(input.options.theme);
|
|
150
|
+
const screen = input.createScreen({
|
|
151
|
+
writeOutput(output: string): void {
|
|
152
|
+
input.writeStdout(output);
|
|
153
|
+
},
|
|
154
|
+
writeError(output: string): void {
|
|
155
|
+
input.writeStderr(output);
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
const events: DiffUiEvent[] = [];
|
|
159
|
+
let width = clampWidth(input.initialWidth);
|
|
160
|
+
let height = clampHeight(input.initialHeight);
|
|
161
|
+
let state = input.initialState;
|
|
162
|
+
let renderedLines = renderDiffUiViewport({
|
|
163
|
+
model: input.model,
|
|
164
|
+
state,
|
|
165
|
+
width,
|
|
166
|
+
height,
|
|
167
|
+
viewMode: input.options.viewMode,
|
|
168
|
+
syntaxMode: input.options.syntaxMode,
|
|
169
|
+
wordDiffMode: input.options.wordDiffMode,
|
|
170
|
+
color: input.options.color,
|
|
171
|
+
theme,
|
|
172
|
+
}).lines;
|
|
173
|
+
|
|
174
|
+
screen.markDirty();
|
|
175
|
+
screen.flush({
|
|
176
|
+
layout: {
|
|
177
|
+
paneRows: renderedLines.length,
|
|
178
|
+
rightCols: width,
|
|
179
|
+
rightStartCol: 1,
|
|
180
|
+
},
|
|
181
|
+
rows: renderedLines,
|
|
182
|
+
rightFrame: null,
|
|
183
|
+
selectionRows: [],
|
|
184
|
+
selectionOverlay: '',
|
|
185
|
+
validateAnsi: false,
|
|
186
|
+
});
|
|
187
|
+
pushRenderEvents({
|
|
188
|
+
events,
|
|
189
|
+
state,
|
|
190
|
+
renderedLines,
|
|
191
|
+
width,
|
|
192
|
+
height,
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
while (true) {
|
|
196
|
+
const pagerEvent = await input.eventSource.readEvent();
|
|
197
|
+
if (pagerEvent === null) {
|
|
198
|
+
pushEvent(events, { type: 'session.quit' });
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
if (pagerEvent.type === 'resize') {
|
|
202
|
+
width = clampWidth(pagerEvent.width);
|
|
203
|
+
height = clampHeight(pagerEvent.height);
|
|
204
|
+
state = reduceDiffUiState({
|
|
205
|
+
model: input.model,
|
|
206
|
+
state,
|
|
207
|
+
action: {
|
|
208
|
+
type: 'viewport.changed',
|
|
209
|
+
width,
|
|
210
|
+
},
|
|
211
|
+
viewportWidth: width,
|
|
212
|
+
viewportHeight: height,
|
|
213
|
+
});
|
|
214
|
+
} else {
|
|
215
|
+
const commands = decodeDiffUiPagerInput(pagerEvent.input);
|
|
216
|
+
let shouldQuit = false;
|
|
217
|
+
for (const command of commands) {
|
|
218
|
+
if (command.type === 'session.quit') {
|
|
219
|
+
shouldQuit = true;
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
state = reduceDiffUiState({
|
|
223
|
+
model: input.model,
|
|
224
|
+
state,
|
|
225
|
+
action: diffUiCommandToStateAction(command, Math.max(1, height - 2)),
|
|
226
|
+
viewportWidth: width,
|
|
227
|
+
viewportHeight: height,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
if (shouldQuit) {
|
|
231
|
+
pushEvent(events, { type: 'session.quit' });
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
if (commands.length === 0) {
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
renderedLines = renderDiffUiViewport({
|
|
240
|
+
model: input.model,
|
|
241
|
+
state,
|
|
242
|
+
width,
|
|
243
|
+
height,
|
|
244
|
+
viewMode: input.options.viewMode,
|
|
245
|
+
syntaxMode: input.options.syntaxMode,
|
|
246
|
+
wordDiffMode: input.options.wordDiffMode,
|
|
247
|
+
color: input.options.color,
|
|
248
|
+
theme,
|
|
249
|
+
}).lines;
|
|
250
|
+
screen.markDirty();
|
|
251
|
+
screen.flush({
|
|
252
|
+
layout: {
|
|
253
|
+
paneRows: renderedLines.length,
|
|
254
|
+
rightCols: width,
|
|
255
|
+
rightStartCol: 1,
|
|
256
|
+
},
|
|
257
|
+
rows: renderedLines,
|
|
258
|
+
rightFrame: null,
|
|
259
|
+
selectionRows: [],
|
|
260
|
+
selectionOverlay: '',
|
|
261
|
+
validateAnsi: false,
|
|
262
|
+
});
|
|
263
|
+
pushRenderEvents({
|
|
264
|
+
events,
|
|
265
|
+
state,
|
|
266
|
+
renderedLines,
|
|
267
|
+
width,
|
|
268
|
+
height,
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return {
|
|
273
|
+
events,
|
|
274
|
+
renderedLines,
|
|
275
|
+
state,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function pushQueuedEvent(
|
|
280
|
+
queue: (DiffUiPagerEvent | null)[],
|
|
281
|
+
waiter: { current: ((event: DiffUiPagerEvent | null) => void) | null },
|
|
282
|
+
event: DiffUiPagerEvent | null,
|
|
283
|
+
): void {
|
|
284
|
+
if (waiter.current !== null) {
|
|
285
|
+
const resolve = waiter.current;
|
|
286
|
+
waiter.current = null;
|
|
287
|
+
resolve(event);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
queue.push(event);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export function createDiffUiPagerEventSource(input: {
|
|
294
|
+
readonly stdin: DiffUiPagerInputStream;
|
|
295
|
+
readonly stdout: DiffUiPagerOutputStream;
|
|
296
|
+
}): DiffUiPagerEventSource {
|
|
297
|
+
const queue: (DiffUiPagerEvent | null)[] = [];
|
|
298
|
+
let closed = false;
|
|
299
|
+
const waiter: { current: ((event: DiffUiPagerEvent | null) => void) | null } = {
|
|
300
|
+
current: null,
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
const onData = (chunk?: unknown): void => {
|
|
304
|
+
const next = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk ?? ''), 'utf8');
|
|
305
|
+
if (next.length === 0) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
pushQueuedEvent(queue, waiter, {
|
|
309
|
+
type: 'input',
|
|
310
|
+
input: next,
|
|
311
|
+
});
|
|
312
|
+
};
|
|
313
|
+
const onEnd = (): void => {
|
|
314
|
+
pushQueuedEvent(queue, waiter, null);
|
|
315
|
+
};
|
|
316
|
+
const onResize = (): void => {
|
|
317
|
+
pushQueuedEvent(queue, waiter, {
|
|
318
|
+
type: 'resize',
|
|
319
|
+
width: input.stdout.columns ?? 120,
|
|
320
|
+
height: input.stdout.rows ?? 40,
|
|
321
|
+
});
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
input.stdin.on('data', onData);
|
|
325
|
+
input.stdin.on('end', onEnd);
|
|
326
|
+
input.stdout.on('resize', onResize);
|
|
327
|
+
|
|
328
|
+
return {
|
|
329
|
+
readEvent: async () => {
|
|
330
|
+
if (closed) {
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
if (queue.length > 0) {
|
|
334
|
+
return queue.shift() ?? null;
|
|
335
|
+
}
|
|
336
|
+
return await new Promise<DiffUiPagerEvent | null>((resolve) => {
|
|
337
|
+
waiter.current = resolve;
|
|
338
|
+
});
|
|
339
|
+
},
|
|
340
|
+
close: () => {
|
|
341
|
+
if (closed) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
closed = true;
|
|
345
|
+
input.stdin.off('data', onData);
|
|
346
|
+
input.stdin.off('end', onEnd);
|
|
347
|
+
input.stdout.off('resize', onResize);
|
|
348
|
+
if (waiter.current !== null) {
|
|
349
|
+
const resolve = waiter.current;
|
|
350
|
+
waiter.current = null;
|
|
351
|
+
resolve(null);
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export function enterDiffUiPagerTerminal(input: {
|
|
358
|
+
readonly stdin: DiffUiPagerInputStream;
|
|
359
|
+
readonly stdout: DiffUiPagerOutputStream;
|
|
360
|
+
readonly writeStdout: (text: string) => void;
|
|
361
|
+
}): () => void {
|
|
362
|
+
if (input.stdin.isTTY !== true || input.stdout.isTTY !== true) {
|
|
363
|
+
throw new Error('--pager requires interactive TTY stdin/stdout');
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
input.stdin.setRawMode?.(true);
|
|
367
|
+
input.stdin.resume();
|
|
368
|
+
input.writeStdout('\u001b[?1049h');
|
|
369
|
+
|
|
370
|
+
return () => {
|
|
371
|
+
input.writeStdout('\u001b[?1049l\u001b[?25h\u001b[?2004l');
|
|
372
|
+
input.stdin.pause();
|
|
373
|
+
input.stdin.setRawMode?.(false);
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export async function runDiffUiPagerProcess(input: {
|
|
378
|
+
readonly model: DiffUiModel;
|
|
379
|
+
readonly options: DiffUiCliOptions;
|
|
380
|
+
readonly initialState: DiffUiState;
|
|
381
|
+
readonly writeStdout: (text: string) => void;
|
|
382
|
+
readonly writeStderr: (text: string) => void;
|
|
383
|
+
readonly stdin: DiffUiPagerInputStream;
|
|
384
|
+
readonly stdout: DiffUiPagerOutputStream;
|
|
385
|
+
readonly createScreen: RunDiffUiPagerSessionInput['createScreen'];
|
|
386
|
+
}): Promise<DiffUiPagerSessionResult> {
|
|
387
|
+
const cleanupTerminal = enterDiffUiPagerTerminal({
|
|
388
|
+
stdin: input.stdin,
|
|
389
|
+
stdout: input.stdout,
|
|
390
|
+
writeStdout: input.writeStdout,
|
|
391
|
+
});
|
|
392
|
+
const eventSource = createDiffUiPagerEventSource({
|
|
393
|
+
stdin: input.stdin,
|
|
394
|
+
stdout: input.stdout,
|
|
395
|
+
});
|
|
396
|
+
try {
|
|
397
|
+
return await runDiffUiPagerSession({
|
|
398
|
+
model: input.model,
|
|
399
|
+
options: input.options,
|
|
400
|
+
initialState: input.initialState,
|
|
401
|
+
initialWidth: input.stdout.columns ?? 120,
|
|
402
|
+
initialHeight: input.stdout.rows ?? 40,
|
|
403
|
+
eventSource,
|
|
404
|
+
writeStdout: input.writeStdout,
|
|
405
|
+
writeStderr: input.writeStderr,
|
|
406
|
+
createScreen: input.createScreen,
|
|
407
|
+
});
|
|
408
|
+
} finally {
|
|
409
|
+
eventSource.close();
|
|
410
|
+
cleanupTerminal();
|
|
411
|
+
}
|
|
412
|
+
}
|