@jackice/pi-ui 0.9.2 → 0.10.0

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +5 -3
  3. package/dist/components/code-block.d.ts +27 -0
  4. package/dist/components/code-block.d.ts.map +1 -1
  5. package/dist/components/code-block.js +117 -1
  6. package/dist/components/code-block.js.map +1 -1
  7. package/dist/components/output-block.d.ts +15 -0
  8. package/dist/components/output-block.d.ts.map +1 -1
  9. package/dist/components/output-block.js +27 -0
  10. package/dist/components/output-block.js.map +1 -1
  11. package/dist/core/ask-text.d.ts +2 -0
  12. package/dist/core/ask-text.d.ts.map +1 -0
  13. package/dist/core/ask-text.js +8 -0
  14. package/dist/core/ask-text.js.map +1 -0
  15. package/dist/core/limits.d.ts +29 -0
  16. package/dist/core/limits.d.ts.map +1 -1
  17. package/dist/core/limits.js +104 -0
  18. package/dist/core/limits.js.map +1 -1
  19. package/dist/core/viewport.d.ts +29 -0
  20. package/dist/core/viewport.d.ts.map +1 -0
  21. package/dist/core/viewport.js +35 -0
  22. package/dist/core/viewport.js.map +1 -0
  23. package/dist/index.d.ts +6 -2
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +3 -0
  26. package/dist/index.js.map +1 -1
  27. package/dist/views/ask-result.d.ts +33 -0
  28. package/dist/views/ask-result.d.ts.map +1 -0
  29. package/dist/views/ask-result.js +220 -0
  30. package/dist/views/ask-result.js.map +1 -0
  31. package/dist/views/ask.d.ts +68 -0
  32. package/dist/views/ask.d.ts.map +1 -0
  33. package/dist/views/ask.js +376 -0
  34. package/dist/views/ask.js.map +1 -0
  35. package/dist/views/bash.d.ts +17 -0
  36. package/dist/views/bash.d.ts.map +1 -1
  37. package/dist/views/bash.js +56 -7
  38. package/dist/views/bash.js.map +1 -1
  39. package/dist/views/debug.d.ts +121 -0
  40. package/dist/views/debug.d.ts.map +1 -0
  41. package/dist/views/debug.js +196 -0
  42. package/dist/views/debug.js.map +1 -0
  43. package/dist/views/write.d.ts +20 -0
  44. package/dist/views/write.d.ts.map +1 -1
  45. package/dist/views/write.js +130 -31
  46. package/dist/views/write.js.map +1 -1
  47. package/package.json +21 -4
@@ -0,0 +1,121 @@
1
+ import { type ThemeLike } from "../core/theme.js";
2
+ export declare const DEBUG_VIEW_API_VERSION = 1;
3
+ export type DebugToolStatus = "pending" | "streaming" | "running" | "success" | "error" | "unknown";
4
+ export interface DebugTruncation {
5
+ truncated: boolean;
6
+ shown?: number;
7
+ total?: number;
8
+ unknownTotal?: boolean;
9
+ }
10
+ export interface DebugLocationView {
11
+ path: string;
12
+ line: number;
13
+ column?: number;
14
+ }
15
+ export interface DebugSessionView {
16
+ kind: "session";
17
+ programLabel?: string;
18
+ stopReason?: string;
19
+ location?: DebugLocationView;
20
+ adapterLabel?: string;
21
+ sessionState?: string;
22
+ }
23
+ export interface DebugBreakpointView {
24
+ path: string;
25
+ requestedLine: number;
26
+ actualLine?: number;
27
+ verified: boolean;
28
+ message?: string;
29
+ }
30
+ export interface DebugThreadView {
31
+ id: number;
32
+ name: string;
33
+ state: "stopped" | "running" | "unknown";
34
+ }
35
+ export interface DebugStackFrameView {
36
+ name: string;
37
+ location?: DebugLocationView;
38
+ current?: boolean;
39
+ }
40
+ export interface DebugScopeView {
41
+ name: string;
42
+ expensive: boolean;
43
+ }
44
+ export interface DebugVariableView {
45
+ name: string;
46
+ type?: string;
47
+ valuePreview: string;
48
+ hasChildren: boolean;
49
+ }
50
+ export interface DebugOutputView {
51
+ lines: readonly string[];
52
+ lost: boolean;
53
+ truncated: boolean;
54
+ }
55
+ export interface DebugMessageView {
56
+ message: string;
57
+ tone?: "muted" | "warning" | "error";
58
+ }
59
+ interface DebugViewBase {
60
+ title: string;
61
+ action: string;
62
+ toolStatus: DebugToolStatus;
63
+ adapterLabel?: string;
64
+ sessionLabel?: string;
65
+ sessionState?: string;
66
+ elapsedMs?: number;
67
+ notice?: string;
68
+ truncation?: DebugTruncation;
69
+ }
70
+ export type DebugViewModel = (DebugViewBase & {
71
+ kind: "session";
72
+ session: DebugSessionView;
73
+ }) | (DebugViewBase & {
74
+ kind: "breakpoints";
75
+ breakpoints: readonly DebugBreakpointView[];
76
+ }) | (DebugViewBase & {
77
+ kind: "threads";
78
+ threads: readonly DebugThreadView[];
79
+ }) | (DebugViewBase & {
80
+ kind: "stack";
81
+ frames: readonly DebugStackFrameView[];
82
+ }) | (DebugViewBase & {
83
+ kind: "scopes";
84
+ scopes: readonly DebugScopeView[];
85
+ }) | (DebugViewBase & {
86
+ kind: "variables";
87
+ variables: readonly DebugVariableView[];
88
+ }) | (DebugViewBase & {
89
+ kind: "output";
90
+ output: DebugOutputView;
91
+ }) | (DebugViewBase & {
92
+ kind: "message";
93
+ messageView: DebugMessageView;
94
+ });
95
+ export interface DebugViewProps {
96
+ model: DebugViewModel;
97
+ expanded?: boolean;
98
+ maxCollapsedRows?: number;
99
+ maxExpandedRows?: number;
100
+ }
101
+ export declare class DebugView {
102
+ private props;
103
+ private theme;
104
+ private revision;
105
+ private cache;
106
+ constructor(theme: ThemeLike, props: DebugViewProps);
107
+ setProps(props: DebugViewProps): void;
108
+ setTheme(theme: ThemeLike): void;
109
+ invalidate(): void;
110
+ render(width: number): string[];
111
+ private build;
112
+ private rows;
113
+ private sessionRows;
114
+ private breakpointRow;
115
+ private threadRow;
116
+ private frameRow;
117
+ private variableRow;
118
+ private outputRows;
119
+ }
120
+ export {};
121
+ //# sourceMappingURL=debug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/views/debug.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,SAAS,EAA2B,MAAM,kBAAkB,CAAC;AAIxF,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAExC,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,SAA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AAC;IAAC,SAAS,EAAE,SAAS,iBAAiB,EAAE,CAAA;CAAE,CAAC,GAChF,CAAC,aAAa,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,eAAe,CAAA;CAAE,CAAC,GAC7D,CAAC,aAAa,GAAG;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,WAAW,EAAE,gBAAgB,CAAA;CAAE,CAAC,CAAC;AAEzE,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,cAAc,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAmBD,qBAAa,SAAS;IACpB,OAAO,CAAC,KAAK,CAAiB;IAC9B,OAAO,CAAC,KAAK,CAAU;IACvB,OAAO,CAAC,QAAQ,CAAK;IACrB,OAAO,CAAC,KAAK,CAA4E;gBAE7E,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,cAAc;IAKnD,QAAQ,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI;IAKrC,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI;IAKhC,UAAU,IAAI,IAAI;IAKlB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE;IAW/B,OAAO,CAAC,KAAK;IAmDb,OAAO,CAAC,IAAI;IAmBZ,OAAO,CAAC,WAAW;IAkBnB,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,SAAS;IAKjB,OAAO,CAAC,QAAQ;IAMhB,OAAO,CAAC,WAAW;IAOnB,OAAO,CAAC,UAAU;CAMnB"}
@@ -0,0 +1,196 @@
1
+ import { normalizeWidth, sanitizeLine } from "../core/ansi.js";
2
+ import { fromPiTheme } from "../core/theme.js";
3
+ import { Panel } from "../components/panel.js";
4
+ export const DEBUG_VIEW_API_VERSION = 1;
5
+ const DEFAULTS = { maxCollapsedRows: 12, maxExpandedRows: 200 };
6
+ const STATUS = {
7
+ pending: { glyph: "○", tone: "muted" },
8
+ streaming: { glyph: "●", tone: "accent" },
9
+ running: { glyph: "●", tone: "accent" },
10
+ success: { glyph: "✓", tone: "success" },
11
+ error: { glyph: "✗", tone: "error" },
12
+ unknown: { glyph: "?", tone: "muted" },
13
+ };
14
+ const THREAD_STATE = {
15
+ stopped: { glyph: "■", tone: "muted", label: "stopped" },
16
+ running: { glyph: "●", tone: "accent", label: "running" },
17
+ unknown: { glyph: "?", tone: "muted", label: "unknown" },
18
+ };
19
+ export class DebugView {
20
+ props;
21
+ theme;
22
+ revision = 0;
23
+ cache;
24
+ constructor(theme, props) {
25
+ this.theme = fromPiTheme(theme);
26
+ this.props = props;
27
+ }
28
+ setProps(props) {
29
+ this.props = props;
30
+ this.invalidate();
31
+ }
32
+ setTheme(theme) {
33
+ this.theme = fromPiTheme(theme);
34
+ this.invalidate();
35
+ }
36
+ invalidate() {
37
+ this.revision++;
38
+ this.cache = undefined;
39
+ }
40
+ render(width) {
41
+ const limit = normalizeWidth(width);
42
+ if (limit === 0)
43
+ return [];
44
+ if (this.cache && this.cache.width === limit && this.cache.revision === this.revision) {
45
+ return [...this.cache.lines];
46
+ }
47
+ const lines = this.build(limit);
48
+ this.cache = { width: limit, revision: this.revision, lines };
49
+ return [...lines];
50
+ }
51
+ build(width) {
52
+ const model = this.props.model;
53
+ const status = STATUS[model.toolStatus];
54
+ const expanded = this.props.expanded === true;
55
+ const configured = expanded ? this.props.maxExpandedRows : this.props.maxCollapsedRows;
56
+ const maxRows = limitRows(configured, expanded ? DEFAULTS.maxExpandedRows : DEFAULTS.maxCollapsedRows);
57
+ const rows = this.rows(model);
58
+ if (model.notice !== undefined && model.notice.length > 0) {
59
+ rows.unshift(this.theme.fg("warning", sanitizeRow(model.notice)));
60
+ }
61
+ const shown = rows.slice(0, maxRows);
62
+ if (rows.length > maxRows) {
63
+ const omitted = rows.length - maxRows;
64
+ shown.push(this.theme.fg("muted", `… ${omitted} more`));
65
+ }
66
+ if (model.truncation?.truncated === true) {
67
+ const shownCount = model.truncation.shown ?? rows.length;
68
+ const total = model.truncation.unknownTotal === true ? "unknown total" : `${model.truncation.total ?? "?"} total`;
69
+ shown.push(this.theme.fg("muted", `… truncated (${shownCount} shown, ${total})`));
70
+ }
71
+ const meta = [];
72
+ if (model.action.length > 0)
73
+ meta.push(sanitizeRow(model.action));
74
+ const inSessionBody = model.kind === "session";
75
+ const adapter = model.adapterLabel ?? (inSessionBody ? model.session.adapterLabel : undefined);
76
+ if (adapter !== undefined && !inSessionBody)
77
+ meta.push(sanitizeRow(adapter));
78
+ if (model.sessionLabel !== undefined)
79
+ meta.push(sanitizeRow(model.sessionLabel));
80
+ const state = model.sessionState ?? (inSessionBody ? model.session.sessionState : undefined);
81
+ if (state !== undefined && !inSessionBody)
82
+ meta.push(sanitizeRow(state));
83
+ if (model.elapsedMs !== undefined)
84
+ meta.push(`${model.elapsedMs}ms`);
85
+ const children = [
86
+ {
87
+ render: (inner) => {
88
+ void inner;
89
+ return shown;
90
+ },
91
+ },
92
+ ];
93
+ return new Panel(this.theme, {
94
+ title: sanitizeRow(model.title),
95
+ titleRight: [this.theme.fg(status.tone, status.glyph), ...meta].join(" · "),
96
+ tone: status.tone,
97
+ border: "rounded",
98
+ paddingX: 1,
99
+ children,
100
+ }).render(width);
101
+ }
102
+ rows(model) {
103
+ if (model.kind === "session")
104
+ return this.sessionRows(model.session, model);
105
+ if (model.kind === "breakpoints")
106
+ return model.breakpoints.map((item) => this.breakpointRow(item));
107
+ if (model.kind === "threads")
108
+ return model.threads.map((item) => this.threadRow(item));
109
+ if (model.kind === "stack")
110
+ return model.frames.map((item) => this.frameRow(item));
111
+ if (model.kind === "scopes") {
112
+ return model.scopes.map((item) => {
113
+ const name = this.theme.fg("text", sanitizeRow(item.name));
114
+ return item.expensive
115
+ ? `${name} ${this.theme.fg("warning", "[expensive]")}`
116
+ : name;
117
+ });
118
+ }
119
+ if (model.kind === "variables")
120
+ return model.variables.map((item) => this.variableRow(item));
121
+ if (model.kind === "output")
122
+ return this.outputRows(model.output);
123
+ const tone = model.messageView.tone ?? "muted";
124
+ return [this.theme.fg(tone, sanitizeRow(model.messageView.message))];
125
+ }
126
+ sessionRows(session, model) {
127
+ const rows = [];
128
+ if (session.programLabel !== undefined) {
129
+ rows.push(`${this.theme.fg("muted", "program")} ${sanitizeRow(session.programLabel)}`);
130
+ }
131
+ const adapter = model.adapterLabel ?? session.adapterLabel;
132
+ if (adapter !== undefined)
133
+ rows.push(`${this.theme.fg("muted", "adapter")} ${sanitizeRow(adapter)}`);
134
+ const state = model.sessionState ?? session.sessionState;
135
+ if (state !== undefined)
136
+ rows.push(`${this.theme.fg("muted", "state")} ${sanitizeRow(state)}`);
137
+ if (session.stopReason !== undefined) {
138
+ rows.push(`${this.theme.fg("muted", "stop")} ${sanitizeRow(session.stopReason)}`);
139
+ }
140
+ if (session.location !== undefined) {
141
+ rows.push(`${this.theme.fg("muted", "at")} ${sanitizeRow(locationText(session.location))}`);
142
+ }
143
+ return rows;
144
+ }
145
+ breakpointRow(item) {
146
+ const text = sanitizeRow(breakpointText(item));
147
+ if (!item.verified) {
148
+ return `${this.theme.fg("warning", "○")} ${text} ${this.theme.fg("warning", "[unverified]")}`;
149
+ }
150
+ return `${this.theme.fg("success", "●")} ${text}`;
151
+ }
152
+ threadRow(item) {
153
+ const state = THREAD_STATE[item.state];
154
+ return `${this.theme.fg(state.tone, state.glyph)} ${sanitizeRow(item.name)} ${this.theme.fg("muted", `(${state.label})`)}`;
155
+ }
156
+ frameRow(item) {
157
+ const marker = item.current === true ? this.theme.fg("accent", "▸") : " ";
158
+ const location = item.location === undefined ? "" : ` ${this.theme.fg("muted", sanitizeRow(locationText(item.location)))}`;
159
+ return `${marker} ${sanitizeRow(item.name)}${location}`;
160
+ }
161
+ variableRow(item) {
162
+ const marker = item.hasChildren ? this.theme.fg("muted", "▸") : " ";
163
+ const type = item.type === undefined ? "" : this.theme.fg("muted", `: ${sanitizeRow(item.type)}`);
164
+ const value = sanitizeRow(item.valuePreview);
165
+ return `${marker} ${sanitizeRow(item.name)}${type} = ${value}`;
166
+ }
167
+ outputRows(output) {
168
+ const rows = output.lines.map((line) => this.theme.fg("text", sanitizeRow(line)));
169
+ if (output.lost)
170
+ rows.push(this.theme.fg("warning", "[output lost]"));
171
+ if (output.truncated)
172
+ rows.push(this.theme.fg("muted", "[output truncated]"));
173
+ return rows;
174
+ }
175
+ }
176
+ function breakpointText(item) {
177
+ const actual = item.actualLine;
178
+ const location = actual === undefined || actual === item.requestedLine
179
+ ? `${item.path}:${item.requestedLine}`
180
+ : `${item.path}:${item.requestedLine} → ${actual}`;
181
+ return item.message === undefined || item.message.length === 0 ? location : `${location} — ${item.message}`;
182
+ }
183
+ function locationText(location) {
184
+ return location.column === undefined
185
+ ? `${location.path}:${location.line}`
186
+ : `${location.path}:${location.line}:${location.column}`;
187
+ }
188
+ function sanitizeRow(text) {
189
+ return sanitizeLine(text).replace(/\n/g, " ");
190
+ }
191
+ function limitRows(value, fallback) {
192
+ if (value === undefined || !Number.isFinite(value) || value <= 0)
193
+ return fallback;
194
+ return Math.floor(value);
195
+ }
196
+ //# sourceMappingURL=debug.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.js","sourceRoot":"","sources":["../../src/views/debug.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAA2C,MAAM,kBAAkB,CAAC;AAExF,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAE/C,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAkGxC,MAAM,QAAQ,GAAG,EAAE,gBAAgB,EAAE,EAAE,EAAE,eAAe,EAAE,GAAG,EAAW,CAAC;AAEzE,MAAM,MAAM,GAAqE;IAC/E,OAAO,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO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I,IAAI,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;AAC7D,CAAC;AAED,SAAS,WAAW,CAAC,IAAY;IAC/B,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,SAAS,CAAC,KAAyB,EAAE,QAAgB;IAC5D,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;QAAE,OAAO,QAAQ,CAAC;IAClF,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC"}
@@ -1,3 +1,4 @@
1
+ import type { ViewportSource } from "../core/viewport.js";
1
2
  import { type Highlight } from "../components/code-block.js";
2
3
  import type { UiTheme } from "../core/theme.js";
3
4
  import type { ToolStatus } from "../components/tool-card.js";
@@ -10,6 +11,7 @@ export interface WriteViewModel {
10
11
  language?: string;
11
12
  notices?: readonly string[];
12
13
  }
14
+ export type WriteViewportSource = ViewportSource;
13
15
  export interface WriteViewConfig {
14
16
  /** 缺省 legacy;omp 将路径与 final 成功行数放入顶部边框。 */
15
17
  layout?: "legacy" | "omp";
@@ -20,6 +22,12 @@ export interface WriteViewConfig {
20
22
  showPath?: boolean;
21
23
  highlighter?: Highlight;
22
24
  themeRevision?: () => string;
25
+ /** 仅在 omp 生效;缺省 false 保持既有消费者行为。 */
26
+ stableStreamingViewport?: boolean;
27
+ /** 包含摘要行的视觉行容量;缺省 12。 */
28
+ streamingViewportRows?: number;
29
+ /** 提供时启用活跃视口状态读取。 */
30
+ viewport?: ViewportSource;
23
31
  }
24
32
  export interface WriteViewProps {
25
33
  model: WriteViewModel;
@@ -30,13 +38,25 @@ export declare class WriteView {
30
38
  private props;
31
39
  private theme;
32
40
  private cachedHighlight;
41
+ private lastBlock;
42
+ private activeStableViewport;
43
+ private draft;
44
+ private footerSummary;
33
45
  constructor(theme: UiTheme, props: WriteViewProps);
34
46
  setProps(props: WriteViewProps): void;
35
47
  setTheme(theme: UiTheme): void;
36
48
  invalidate(): void;
49
+ /** 最近一次成功渲染的稳定视口候选;由外部 wrapper 决定是否提交。 */
50
+ viewportDraft(): {
51
+ width: number;
52
+ height: number;
53
+ digits: number;
54
+ } | undefined;
37
55
  render(width: number): readonly string[];
38
56
  private renderLegacy;
39
57
  private renderOmp;
40
58
  private buildChildren;
59
+ private renderedBlock;
60
+ private stableViewport;
41
61
  }
42
62
  //# sourceMappingURL=write.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../src/views/write.ts"],"names":[],"mappings":"AAEA,OAAO,EAAa,KAAK,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAGxE,OAAO,KAAK,EAAQ,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAE7D,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,UAAU,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,OAAO,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,eAAe;IAC9B,2CAA2C;IAC3C,MAAM,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,aAAa,CAAC,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AAE,MAAM,GAAG,SAAS,MAAM,EAAE;IAcxC,OAAO,CAAC,YAAY;IAepB,OAAO,CAAC,SAAS;IA+BjB,OAAO,CAAC,aAAa;IA6FrB,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,cAAc;CAWvB"}
@@ -1,5 +1,5 @@
1
- import { middleTruncate, sanitizeLine, truncate } from "../core/ansi.js";
2
- import { UI_MAX_LINES, takeLines } from "../core/limits.js";
1
+ import { displayWidth, middleTruncate, sanitizeLine, truncate } from "../core/ansi.js";
2
+ import { clampCharsTail, takeLines, tailSource } from "../core/limits.js";
3
3
  import { CodeBlock } from "../components/code-block.js";
4
4
  import { Panel } from "../components/panel.js";
5
5
  const STATUS = {
@@ -10,27 +10,55 @@ const STATUS = {
10
10
  error: { glyph: "✗", tone: "error" },
11
11
  unknown: { glyph: "?", tone: "muted" },
12
12
  };
13
+ const DEFAULT_STREAMING_VIEWPORT_ROWS = 12;
14
+ const DEFAULT_MAX_PREVIEW_ROWS = 18;
15
+ const MIN_STREAMING_GUTTER_DIGITS = 4;
16
+ const HIGHLIGHT_CONTEXT_MAX_CHARS = 64 * 1024;
13
17
  export class WriteView {
14
18
  props;
15
19
  theme;
16
20
  cachedHighlight;
21
+ lastBlock;
22
+ activeStableViewport = false;
23
+ draft;
24
+ footerSummary;
17
25
  constructor(theme, props) {
18
26
  this.theme = theme;
19
27
  this.props = props;
20
28
  }
21
29
  setProps(props) {
30
+ const previous = this.props;
31
+ if (previous.model.content !== props.model.content
32
+ || previous.model.path !== props.model.path
33
+ || previous.model.language !== props.model.language
34
+ || previous.config?.highlighter !== props.config?.highlighter
35
+ || (previous.config?.themeRevision?.() ?? "") !== (props.config?.themeRevision?.() ?? "")) {
36
+ this.cachedHighlight = undefined;
37
+ }
22
38
  this.props = props;
23
- this.cachedHighlight = undefined;
24
39
  }
25
40
  setTheme(theme) {
26
41
  this.theme = theme;
27
42
  this.cachedHighlight = undefined;
28
43
  }
29
44
  invalidate() { }
45
+ /** 最近一次成功渲染的稳定视口候选;由外部 wrapper 决定是否提交。 */
46
+ viewportDraft() {
47
+ return this.draft;
48
+ }
30
49
  render(width) {
31
- if (this.props.config?.layout === "omp")
32
- return this.renderOmp(width);
33
- return this.renderLegacy(width);
50
+ this.draft = undefined;
51
+ this.lastBlock = undefined;
52
+ this.footerSummary = undefined;
53
+ this.activeStableViewport = false;
54
+ const rows = this.props.config?.layout === "omp" ? this.renderOmp(width) : this.renderLegacy(width);
55
+ const block = this.renderedBlock();
56
+ if (this.activeStableViewport && block !== undefined) {
57
+ const layout = block.viewportLayout();
58
+ if (layout !== undefined)
59
+ this.draft = { width, height: layout.height, digits: layout.digits };
60
+ }
61
+ return rows;
34
62
  }
35
63
  renderLegacy(width) {
36
64
  const { model } = this.props;
@@ -44,7 +72,7 @@ export class WriteView {
44
72
  tone: status.tone,
45
73
  border: "rounded",
46
74
  paddingX: 1,
47
- children: this.buildChildren(true),
75
+ children: this.buildChildren(true, width),
48
76
  }).render(width);
49
77
  }
50
78
  renderOmp(width) {
@@ -54,7 +82,7 @@ export class WriteView {
54
82
  return [];
55
83
  if (width <= 6 && model.status === "error")
56
84
  return narrowError(status.glyph, "Write", width);
57
- const children = this.buildChildren(false);
85
+ const children = this.buildChildren(false, width);
58
86
  const header = [{ text: "Write", priority: 10 }];
59
87
  if (config.showPath !== false && model.path !== undefined) {
60
88
  header.push({ text: model.path, tone: "muted", priority: 2, truncate: "middle" });
@@ -62,12 +90,17 @@ export class WriteView {
62
90
  if (model.status === "success" && model.lineCount !== undefined) {
63
91
  header.push({ text: `${model.lineCount} lines`, tone: "muted", priority: 8 });
64
92
  }
93
+ const footer = [];
94
+ if (model.status !== "success")
95
+ footer.push({ text: status.glyph, tone: status.tone });
96
+ if (this.footerSummary !== undefined)
97
+ footer.push({ text: this.footerSummary, tone: "muted", priority: 1 });
65
98
  return new Panel(this.theme, {
66
99
  title: "",
67
100
  frame: {
68
101
  header,
69
102
  sections: children.length === 0 ? [] : [{ children }],
70
- ...(model.status === "success" ? {} : { footer: [{ text: status.glyph, tone: status.tone }] }),
103
+ ...(footer.length === 0 ? {} : { footer }),
71
104
  borderTone: statusBorderTone(model.status),
72
105
  },
73
106
  border: "rounded",
@@ -75,17 +108,21 @@ export class WriteView {
75
108
  children: [],
76
109
  }).render(width);
77
110
  }
78
- buildChildren(includePath) {
111
+ buildChildren(includePath, width) {
79
112
  const { model, expanded, config = {} } = this.props;
80
113
  const children = [];
81
114
  const injected = config.highlighter;
82
- const revision = config.themeRevision?.() ?? '';
115
+ const revision = config.themeRevision?.() ?? "";
83
116
  const highlighter = injected === undefined ? undefined : (code, language) => {
84
117
  const cached = this.cachedHighlight;
85
- if (cached !== undefined && cached.revision === revision && cached.language === language && cached.source === code)
118
+ if (cached !== undefined
119
+ && cached.highlighter === injected
120
+ && cached.revision === revision
121
+ && cached.language === language
122
+ && cached.source === code)
86
123
  return cached.rows;
87
124
  const rows = injected(code, language);
88
- this.cachedHighlight = { revision, language, source: code, rows };
125
+ this.cachedHighlight = { revision, language, highlighter: injected, source: code, rows };
89
126
  return rows;
90
127
  };
91
128
  if (includePath && config.showPath !== false && model.path !== undefined) {
@@ -99,28 +136,60 @@ export class WriteView {
99
136
  render: (inner) => notices.map((notice) => truncateNotice(this.theme, notice, inner)),
100
137
  });
101
138
  }
102
- const showContent = (model.status !== "error" || expanded) && (model.content?.length ?? 0) > 0;
139
+ const content = model.content ?? "";
140
+ const stable = this.stableViewport(width);
141
+ const showContent = stable !== undefined || ((model.status !== "error" || expanded) && content.length > 0);
103
142
  if (showContent) {
104
- const streaming = !model.argsComplete && model.status !== "success";
105
- const previewLines = streaming ? config.streamingPreviewLines ?? 12 : config.previewLines ?? 6;
106
- const limited = takeLines(model.content ?? "", UI_MAX_LINES);
107
- const contentLines = limited.lines;
108
- if (contentLines.length > 1 && contentLines.at(-1) === "" && limited.truncated === false)
109
- contentLines.pop();
110
- children.push(new CodeBlock(this.theme, {
111
- lines: contentLines.map((text, index) => ({ text, number: index + 1 })),
143
+ const previewLines = stable !== undefined
144
+ ? stable.previewLines
145
+ : (!model.argsComplete && model.status !== "success" ? config.streamingPreviewLines ?? 12 : config.previewLines ?? 6);
146
+ const limited = stable === undefined ? takeLines(content, 20000) : undefined;
147
+ if (limited !== undefined && limited.lines.length > 1 && limited.lines.at(-1) === "" && limited.truncated === false) {
148
+ limited.lines.pop();
149
+ }
150
+ const tail = stable === undefined ? undefined : tailSource(content, previewLines);
151
+ const contentLines = stable === undefined
152
+ ? (limited?.lines ?? []).map((text, index) => ({ text, number: index + 1 }))
153
+ : tail?.lines ?? [];
154
+ const minDigits = Math.max(MIN_STREAMING_GUTTER_DIGITS, config.viewport?.previousDigits?.(width) ?? 0);
155
+ const preview = stable === undefined
156
+ ? {
157
+ direction: !model.argsComplete && model.status !== "success" ? "tail" : "head",
158
+ maxLogicalLines: previewLines,
159
+ maxVisualRows: config.maxPreviewRows ?? DEFAULT_MAX_PREVIEW_ROWS,
160
+ expanded,
161
+ ...(limited?.truncated ? { hideCount: true } : {}),
162
+ }
163
+ : {
164
+ direction: "tail",
165
+ maxLogicalLines: previewLines,
166
+ maxVisualRows: stable.capacity,
167
+ expanded,
168
+ minLineDigits: minDigits,
169
+ stableViewport: {
170
+ capacity: stable.capacity,
171
+ previousHeight: config.viewport?.previousHeight(width) ?? 0,
172
+ omittedBefore: tail?.omitted === true,
173
+ safety: tail?.safety === true,
174
+ },
175
+ };
176
+ const block = new CodeBlock(this.theme, {
177
+ lines: contentLines,
112
178
  ...(model.language === undefined ? {} : { language: model.language }),
113
179
  ...(highlighter === undefined ? {} : { highlight: highlighter }),
180
+ ...(stable !== undefined && tail !== undefined && !tail.safety && content.length <= HIGHLIGHT_CONTEXT_MAX_CHARS
181
+ ? { highlightSource: content }
182
+ : {}),
114
183
  showLineNumbers: config.lineNumbers !== false,
115
- preview: {
116
- direction: streaming ? "tail" : "head",
117
- maxLogicalLines: previewLines,
118
- maxVisualRows: config.maxPreviewRows ?? 18,
119
- expanded,
120
- ...(limited.truncated ? { hideCount: true } : {}),
121
- },
122
- }));
123
- if (limited.truncated) {
184
+ preview,
185
+ });
186
+ children.push(block);
187
+ if (stable !== undefined) {
188
+ this.activeStableViewport = true;
189
+ this.lastBlock = block;
190
+ this.footerSummary = stable.capacity === 1 ? footerSummaryFor(tail, width, config.lineNumbers !== false, minDigits) : undefined;
191
+ }
192
+ else if (limited?.truncated === true) {
124
193
  children.push({
125
194
  render: (inner) => [truncateNotice(this.theme, "UI safety limit — available result not fully shown", inner)],
126
195
  });
@@ -128,6 +197,36 @@ export class WriteView {
128
197
  }
129
198
  return children;
130
199
  }
200
+ renderedBlock() {
201
+ return this.lastBlock;
202
+ }
203
+ stableViewport(width) {
204
+ const { model, expanded, config = {} } = this.props;
205
+ if (config.layout !== "omp" || config.stableStreamingViewport !== true || config.viewport === undefined)
206
+ return undefined;
207
+ if (expanded || width <= 0)
208
+ return undefined;
209
+ if (model.status === "success" || model.status === "error")
210
+ return undefined;
211
+ const capacity = Math.max(1, Math.min(config.streamingViewportRows ?? DEFAULT_STREAMING_VIEWPORT_ROWS, config.maxPreviewRows ?? DEFAULT_MAX_PREVIEW_ROWS));
212
+ return { capacity, previewLines: config.streamingPreviewLines ?? 12 };
213
+ }
214
+ }
215
+ function footerSummaryFor(tail, width, lineNumbers, minDigits) {
216
+ if (tail === undefined)
217
+ return undefined;
218
+ if (tail.safety)
219
+ return "UI safety limit";
220
+ const inner = width - 4;
221
+ const digits = Math.max(minDigits, ...tail.lines.map((line) => (line.number === null ? 1 : String(line.number).length)));
222
+ const gutter = lineNumbers && inner - (digits + 1) >= 1 ? digits + 1 : 0;
223
+ const available = Math.max(1, inner - gutter);
224
+ const last = tail.lines.at(-1)?.text;
225
+ const lastText = last === undefined ? "" : clampCharsTail(last, available * 2).text;
226
+ const wrapped = lastText.length > 0 && displayWidth(lastText) > available;
227
+ if (tail.omitted || tail.lines.length > 1 || wrapped)
228
+ return "… earlier content hidden";
229
+ return undefined;
131
230
  }
132
231
  function narrowError(glyph, label, width) {
133
232
  if (width <= 1)