@xmoon76/dsh-pi-tui 0.5.6 → 0.5.8
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/LICENSE +33 -0
- package/README.en.md +103 -814
- package/README.md +102 -711
- package/cordis.patch.yml +186 -0
- package/dist/acp-preferences.d.mts +29 -0
- package/dist/acp-preferences.mjs +15 -0
- package/dist/{bootstrap-DQ4YPL-7.mjs → bootstrap-CMIjGyuk.mjs} +33515 -7587
- package/dist/builtins.mjs +3 -3
- package/dist/{client-bootstrap-Cr1JCaF5.mjs → client-bootstrap-BjGPc-DM.mjs} +4637 -492
- package/dist/client-extension-loader-probe-BUw7q8bJ.mjs +119 -0
- package/dist/command-trust-DChWUamk.mjs +406 -0
- package/dist/daemon-launcher-Dult7Jxv.mjs +1932 -0
- package/dist/daemon-launcher.d.mts +159 -0
- package/dist/daemon-launcher.mjs +2 -0
- package/dist/diagnostics-D5jwc-q1.d.mts +11 -0
- package/dist/{dist-CIsR7cz4.mjs → dist-BFgC-5tL.mjs} +938 -487
- package/dist/entry-control-DjNsE3I0.mjs +190 -0
- package/dist/extension/advanced.d.mts +1 -1
- package/dist/extension/unstable.d.mts +1 -1
- package/dist/extension-config-probe-BDdvutkG.mjs +95 -0
- package/dist/extension-config.d.mts +29 -0
- package/dist/extension-config.mjs +22 -0
- package/dist/{extensions-Bp0L37lP.mjs → extensions-B4uLpSTv.mjs} +1109 -100
- package/dist/{extensions-Bte3XOt5.d.mts → extensions-C8eAM0gX.d.mts} +1 -1
- package/dist/extensions.d.mts +2 -2
- package/dist/extensions.mjs +1 -1
- package/dist/{host-bootstrap-DilsvA6f.mjs → host-bootstrap-MVxks641.mjs} +129 -24
- package/dist/{host-foundation-probe--5jtvHVe.mjs → host-foundation-probe-DMNTmNrH.mjs} +2 -2
- package/dist/host-runtime.d.mts +11 -5
- package/dist/host-runtime.mjs +4171 -920
- package/dist/index.d.mts +86 -174
- package/dist/index.mjs +38087 -9967
- package/dist/local-acp-listener-B65J0Bx4.mjs +3115 -0
- package/dist/local-client.mjs +1158 -59
- package/dist/local-daemon-control-C14q9KnD.mjs +1588 -0
- package/dist/local-daemon-control-TCnERL7n.mjs +1424 -0
- package/dist/local-discovery-DOSsCh9q.mjs +2883 -0
- package/dist/local-discovery-egN4_gsQ.mjs +2 -0
- package/dist/local-discovery-uOBfFq5j.mjs +2764 -0
- package/dist/local-host.mjs +812 -89
- package/dist/local-profile-daemon-admin-BmQSdzT0.mjs +210 -0
- package/dist/local-scope-DamiMqPd.mjs +1340 -0
- package/dist/{local-transport-BVwFYq_Y.mjs → local-transport-Iwo0mtu3.mjs} +313 -38
- package/dist/local-web-control-DMrjwCkl.mjs +454 -0
- package/dist/local-workspace-object-D06GL0UO.mjs +248 -0
- package/dist/native/darwin/prebuilds/darwin-arm64/darwin-platform.node +0 -0
- package/dist/native/darwin/prebuilds/darwin-x64/darwin-platform.node +0 -0
- package/dist/open-CmOBxSjN.mjs +63 -0
- package/dist/persisted-setting-probe-DWZLtWoB.mjs +145 -0
- package/dist/pi-tui-acp-access-contract-BdLwduU6.mjs +75 -0
- package/dist/pi-tui-remote-contribution-Do8ECrUy.mjs +1492 -0
- package/dist/pi-tui-terminal-progress-contract-B3RoEzjK.mjs +146 -0
- package/dist/preferences.d.mts +17 -0
- package/dist/preferences.mjs +20 -0
- package/dist/preset-BcWqOtY7.mjs +46 -0
- package/dist/profile-preferences-migration-BfUGdPZx.mjs +500 -0
- package/dist/profile-preferences-migration-CThz4rHH.mjs +2 -0
- package/dist/prompt-sections-DUKmWb8g.mjs +2232 -0
- package/dist/prompt-sections-DXmjB58H.mjs +634 -0
- package/dist/{public-types-Dgf1bDke.d.mts → public-types-C1YgFtwC.d.mts} +56 -3
- package/dist/row-id-DPbyt9Nn.mjs +24 -0
- package/dist/{runtime-status-Cj1nFOdS.mjs → runtime-status-v-FTnWcD.mjs} +49 -3
- package/dist/schema-BTGYn8_X.d.mts +54 -0
- package/dist/schema-qE_P09zJ.mjs +124 -0
- package/dist/{session-BKGXyh80.mjs → session-C6tSs86s.mjs} +9672 -7270
- package/dist/{session-CPt_U8_f.mjs → session-CstInGIA.mjs} +9674 -7273
- package/dist/startup-CarQxWwi.d.mts +213 -0
- package/dist/{startup-7BYWuvBU.mjs → startup-EG5UqIcd.mjs} +341 -26
- package/dist/startup.d.mts +2 -99
- package/dist/startup.mjs +2 -2
- package/dist/{terminal-progress-source-DrqQhtT8.mjs → terminal-progress-source-CpfpQO_h.mjs} +2038 -67
- package/dist/{pasted-path-range-CMnxuGPx.mjs → transcript-view-C1YtJ49Y.mjs} +11590 -6718
- package/dist/{pasted-path-range-r6qzV_tC.mjs → transcript-view-CuJYWkhp.mjs} +12296 -6923
- package/dist/version-B9yC7bBk.mjs +83 -0
- package/dist/visual-tools.d.mts +1 -1
- package/dist/visual-tools.mjs +1 -1
- package/dist/web-preferences.d.mts +1 -1
- package/dist/{web-roster-CjqnUXNk.mjs → web-roster-Dis7BhrA.mjs} +63 -3
- package/generated/dsh-presets/cordis.patch.yml +4 -2
- package/generated/dsh-presets/ptc.patch.yml +4 -0
- package/generated/dsh-presets/standard.patch.yml +7 -0
- package/generated/web-access/cordis.patch.yml +239 -0
- package/package.json +217 -170
- package/dist/entry-control-DnduyDiw.mjs +0 -92
- package/dist/local-discovery-C9VMjc0K.mjs +0 -759
- package/dist/local-discovery-CDaQHA_R.mjs +0 -2
- package/dist/pi-tui-remote-contribution-B0EQsP0N.mjs +0 -85
- package/dist/pi-tui-terminal-progress-contract-CdBH9j78.mjs +0 -70
- package/dist/pi-tui-terminal-progress-contract-MLXZ-i3t.mjs +0 -905
- package/dist/version-a-eF-QER.mjs +0 -80
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as TUI_STARTUP_SERVICE } from "./startup-EG5UqIcd.mjs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import * as fs from "node:fs";
|
|
4
4
|
import { readFileSync } from "node:fs";
|
|
@@ -3058,10 +3058,6 @@ function getCapabilities() {
|
|
|
3058
3058
|
}
|
|
3059
3059
|
return cachedCapabilities;
|
|
3060
3060
|
}
|
|
3061
|
-
/** Override the cached capabilities. Useful in tests to exercise both code paths. */
|
|
3062
|
-
function setCapabilities(caps) {
|
|
3063
|
-
cachedCapabilities = caps;
|
|
3064
|
-
}
|
|
3065
3061
|
const KITTY_PREFIX = "\x1B_G";
|
|
3066
3062
|
const ITERM2_PREFIX = "\x1B]1337;File=";
|
|
3067
3063
|
/** The Kitty Unicode placeholder base character (Supplementary PUA, plane 16). */
|
|
@@ -3202,6 +3198,21 @@ function deleteKittyImage(imageId) {
|
|
|
3202
3198
|
return `\x1b_Ga=d,d=I,i=${imageId},q=2\x1b\\`;
|
|
3203
3199
|
}
|
|
3204
3200
|
/**
|
|
3201
|
+
* Delete Kitty image placements while keeping the uploaded image data resident
|
|
3202
|
+
* (lowercase `d=i`).
|
|
3203
|
+
*
|
|
3204
|
+
* With a `placementId`, ONLY that placement is removed (the protocol contract:
|
|
3205
|
+
* `a=d,d=i,i=<id>,p=<placement>`). Without one, every placement of the image
|
|
3206
|
+
* id is removed — still data-retaining, so it is never a destructive delete.
|
|
3207
|
+
*
|
|
3208
|
+
* The Screen uses this when a line yields only for a frame — a visible overlay
|
|
3209
|
+
* preemption (X077) — so the block can be placed again without a new
|
|
3210
|
+
* transmission and an image the Screen does not own never loses its data.
|
|
3211
|
+
*/
|
|
3212
|
+
function deleteKittyImagePlacement(imageId, placementId) {
|
|
3213
|
+
return `\x1b_Ga=d,d=i,i=${imageId}${placementId === void 0 ? "" : `,p=${placementId}`},q=2\x1b\\`;
|
|
3214
|
+
}
|
|
3215
|
+
/**
|
|
3205
3216
|
* Delete all visible Kitty graphics images.
|
|
3206
3217
|
* Uses uppercase 'A' to also free the image data.
|
|
3207
3218
|
*/
|
|
@@ -3850,6 +3861,47 @@ function compositeTuiLine(baseLine, overlayLine, startCol, overlayWidth, totalWi
|
|
|
3850
3861
|
const result = base.before + " ".repeat(beforePad) + SEGMENT_RESET + overlay.text + " ".repeat(overlayPad) + SEGMENT_RESET + base.after + " ".repeat(afterPad);
|
|
3851
3862
|
return visibleWidth(result) <= totalWidth ? result : sliceByColumn(result, 0, totalWidth, true);
|
|
3852
3863
|
}
|
|
3864
|
+
/**
|
|
3865
|
+
* The rows and image id one line's FIRST Kitty APC paints as a device layer,
|
|
3866
|
+
* or undefined when the line is not a Native Kitty placement anchor (X077).
|
|
3867
|
+
*
|
|
3868
|
+
* `a=p` is the managed placement shape and `a=T` the vendored `Image`'s inline
|
|
3869
|
+
* transmit-and-display sibling; every other action (upload, query, delete) is
|
|
3870
|
+
* not a placement. `U=1` is excluded: its pixels belong to the visible
|
|
3871
|
+
* placeholder cells, so a writer-side placement delete cannot remove it.
|
|
3872
|
+
*/
|
|
3873
|
+
/** The cell rows one Direct iTerm2 (OSC 1337) inline image paints above and
|
|
3874
|
+
* including its anchor line. The fork `Image` renders `rows - 1` blank lines
|
|
3875
|
+
* followed by `<cursorUp><OSC 1337 payload>`, so the anchor's own prefix is
|
|
3876
|
+
* the only height authority. Returns undefined for every other line.
|
|
3877
|
+
* (dsh-pi-tui divergence X080.) */
|
|
3878
|
+
function iterm2ImageBlockRows(line) {
|
|
3879
|
+
if (!line.includes("\x1B]1337;File=")) return void 0;
|
|
3880
|
+
const up = /^\x1b\[(\d{1,4})A/.exec(line)?.[1];
|
|
3881
|
+
const offset = up === void 0 ? 0 : Number.parseInt(up, 10);
|
|
3882
|
+
if (!Number.isInteger(offset) || offset < 0 || offset > 4096) return void 0;
|
|
3883
|
+
return offset + 1;
|
|
3884
|
+
}
|
|
3885
|
+
function nativeKittyBlock(line) {
|
|
3886
|
+
const controls = /\x1b_G([^;]*);/.exec(line)?.[1];
|
|
3887
|
+
if (controls === void 0) return void 0;
|
|
3888
|
+
const action = /(?:^|,)a=([A-Za-z])(?:,|$)/.exec(controls)?.[1];
|
|
3889
|
+
if (action !== "p" && action !== "T") return void 0;
|
|
3890
|
+
if (/(?:^|,)U=1(?:,|$)/.test(controls)) return void 0;
|
|
3891
|
+
const idText = /(?:^|,)i=(\d{1,10})(?:,|$)/.exec(controls)?.[1];
|
|
3892
|
+
const placementText = /(?:^|,)p=(\d{1,10})(?:,|$)/.exec(controls)?.[1];
|
|
3893
|
+
const positive = (text) => {
|
|
3894
|
+
if (text === void 0) return void 0;
|
|
3895
|
+
const value = Number.parseInt(text, 10);
|
|
3896
|
+
return Number.isInteger(value) && value > 0 && value <= 4294967295 ? value : void 0;
|
|
3897
|
+
};
|
|
3898
|
+
return {
|
|
3899
|
+
rows: getKittyImagePlacementRows(line) ?? 1,
|
|
3900
|
+
action,
|
|
3901
|
+
imageId: positive(idText),
|
|
3902
|
+
placementId: positive(placementText)
|
|
3903
|
+
};
|
|
3904
|
+
}
|
|
3853
3905
|
const VIEWPORT_TUI = Symbol.for("@earendil-works/pi-tui/viewport");
|
|
3854
3906
|
var TuiBase = class TuiBase extends Container {
|
|
3855
3907
|
terminal;
|
|
@@ -3894,6 +3946,14 @@ var TuiBase = class TuiBase extends Container {
|
|
|
3894
3946
|
* gesture-liveness check reads the CURRENT painted placement of a
|
|
3895
3947
|
* retained target). */
|
|
3896
3948
|
renderedOverlayLayouts = [];
|
|
3949
|
+
/**
|
|
3950
|
+
* The Native Kitty image ids THIS frame's projection preempted for a
|
|
3951
|
+
* visible overlay (X077). They are a per-frame fact, never durable state:
|
|
3952
|
+
* the Main Screen must remove only their placement and keep the data
|
|
3953
|
+
* resident, because the block is expected back the moment the overlay
|
|
3954
|
+
* closes and a foreign occurrence cannot re-transmit its own upload.
|
|
3955
|
+
*/
|
|
3956
|
+
preemptedKittyImageIds = /* @__PURE__ */ new Set();
|
|
3897
3957
|
get hasOverlayEntries() {
|
|
3898
3958
|
return this.overlayStack.length > 0;
|
|
3899
3959
|
}
|
|
@@ -4725,6 +4785,7 @@ var TuiBase = class TuiBase extends Container {
|
|
|
4725
4785
|
compositeOverlays(lines, termWidth, termHeight) {
|
|
4726
4786
|
if (this.overlayStack.length === 0) {
|
|
4727
4787
|
this.renderedOverlayLayouts = [];
|
|
4788
|
+
this.preemptedKittyImageIds = /* @__PURE__ */ new Set();
|
|
4728
4789
|
return lines;
|
|
4729
4790
|
}
|
|
4730
4791
|
const result = [...lines];
|
|
@@ -4764,6 +4825,30 @@ var TuiBase = class TuiBase extends Container {
|
|
|
4764
4825
|
const workingHeight = Math.max(result.length, termHeight, minLinesNeeded);
|
|
4765
4826
|
while (result.length < workingHeight) result.push("");
|
|
4766
4827
|
const viewportStart = Math.max(0, workingHeight - termHeight);
|
|
4828
|
+
const preempted = /* @__PURE__ */ new Set();
|
|
4829
|
+
if (rendered.length > 0) for (let row = viewportStart; row < result.length; row++) {
|
|
4830
|
+
const block = nativeKittyBlock(result[row] ?? "");
|
|
4831
|
+
if (block === void 0) continue;
|
|
4832
|
+
const first = row - viewportStart;
|
|
4833
|
+
const last = first + block.rows - 1;
|
|
4834
|
+
if (!rendered.some(({ overlayLines, row: overlayRow }) => overlayLines.length > 0 && overlayRow <= last && overlayRow + overlayLines.length - 1 >= first)) continue;
|
|
4835
|
+
if (block.action === "T") {
|
|
4836
|
+
result[row] = "";
|
|
4837
|
+
continue;
|
|
4838
|
+
}
|
|
4839
|
+
if (block.imageId === void 0 || block.placementId === void 0) continue;
|
|
4840
|
+
preempted.add(block.imageId);
|
|
4841
|
+
result[row] = "";
|
|
4842
|
+
}
|
|
4843
|
+
this.preemptedKittyImageIds = preempted;
|
|
4844
|
+
if (rendered.length > 0 && getCapabilities().images === "iterm2") for (let row = viewportStart; row < result.length; row++) {
|
|
4845
|
+
const rows = iterm2ImageBlockRows(result[row] ?? "");
|
|
4846
|
+
if (rows === void 0) continue;
|
|
4847
|
+
const first = row - viewportStart - (rows - 1);
|
|
4848
|
+
const last = row - viewportStart;
|
|
4849
|
+
if (!rendered.some(({ overlayLines, row: overlayRow }) => overlayLines.length > 0 && overlayRow <= last && overlayRow + overlayLines.length - 1 >= first)) continue;
|
|
4850
|
+
for (let target = row - (rows - 1); target <= row; target++) if (target >= 0) result[target] = "";
|
|
4851
|
+
}
|
|
4767
4852
|
for (const { overlayLines, row, col, w } of rendered) for (let i = 0; i < overlayLines.length; i++) {
|
|
4768
4853
|
const idx = viewportStart + row + i;
|
|
4769
4854
|
if (idx >= 0 && idx < result.length) {
|
|
@@ -5500,7 +5585,10 @@ var SelectList = class {
|
|
|
5500
5585
|
const delta = event.wheelDelta < 0 ? -1 : 1;
|
|
5501
5586
|
const previousIndex = this.selectedIndex;
|
|
5502
5587
|
this.selectedIndex = Math.max(0, Math.min(this.filteredItems.length - 1, this.selectedIndex + delta));
|
|
5503
|
-
if (this.selectedIndex !== previousIndex)
|
|
5588
|
+
if (this.selectedIndex !== previousIndex) {
|
|
5589
|
+
this.mousePressedItem = void 0;
|
|
5590
|
+
this.notifySelectionChange();
|
|
5591
|
+
}
|
|
5504
5592
|
return {
|
|
5505
5593
|
handled: true,
|
|
5506
5594
|
render: this.selectedIndex !== previousIndex
|
|
@@ -9770,6 +9858,228 @@ function trimPartialClosingFences(tokens) {
|
|
|
9770
9858
|
if (!marker || !lastLine || lastLine.length >= marker.length || lastLine !== marker[0]?.repeat(lastLine.length)) return;
|
|
9771
9859
|
token.text = token.text.slice(0, -lastLine.length).replace(/\n$/, "");
|
|
9772
9860
|
}
|
|
9861
|
+
/** Proof-mode zero-width boundary sentinels. They exist only in the disposable
|
|
9862
|
+
* rows of one `proveSourceSpan()` call and are always stripped before the proof
|
|
9863
|
+
* output is compared with the normal render. */
|
|
9864
|
+
const PROOF_OPEN = "";
|
|
9865
|
+
const PROOF_CLOSE = "";
|
|
9866
|
+
const proofSegmenter = getGraphemeSegmenter();
|
|
9867
|
+
function isGraphemeBoundary(text, index) {
|
|
9868
|
+
if (index <= 0 || index >= text.length) return true;
|
|
9869
|
+
for (const segment of proofSegmenter.segment(text)) if (segment.index === index) return true;
|
|
9870
|
+
return false;
|
|
9871
|
+
}
|
|
9872
|
+
/** Project a component-source offset onto the TAB-normalized source the parser sees. */
|
|
9873
|
+
function projectTabOffset(text, index) {
|
|
9874
|
+
let projected = index;
|
|
9875
|
+
for (let position = 0; position < index; position++) if (text.charCodeAt(position) === 9) projected += 2;
|
|
9876
|
+
return projected;
|
|
9877
|
+
}
|
|
9878
|
+
/** Remove the zero-width proof sentinels from one row without changing columns. */
|
|
9879
|
+
function stripProofSentinels(line) {
|
|
9880
|
+
if (!line.includes(PROOF_OPEN) && !line.includes(PROOF_CLOSE)) return line;
|
|
9881
|
+
return line.split(PROOF_OPEN).join("").split(PROOF_CLOSE).join("");
|
|
9882
|
+
}
|
|
9883
|
+
/**
|
|
9884
|
+
* Build a view of `content` against the raw text a block tokenizer produced it from. `content` lines are
|
|
9885
|
+
* prefixes-removed suffixes of the raw lines (blockquote markers, list indentation, code fences), so every line
|
|
9886
|
+
* must line up exactly; anything else is refused instead of guessed.
|
|
9887
|
+
* `offsets[viewIndex]` is the offset inside `raw` of the content character at `viewIndex`.
|
|
9888
|
+
*/
|
|
9889
|
+
function buildLineView(raw, content) {
|
|
9890
|
+
if (raw === content) {
|
|
9891
|
+
const offsets = new Array(content.length);
|
|
9892
|
+
for (let index = 0; index < content.length; index++) offsets[index] = index;
|
|
9893
|
+
return {
|
|
9894
|
+
text: content,
|
|
9895
|
+
offsets
|
|
9896
|
+
};
|
|
9897
|
+
}
|
|
9898
|
+
const rawLines = raw.split("\n");
|
|
9899
|
+
const contentLines = content.split("\n");
|
|
9900
|
+
if (contentLines.length > rawLines.length) return;
|
|
9901
|
+
const offsets = new Array(content.length);
|
|
9902
|
+
let viewIndex = 0;
|
|
9903
|
+
let rawLineStart = 0;
|
|
9904
|
+
for (let line = 0; line < contentLines.length; line++) {
|
|
9905
|
+
const rawLine = rawLines[line];
|
|
9906
|
+
const contentLine = contentLines[line];
|
|
9907
|
+
if (rawLine === void 0 || !rawLine.endsWith(contentLine)) return;
|
|
9908
|
+
const prefix = rawLine.length - contentLine.length;
|
|
9909
|
+
for (let index = 0; index < contentLine.length; index++) {
|
|
9910
|
+
offsets[viewIndex] = rawLineStart + prefix + index;
|
|
9911
|
+
viewIndex += 1;
|
|
9912
|
+
}
|
|
9913
|
+
if (line < contentLines.length - 1) {
|
|
9914
|
+
offsets[viewIndex] = rawLineStart + rawLine.length;
|
|
9915
|
+
viewIndex += 1;
|
|
9916
|
+
}
|
|
9917
|
+
rawLineStart += rawLine.length + 1;
|
|
9918
|
+
}
|
|
9919
|
+
return viewIndex === content.length ? {
|
|
9920
|
+
text: content,
|
|
9921
|
+
offsets
|
|
9922
|
+
} : void 0;
|
|
9923
|
+
}
|
|
9924
|
+
/** Absolute offset of a raw-relative offset, using the token's per-line mapping. */
|
|
9925
|
+
function absoluteFromRawOffset(origin, raw, rawOffset) {
|
|
9926
|
+
for (let line = 0; line < raw.length; line++) {
|
|
9927
|
+
const lineStart = origin.rawLineStarts[line];
|
|
9928
|
+
const lineEnd = lineStart + raw[line].length;
|
|
9929
|
+
if (rawOffset >= lineStart && rawOffset <= lineEnd) return origin.lineStarts[line] + (rawOffset - lineStart);
|
|
9930
|
+
}
|
|
9931
|
+
}
|
|
9932
|
+
/** Slice the visible columns `[startCol, endCol)` of an ANSI-stripped string. */
|
|
9933
|
+
function visibleColumnSlice(visible, startCol, endCol) {
|
|
9934
|
+
if (startCol < 0 || endCol < startCol) return;
|
|
9935
|
+
let column = 0;
|
|
9936
|
+
let startIndex = -1;
|
|
9937
|
+
let endIndex = -1;
|
|
9938
|
+
for (const { segment, index } of proofSegmenter.segment(visible)) {
|
|
9939
|
+
if (column === startCol && startIndex < 0) startIndex = index;
|
|
9940
|
+
if (column === endCol) {
|
|
9941
|
+
endIndex = index;
|
|
9942
|
+
break;
|
|
9943
|
+
}
|
|
9944
|
+
column += visibleWidth(segment);
|
|
9945
|
+
if (column > endCol) return;
|
|
9946
|
+
}
|
|
9947
|
+
if (startIndex < 0 && column === startCol) startIndex = visible.length;
|
|
9948
|
+
if (endIndex < 0 && column === endCol) endIndex = visible.length;
|
|
9949
|
+
if (startIndex < 0 || endIndex < 0) return;
|
|
9950
|
+
return visible.slice(startIndex, endIndex);
|
|
9951
|
+
}
|
|
9952
|
+
/** Every grapheme-boundary column of an ANSI-stripped visible string. */
|
|
9953
|
+
function visibleColumnBoundaries(visible) {
|
|
9954
|
+
const boundaries = [0];
|
|
9955
|
+
let column = 0;
|
|
9956
|
+
for (const { segment } of proofSegmenter.segment(visible)) {
|
|
9957
|
+
column += visibleWidth(segment);
|
|
9958
|
+
boundaries.push(column);
|
|
9959
|
+
}
|
|
9960
|
+
return boundaries;
|
|
9961
|
+
}
|
|
9962
|
+
/** The direct child tokens of one token, in rendering order. */
|
|
9963
|
+
function childTokensOf(token) {
|
|
9964
|
+
if (token.type === "list") return token.items;
|
|
9965
|
+
if (token.type === "table") {
|
|
9966
|
+
const table = token;
|
|
9967
|
+
const children = [];
|
|
9968
|
+
for (const cell of [...table.header, ...table.rows.flat()]) children.push(...cell.tokens ?? []);
|
|
9969
|
+
return children;
|
|
9970
|
+
}
|
|
9971
|
+
const generic = token;
|
|
9972
|
+
return generic.tokens === void 0 ? [] : [...generic.tokens];
|
|
9973
|
+
}
|
|
9974
|
+
/** Visible content of one proof row: sentinels and terminal sequences removed, trailing padding dropped. */
|
|
9975
|
+
function proofRowContent(line) {
|
|
9976
|
+
return stripTerminalSequences(stripProofSentinels(line)).trimEnd();
|
|
9977
|
+
}
|
|
9978
|
+
/**
|
|
9979
|
+
* Recover the ONE sentinel-wrapped painted range from a proof render. A range may span several wrapped rows: the
|
|
9980
|
+
* first row contributes its tail, every further row contributes its content after the layout prefix, and the last
|
|
9981
|
+
* row ends exactly at the closing sentinel. The prefix width of continuation rows is not assumed: it is the one
|
|
9982
|
+
* boundary width that reconstructs `expected` exactly, and an ambiguous reconstruction is refused.
|
|
9983
|
+
*/
|
|
9984
|
+
function recoverProofSegments(rows, expected) {
|
|
9985
|
+
let openRow = -1;
|
|
9986
|
+
let openIndex = -1;
|
|
9987
|
+
let closeRow = -1;
|
|
9988
|
+
let closeIndex = -1;
|
|
9989
|
+
for (let row = 0; row < rows.length; row++) {
|
|
9990
|
+
const line = rows[row];
|
|
9991
|
+
let cursor = 0;
|
|
9992
|
+
while (cursor <= line.length) {
|
|
9993
|
+
const open = line.indexOf(PROOF_OPEN, cursor);
|
|
9994
|
+
const close = line.indexOf(PROOF_CLOSE, cursor);
|
|
9995
|
+
if (open < 0 && close < 0) break;
|
|
9996
|
+
if (open >= 0 && (close < 0 || open < close)) {
|
|
9997
|
+
if (openRow >= 0) return { failure: "REFLOW" };
|
|
9998
|
+
openRow = row;
|
|
9999
|
+
openIndex = open;
|
|
10000
|
+
cursor = open + 1;
|
|
10001
|
+
continue;
|
|
10002
|
+
}
|
|
10003
|
+
if (closeRow >= 0 || openRow < 0) return { failure: "REFLOW" };
|
|
10004
|
+
closeRow = row;
|
|
10005
|
+
closeIndex = close;
|
|
10006
|
+
cursor = close + 1;
|
|
10007
|
+
}
|
|
10008
|
+
}
|
|
10009
|
+
if (openRow < 0 || closeRow < 0) return { failure: "REFLOW" };
|
|
10010
|
+
const openCol = visibleWidth(rows[openRow].slice(0, openIndex));
|
|
10011
|
+
const closeCol = visibleWidth(rows[closeRow].slice(0, closeIndex));
|
|
10012
|
+
if (openRow === closeRow) {
|
|
10013
|
+
const chunk = visibleColumnSlice(proofRowContent(rows[openRow]), openCol, closeCol);
|
|
10014
|
+
if (chunk === void 0) return { failure: "REFLOW" };
|
|
10015
|
+
if (chunk.length === 0 || chunk !== expected) return { failure: "RENDER_EQUIVALENCE" };
|
|
10016
|
+
return {
|
|
10017
|
+
segments: [{
|
|
10018
|
+
row: openRow,
|
|
10019
|
+
startCol: openCol,
|
|
10020
|
+
endCol: openCol + visibleWidth(chunk)
|
|
10021
|
+
}],
|
|
10022
|
+
collected: chunk
|
|
10023
|
+
};
|
|
10024
|
+
}
|
|
10025
|
+
const startVisible = proofRowContent(rows[openRow]);
|
|
10026
|
+
if (visibleWidth(startVisible) <= openCol) return { failure: "REFLOW" };
|
|
10027
|
+
const continuationTexts = [];
|
|
10028
|
+
for (let row = openRow + 1; row <= closeRow; row++) continuationTexts.push(proofRowContent(rows[row]));
|
|
10029
|
+
const closeVisible = continuationTexts[continuationTexts.length - 1];
|
|
10030
|
+
const contentEnds = visibleColumnBoundaries(startVisible).filter((column) => column > openCol);
|
|
10031
|
+
const prefixWidths = visibleColumnBoundaries(closeVisible).filter((column) => column < closeCol);
|
|
10032
|
+
const candidates = [];
|
|
10033
|
+
const seen = /* @__PURE__ */ new Set();
|
|
10034
|
+
for (const prefixWidth of prefixWidths) for (const contentEnd of contentEnds) {
|
|
10035
|
+
if (contentEnd <= prefixWidth) continue;
|
|
10036
|
+
const startChunk = visibleColumnSlice(startVisible, openCol, contentEnd);
|
|
10037
|
+
if (startChunk === void 0 || !expected.startsWith(startChunk)) continue;
|
|
10038
|
+
let left = expected.slice(startChunk.length);
|
|
10039
|
+
let valid = true;
|
|
10040
|
+
const segments = [];
|
|
10041
|
+
if (visibleWidth(startChunk) > 0) segments.push({
|
|
10042
|
+
row: openRow,
|
|
10043
|
+
startCol: openCol,
|
|
10044
|
+
endCol: openCol + visibleWidth(startChunk)
|
|
10045
|
+
});
|
|
10046
|
+
for (let index = 0; index < continuationTexts.length - 1; index++) {
|
|
10047
|
+
const visible = continuationTexts[index];
|
|
10048
|
+
if (visibleWidth(visible) < contentEnd) {
|
|
10049
|
+
valid = false;
|
|
10050
|
+
break;
|
|
10051
|
+
}
|
|
10052
|
+
const chunk = visibleColumnSlice(visible, prefixWidth, contentEnd);
|
|
10053
|
+
if (chunk === void 0 || chunk.length === 0 || !left.startsWith(chunk)) {
|
|
10054
|
+
valid = false;
|
|
10055
|
+
break;
|
|
10056
|
+
}
|
|
10057
|
+
left = left.slice(chunk.length);
|
|
10058
|
+
segments.push({
|
|
10059
|
+
row: openRow + 1 + index,
|
|
10060
|
+
startCol: prefixWidth,
|
|
10061
|
+
endCol: prefixWidth + visibleWidth(chunk)
|
|
10062
|
+
});
|
|
10063
|
+
}
|
|
10064
|
+
if (!valid) continue;
|
|
10065
|
+
const closeChunk = visibleColumnSlice(closeVisible, prefixWidth, closeCol);
|
|
10066
|
+
if (closeChunk === void 0 || closeChunk.length === 0 || closeChunk !== left) continue;
|
|
10067
|
+
segments.push({
|
|
10068
|
+
row: closeRow,
|
|
10069
|
+
startCol: prefixWidth,
|
|
10070
|
+
endCol: closeCol
|
|
10071
|
+
});
|
|
10072
|
+
const signature = segments.map((segment) => `${segment.row}:${segment.startCol}-${segment.endCol}`).join(",");
|
|
10073
|
+
if (seen.has(signature)) continue;
|
|
10074
|
+
seen.add(signature);
|
|
10075
|
+
candidates.push(segments);
|
|
10076
|
+
}
|
|
10077
|
+
if (candidates.length !== 1) return { failure: "REFLOW" };
|
|
10078
|
+
return {
|
|
10079
|
+
segments: candidates[0],
|
|
10080
|
+
collected: expected
|
|
10081
|
+
};
|
|
10082
|
+
}
|
|
9773
10083
|
const markdownParser = new Marked();
|
|
9774
10084
|
markdownParser.setOptions({ tokenizer: new MarkdownTokenizer() });
|
|
9775
10085
|
markdownParser.use({
|
|
@@ -9787,9 +10097,12 @@ var Markdown = class {
|
|
|
9787
10097
|
cachedText;
|
|
9788
10098
|
cachedWidth;
|
|
9789
10099
|
cachedLines;
|
|
10100
|
+
cachedCapabilities;
|
|
9790
10101
|
cachedTokens;
|
|
9791
10102
|
blocks;
|
|
9792
10103
|
blockHighlightedCode;
|
|
10104
|
+
proofState;
|
|
10105
|
+
primingProofBlocks = false;
|
|
9793
10106
|
constructor(text, paddingX, paddingY, theme, defaultTextStyle, options) {
|
|
9794
10107
|
this.text = text;
|
|
9795
10108
|
this.paddingX = paddingX;
|
|
@@ -9811,18 +10124,152 @@ var Markdown = class {
|
|
|
9811
10124
|
this.cachedText = void 0;
|
|
9812
10125
|
this.cachedWidth = void 0;
|
|
9813
10126
|
this.cachedLines = void 0;
|
|
10127
|
+
this.cachedCapabilities = void 0;
|
|
9814
10128
|
}
|
|
9815
10129
|
render(width) {
|
|
9816
10130
|
if (this.cachedLines && this.cachedText === this.text && this.cachedWidth === width) return this.cachedLines;
|
|
10131
|
+
const result = this.renderLines(width, false);
|
|
10132
|
+
this.cachedText = this.text;
|
|
10133
|
+
this.cachedWidth = width;
|
|
10134
|
+
this.cachedLines = result;
|
|
10135
|
+
this.cachedCapabilities = getCapabilities().hyperlinks;
|
|
10136
|
+
return result;
|
|
10137
|
+
}
|
|
10138
|
+
/**
|
|
10139
|
+
* Prove ONE source-local UTF-16 range against THIS component's own current source and the painted cells of
|
|
10140
|
+
* `render(width)`. The proof render runs the same parser and renderer and injects zero-width sentinels only into
|
|
10141
|
+
* the emitted text of the target token; it is accepted only when the proof rows, with the sentinels removed, are
|
|
10142
|
+
* byte-identical to the normal render. The normal render and block caches are never written by a proof.
|
|
10143
|
+
*/
|
|
10144
|
+
proveSourceSpan(range, width) {
|
|
10145
|
+
if (!Number.isInteger(range.start) || !Number.isInteger(range.end) || range.start < 0 || range.end <= range.start || range.end > this.text.length) return {
|
|
10146
|
+
kind: "UNPROVEN",
|
|
10147
|
+
reason: "SOURCE_PROJECTION"
|
|
10148
|
+
};
|
|
10149
|
+
if (this.text.includes(PROOF_OPEN) || this.text.includes(PROOF_CLOSE)) return {
|
|
10150
|
+
kind: "UNPROVEN",
|
|
10151
|
+
reason: "SOURCE_PROJECTION"
|
|
10152
|
+
};
|
|
10153
|
+
const hyperlinks = getCapabilities().hyperlinks;
|
|
10154
|
+
if (this.cachedLines !== void 0 && this.cachedText === this.text && this.cachedWidth === width && this.cachedCapabilities !== void 0 && this.cachedCapabilities !== hyperlinks) return {
|
|
10155
|
+
kind: "UNPROVEN",
|
|
10156
|
+
reason: "STALE_RENDER"
|
|
10157
|
+
};
|
|
10158
|
+
const cacheWasWarm = this.cachedLines !== void 0 && this.cachedText === this.text && this.cachedWidth === width;
|
|
10159
|
+
this.primingProofBlocks = true;
|
|
10160
|
+
let normalRows;
|
|
10161
|
+
try {
|
|
10162
|
+
normalRows = this.render(width);
|
|
10163
|
+
} finally {
|
|
10164
|
+
this.primingProofBlocks = false;
|
|
10165
|
+
}
|
|
10166
|
+
const cachedBlocks = this.blocks?.deref();
|
|
10167
|
+
if (cacheWasWarm && (cachedBlocks === void 0 || cachedBlocks.size === 0)) this.primeProofBlocks(width);
|
|
10168
|
+
const state = {
|
|
10169
|
+
request: {
|
|
10170
|
+
start: projectTabOffset(this.text, range.start),
|
|
10171
|
+
end: projectTabOffset(this.text, range.end)
|
|
10172
|
+
},
|
|
10173
|
+
origin: void 0,
|
|
10174
|
+
located: [],
|
|
10175
|
+
mappingFailure: void 0,
|
|
10176
|
+
sourceProjectionFailure: false,
|
|
10177
|
+
hrefCandidates: [],
|
|
10178
|
+
hrefTarget: void 0,
|
|
10179
|
+
wrappedLeaves: 0,
|
|
10180
|
+
suppressWrapping: false
|
|
10181
|
+
};
|
|
10182
|
+
this.proofState = state;
|
|
10183
|
+
let proofRows;
|
|
10184
|
+
try {
|
|
10185
|
+
proofRows = this.renderLines(width, true);
|
|
10186
|
+
} finally {
|
|
10187
|
+
this.proofState = void 0;
|
|
10188
|
+
}
|
|
10189
|
+
if (state.sourceProjectionFailure) return {
|
|
10190
|
+
kind: "UNPROVEN",
|
|
10191
|
+
reason: "SOURCE_PROJECTION"
|
|
10192
|
+
};
|
|
10193
|
+
if (state.mappingFailure !== void 0) return {
|
|
10194
|
+
kind: "UNPROVEN",
|
|
10195
|
+
reason: "TOKEN_ORIGIN"
|
|
10196
|
+
};
|
|
10197
|
+
if (proofRows.length !== normalRows.length) return {
|
|
10198
|
+
kind: "UNPROVEN",
|
|
10199
|
+
reason: "RENDER_EQUIVALENCE"
|
|
10200
|
+
};
|
|
10201
|
+
let sentinelRows = 0;
|
|
10202
|
+
for (let row = 0; row < proofRows.length; row++) {
|
|
10203
|
+
const proofRow = proofRows[row];
|
|
10204
|
+
if (proofRow.includes(PROOF_OPEN) || proofRow.includes(PROOF_CLOSE)) sentinelRows += 1;
|
|
10205
|
+
if (stripProofSentinels(proofRow) !== normalRows[row]) return {
|
|
10206
|
+
kind: "UNPROVEN",
|
|
10207
|
+
reason: "RENDER_EQUIVALENCE"
|
|
10208
|
+
};
|
|
10209
|
+
}
|
|
10210
|
+
if (sentinelRows === 0) {
|
|
10211
|
+
const request = state.request;
|
|
10212
|
+
if (state.hrefCandidates.some((candidate) => request.start >= candidate.start && request.end <= candidate.end)) return {
|
|
10213
|
+
kind: "NOT_PAINTED",
|
|
10214
|
+
reason: "HIDDEN_LINK_TARGET"
|
|
10215
|
+
};
|
|
10216
|
+
if (this.isMarkupOnlyRange(state)) return {
|
|
10217
|
+
kind: "NOT_PAINTED",
|
|
10218
|
+
reason: "MARKUP_ONLY"
|
|
10219
|
+
};
|
|
10220
|
+
return {
|
|
10221
|
+
kind: "UNPROVEN",
|
|
10222
|
+
reason: "TOKEN_ORIGIN"
|
|
10223
|
+
};
|
|
10224
|
+
}
|
|
10225
|
+
if (state.wrappedLeaves !== 1) return {
|
|
10226
|
+
kind: "UNPROVEN",
|
|
10227
|
+
reason: "TOKEN_ORIGIN"
|
|
10228
|
+
};
|
|
10229
|
+
const expected = this.text.slice(range.start, range.end);
|
|
10230
|
+
if (expected.includes("\n")) return {
|
|
10231
|
+
kind: "UNPROVEN",
|
|
10232
|
+
reason: "REFLOW"
|
|
10233
|
+
};
|
|
10234
|
+
const recovered = recoverProofSegments(proofRows, expected);
|
|
10235
|
+
if ("failure" in recovered) return {
|
|
10236
|
+
kind: "UNPROVEN",
|
|
10237
|
+
reason: recovered.failure
|
|
10238
|
+
};
|
|
10239
|
+
if (recovered.segments.length === 0) return {
|
|
10240
|
+
kind: "UNPROVEN",
|
|
10241
|
+
reason: "SOURCE_PROJECTION"
|
|
10242
|
+
};
|
|
10243
|
+
for (const segment of recovered.segments) {
|
|
10244
|
+
const normalRow = normalRows[segment.row];
|
|
10245
|
+
if (normalRow === void 0) return {
|
|
10246
|
+
kind: "UNPROVEN",
|
|
10247
|
+
reason: "RENDER_EQUIVALENCE"
|
|
10248
|
+
};
|
|
10249
|
+
if (segment.startCol < 0 || segment.endCol <= segment.startCol) return {
|
|
10250
|
+
kind: "UNPROVEN",
|
|
10251
|
+
reason: "REFLOW"
|
|
10252
|
+
};
|
|
10253
|
+
if (segment.endCol > visibleWidth(normalRow)) return {
|
|
10254
|
+
kind: "UNPROVEN",
|
|
10255
|
+
reason: "RENDER_EQUIVALENCE"
|
|
10256
|
+
};
|
|
10257
|
+
}
|
|
10258
|
+
return {
|
|
10259
|
+
kind: "PROVEN",
|
|
10260
|
+
segments: recovered.segments
|
|
10261
|
+
};
|
|
10262
|
+
}
|
|
10263
|
+
renderLines(width, proofMode) {
|
|
9817
10264
|
const contentWidth = Math.max(1, width - this.paddingX * 2);
|
|
9818
10265
|
const text = this.options.transform?.(this.text, contentWidth) ?? this.text;
|
|
10266
|
+
if (proofMode && text !== this.text) {
|
|
10267
|
+
const state = this.proofState;
|
|
10268
|
+
if (state !== void 0) state.sourceProjectionFailure = true;
|
|
10269
|
+
}
|
|
9819
10270
|
if (!text || text.trim() === "") {
|
|
9820
|
-
this.blocks = void 0;
|
|
9821
|
-
|
|
9822
|
-
this.cachedText = this.text;
|
|
9823
|
-
this.cachedWidth = width;
|
|
9824
|
-
this.cachedLines = result;
|
|
9825
|
-
return result;
|
|
10271
|
+
if (!proofMode) this.blocks = void 0;
|
|
10272
|
+
return [];
|
|
9826
10273
|
}
|
|
9827
10274
|
const normalizedText = text.replace(/\t/g, " ");
|
|
9828
10275
|
const cached = this.cachedTokens?.deref();
|
|
@@ -9830,27 +10277,30 @@ var Markdown = class {
|
|
|
9830
10277
|
if (!tokens) {
|
|
9831
10278
|
tokens = markdownParser.lexer(normalizedText);
|
|
9832
10279
|
trimPartialClosingFences(tokens);
|
|
9833
|
-
this.cachedTokens = new WeakRef({
|
|
10280
|
+
if (!proofMode) this.cachedTokens = new WeakRef({
|
|
9834
10281
|
source: normalizedText,
|
|
9835
10282
|
tokens
|
|
9836
10283
|
});
|
|
9837
10284
|
}
|
|
10285
|
+
if (proofMode) this.prepareProof(normalizedText, tokens);
|
|
9838
10286
|
const reuseBlocks = Object.keys(tokens.links).length === 0;
|
|
9839
10287
|
const previousBlocks = this.blocks?.deref();
|
|
9840
10288
|
const blocks = /* @__PURE__ */ new Map();
|
|
9841
|
-
this.blocks = new WeakRef(blocks);
|
|
10289
|
+
if (!proofMode) this.blocks = new WeakRef(blocks);
|
|
9842
10290
|
const contentLines = [];
|
|
9843
10291
|
for (let i = 0; i < tokens.length; i++) {
|
|
9844
10292
|
const token = tokens[i];
|
|
9845
10293
|
const nextTokenType = tokens[i + 1]?.type;
|
|
9846
|
-
const
|
|
10294
|
+
const proofTarget = proofMode && (this.proofIntersects(token) || this.proofNeedsHrefFallback(token));
|
|
10295
|
+
const key = proofTarget ? `${token.raw}\0proof` : token.raw;
|
|
10296
|
+
const block = ((proofMode || reuseBlocks) && !proofTarget ? blocks.get(key) ?? previousBlocks?.get(key) : void 0) ?? {
|
|
9847
10297
|
width: -1,
|
|
9848
10298
|
nextTokenType,
|
|
9849
10299
|
lines: [],
|
|
9850
10300
|
highlightedCode: /* @__PURE__ */ new Map()
|
|
9851
10301
|
};
|
|
9852
10302
|
if (block.width !== width || block.nextTokenType !== nextTokenType) this.renderBlock(block, token, nextTokenType, width, contentWidth);
|
|
9853
|
-
if (reuseBlocks) blocks.set(
|
|
10303
|
+
if (reuseBlocks || this.primingProofBlocks) blocks.set(key, block);
|
|
9854
10304
|
for (const line of block.lines) contentLines.push(line);
|
|
9855
10305
|
}
|
|
9856
10306
|
const bgFn = this.defaultTextStyle?.bgColor;
|
|
@@ -9862,11 +10312,370 @@ var Markdown = class {
|
|
|
9862
10312
|
}
|
|
9863
10313
|
flattenLines(emptyLines);
|
|
9864
10314
|
const result = emptyLines.concat(contentLines, emptyLines);
|
|
9865
|
-
this.cachedText = this.text;
|
|
9866
|
-
this.cachedWidth = width;
|
|
9867
|
-
this.cachedLines = result;
|
|
9868
10315
|
return result.length > 0 ? result : [""];
|
|
9869
10316
|
}
|
|
10317
|
+
/**
|
|
10318
|
+
* Fill the normal block cache for this exact source/width with a normal-mode render, without touching the cached
|
|
10319
|
+
* normal rows. Only a proof calls this; the cached blocks are ordinary normal blocks (no sentinel).
|
|
10320
|
+
*/
|
|
10321
|
+
primeProofBlocks(width) {
|
|
10322
|
+
const previous = this.primingProofBlocks;
|
|
10323
|
+
this.primingProofBlocks = true;
|
|
10324
|
+
try {
|
|
10325
|
+
this.renderLines(width, false);
|
|
10326
|
+
} finally {
|
|
10327
|
+
this.primingProofBlocks = previous;
|
|
10328
|
+
}
|
|
10329
|
+
}
|
|
10330
|
+
/** Whether this token owns a link that prints the fallback destination the request targets. */
|
|
10331
|
+
proofNeedsHrefFallback(token) {
|
|
10332
|
+
const state = this.proofState;
|
|
10333
|
+
if (state === void 0 || state.hrefTarget === void 0) return false;
|
|
10334
|
+
const href = state.hrefTarget.href;
|
|
10335
|
+
const pending = [token];
|
|
10336
|
+
while (pending.length > 0) {
|
|
10337
|
+
const current = pending.pop();
|
|
10338
|
+
if (current.type === "link" && current.href === href) return true;
|
|
10339
|
+
pending.push(...childTokensOf(current));
|
|
10340
|
+
}
|
|
10341
|
+
return false;
|
|
10342
|
+
}
|
|
10343
|
+
/** Whether the requested range intersects one token's own source span. */
|
|
10344
|
+
proofIntersects(token) {
|
|
10345
|
+
const state = this.proofState;
|
|
10346
|
+
if (state === void 0) return false;
|
|
10347
|
+
const origin = state.origin?.get(token);
|
|
10348
|
+
if (origin === void 0) return false;
|
|
10349
|
+
return state.request.start < origin.end && state.request.end > origin.start;
|
|
10350
|
+
}
|
|
10351
|
+
proofFail(reason) {
|
|
10352
|
+
const state = this.proofState;
|
|
10353
|
+
if (state !== void 0) state.mappingFailure ??= reason;
|
|
10354
|
+
}
|
|
10355
|
+
/**
|
|
10356
|
+
* Map every token of the ACTUAL token tree to its absolute source span. Structural `indexOf` is only a candidate
|
|
10357
|
+
* locator: child spans must stay ordered inside their parent and every stripped block view must line up line by
|
|
10358
|
+
* line, or the mapping fails closed.
|
|
10359
|
+
*/
|
|
10360
|
+
prepareProof(normalizedText, tokens) {
|
|
10361
|
+
const state = this.proofState;
|
|
10362
|
+
if (state === void 0 || state.sourceProjectionFailure) return;
|
|
10363
|
+
const origin = /* @__PURE__ */ new WeakMap();
|
|
10364
|
+
const located = [];
|
|
10365
|
+
state.origin = origin;
|
|
10366
|
+
state.located = located;
|
|
10367
|
+
const register = (token, raw, coordToAbsolute, startCoordinate) => {
|
|
10368
|
+
const rawLines = raw.split("\n");
|
|
10369
|
+
const rawLineStarts = [];
|
|
10370
|
+
const lineStarts = [];
|
|
10371
|
+
let rawOffset = 0;
|
|
10372
|
+
for (const rawLine of rawLines) {
|
|
10373
|
+
rawLineStarts.push(rawOffset);
|
|
10374
|
+
const absolute = coordToAbsolute(startCoordinate + rawOffset);
|
|
10375
|
+
if (absolute === void 0) {
|
|
10376
|
+
state.mappingFailure ??= "token-line-unmapped";
|
|
10377
|
+
return;
|
|
10378
|
+
}
|
|
10379
|
+
lineStarts.push(absolute);
|
|
10380
|
+
rawOffset += rawLine.length + 1;
|
|
10381
|
+
}
|
|
10382
|
+
const lastLine = rawLines[rawLines.length - 1] ?? "";
|
|
10383
|
+
const entry = {
|
|
10384
|
+
start: lineStarts[0] ?? 0,
|
|
10385
|
+
end: (lineStarts[lineStarts.length - 1] ?? 0) + lastLine.length,
|
|
10386
|
+
lineStarts,
|
|
10387
|
+
rawLineStarts
|
|
10388
|
+
};
|
|
10389
|
+
origin.set(token, entry);
|
|
10390
|
+
located.push({
|
|
10391
|
+
token,
|
|
10392
|
+
origin: entry
|
|
10393
|
+
});
|
|
10394
|
+
locateChildren(token, raw, coordToAbsolute, startCoordinate);
|
|
10395
|
+
};
|
|
10396
|
+
const locateChildren = (token, raw, coordToAbsolute, startCoordinate) => {
|
|
10397
|
+
const children = childTokensOf(token);
|
|
10398
|
+
if (children.length === 0) return;
|
|
10399
|
+
const stripped = token.type === "blockquote" || token.type === "list_item";
|
|
10400
|
+
let view;
|
|
10401
|
+
if (stripped) {
|
|
10402
|
+
const content = token.text;
|
|
10403
|
+
if (typeof content !== "string") {
|
|
10404
|
+
state.mappingFailure ??= "stripped-block-content";
|
|
10405
|
+
return;
|
|
10406
|
+
}
|
|
10407
|
+
view = buildLineView(raw, content);
|
|
10408
|
+
if (view === void 0) {
|
|
10409
|
+
state.mappingFailure ??= "stripped-block-view";
|
|
10410
|
+
return;
|
|
10411
|
+
}
|
|
10412
|
+
}
|
|
10413
|
+
const childToAbsolute = (coordinate) => {
|
|
10414
|
+
if (view === void 0) return coordToAbsolute(startCoordinate + coordinate);
|
|
10415
|
+
const rawOffset = view.offsets[coordinate];
|
|
10416
|
+
return rawOffset === void 0 ? void 0 : coordToAbsolute(startCoordinate + rawOffset);
|
|
10417
|
+
};
|
|
10418
|
+
const childText = view === void 0 ? raw : view.text;
|
|
10419
|
+
let cursor = 0;
|
|
10420
|
+
for (const child of children) {
|
|
10421
|
+
const childRaw = typeof child.raw === "string" ? child.raw : "";
|
|
10422
|
+
if (childRaw === "") continue;
|
|
10423
|
+
const index = childText.indexOf(childRaw, cursor);
|
|
10424
|
+
if (index < 0) {
|
|
10425
|
+
state.mappingFailure ??= "child-raw-lookup";
|
|
10426
|
+
continue;
|
|
10427
|
+
}
|
|
10428
|
+
cursor = index + childRaw.length;
|
|
10429
|
+
register(child, childRaw, childToAbsolute, index);
|
|
10430
|
+
}
|
|
10431
|
+
};
|
|
10432
|
+
let topCursor = 0;
|
|
10433
|
+
for (const token of tokens) {
|
|
10434
|
+
const raw = typeof token.raw === "string" ? token.raw : "";
|
|
10435
|
+
if (raw === "") continue;
|
|
10436
|
+
const index = normalizedText.indexOf(raw, topCursor);
|
|
10437
|
+
if (index < 0) {
|
|
10438
|
+
state.mappingFailure ??= "top-token-raw-lookup";
|
|
10439
|
+
continue;
|
|
10440
|
+
}
|
|
10441
|
+
topCursor = index + raw.length;
|
|
10442
|
+
register(token, raw, (coordinate) => coordinate, index);
|
|
10443
|
+
}
|
|
10444
|
+
const request = state.request;
|
|
10445
|
+
const hyperlinks = getCapabilities().hyperlinks;
|
|
10446
|
+
for (const locatedToken of located) {
|
|
10447
|
+
const token = locatedToken.token;
|
|
10448
|
+
if (token.type !== "link" && token.type !== "def") continue;
|
|
10449
|
+
const href = token.href;
|
|
10450
|
+
if (typeof href !== "string" || href.length === 0) continue;
|
|
10451
|
+
const rawLines = token.raw.split("\n");
|
|
10452
|
+
let index = token.raw.indexOf(href);
|
|
10453
|
+
while (index >= 0) {
|
|
10454
|
+
const absolute = absoluteFromRawOffset(locatedToken.origin, rawLines, index);
|
|
10455
|
+
const absoluteEnd = absoluteFromRawOffset(locatedToken.origin, rawLines, index + href.length);
|
|
10456
|
+
if (absolute !== void 0 && absoluteEnd === absolute + href.length) {
|
|
10457
|
+
if (request.start >= absolute && request.end <= absoluteEnd) {
|
|
10458
|
+
if (hyperlinks) state.hrefCandidates.push({
|
|
10459
|
+
start: absolute,
|
|
10460
|
+
end: absoluteEnd
|
|
10461
|
+
});
|
|
10462
|
+
else {
|
|
10463
|
+
const start = request.start - absolute;
|
|
10464
|
+
const end = request.end - absolute;
|
|
10465
|
+
if (isGraphemeBoundary(href, start) && isGraphemeBoundary(href, end)) state.hrefTarget = {
|
|
10466
|
+
href,
|
|
10467
|
+
start,
|
|
10468
|
+
end
|
|
10469
|
+
};
|
|
10470
|
+
else state.mappingFailure ??= "href-grapheme-split";
|
|
10471
|
+
}
|
|
10472
|
+
break;
|
|
10473
|
+
}
|
|
10474
|
+
}
|
|
10475
|
+
index = token.raw.indexOf(href, index + 1);
|
|
10476
|
+
}
|
|
10477
|
+
}
|
|
10478
|
+
}
|
|
10479
|
+
/**
|
|
10480
|
+
* Wrap the emitted text of ONE leaf whose raw-to-emitted identity covers the request. `rawOffset` is where the
|
|
10481
|
+
* emitted text starts inside the token raw (codespans and escapes print a sub-range of their raw). Anything that
|
|
10482
|
+
* does not line up with a single source line fails closed; a request in the markup part of the leaf is left alone.
|
|
10483
|
+
*/
|
|
10484
|
+
proofWrap(token, emitted, rawOffset = 0) {
|
|
10485
|
+
const state = this.proofState;
|
|
10486
|
+
if (state === void 0 || state.suppressWrapping) return emitted;
|
|
10487
|
+
const origin = state.origin?.get(token);
|
|
10488
|
+
if (origin === void 0) return emitted;
|
|
10489
|
+
const request = state.request;
|
|
10490
|
+
if (request.end <= origin.start || request.start >= origin.end) return emitted;
|
|
10491
|
+
const raw = token.raw;
|
|
10492
|
+
if (raw.slice(rawOffset, rawOffset + emitted.length) !== emitted) {
|
|
10493
|
+
state.mappingFailure ??= "leaf-raw-text-mismatch";
|
|
10494
|
+
return emitted;
|
|
10495
|
+
}
|
|
10496
|
+
const rawLines = raw.split("\n");
|
|
10497
|
+
let line = -1;
|
|
10498
|
+
for (let index = 0; index < rawLines.length; index++) {
|
|
10499
|
+
const lineStart = origin.lineStarts[index] ?? origin.start;
|
|
10500
|
+
const lineEnd = lineStart + rawLines[index].length;
|
|
10501
|
+
if (request.start >= lineEnd || request.end <= lineStart) continue;
|
|
10502
|
+
if (request.start >= lineStart && request.end <= lineEnd) {
|
|
10503
|
+
line = index;
|
|
10504
|
+
break;
|
|
10505
|
+
}
|
|
10506
|
+
state.mappingFailure ??= "request-crosses-line";
|
|
10507
|
+
return emitted;
|
|
10508
|
+
}
|
|
10509
|
+
if (line < 0) return emitted;
|
|
10510
|
+
const lineStart = origin.lineStarts[line] ?? origin.start;
|
|
10511
|
+
const emittedStart = origin.rawLineStarts[line] + (request.start - lineStart) - rawOffset;
|
|
10512
|
+
const emittedEnd = emittedStart + (request.end - request.start);
|
|
10513
|
+
if (emittedEnd <= 0 || emittedStart >= emitted.length) return emitted;
|
|
10514
|
+
if (emittedStart < 0 || emittedEnd > emitted.length) {
|
|
10515
|
+
state.mappingFailure ??= "request-crosses-leaf";
|
|
10516
|
+
return emitted;
|
|
10517
|
+
}
|
|
10518
|
+
if (!isGraphemeBoundary(emitted, emittedStart) || !isGraphemeBoundary(emitted, emittedEnd)) {
|
|
10519
|
+
state.mappingFailure ??= "grapheme-split";
|
|
10520
|
+
return emitted;
|
|
10521
|
+
}
|
|
10522
|
+
state.wrappedLeaves += 1;
|
|
10523
|
+
if (state.wrappedLeaves > 1) state.mappingFailure ??= "request-spans-multiple-leaves";
|
|
10524
|
+
return emitted.slice(0, emittedStart) + PROOF_OPEN + emitted.slice(emittedStart, emittedEnd) + PROOF_CLOSE + emitted.slice(emittedEnd);
|
|
10525
|
+
}
|
|
10526
|
+
/**
|
|
10527
|
+
* Print a link's fallback destination. When the request targets this exact destination, the printed fallback IS
|
|
10528
|
+
* the painted form of that source range, so it receives the proof sentinels.
|
|
10529
|
+
*/
|
|
10530
|
+
printedHref(token) {
|
|
10531
|
+
const state = this.proofState;
|
|
10532
|
+
const href = token.href;
|
|
10533
|
+
if (state === void 0 || state.suppressWrapping || state.hrefTarget === void 0) return href;
|
|
10534
|
+
const target = state.hrefTarget;
|
|
10535
|
+
if (target.href !== href) return href;
|
|
10536
|
+
state.wrappedLeaves += 1;
|
|
10537
|
+
if (state.wrappedLeaves > 1) state.mappingFailure ??= "request-spans-multiple-leaves";
|
|
10538
|
+
return href.slice(0, target.start) + PROOF_OPEN + href.slice(target.start, target.end) + PROOF_CLOSE + href.slice(target.end);
|
|
10539
|
+
}
|
|
10540
|
+
/** Wrap a rendered (possibly transformed) leaf only when its output is a direct source sub-range. */
|
|
10541
|
+
proofWrapRendered(token, emitted, pending) {
|
|
10542
|
+
const state = this.proofState;
|
|
10543
|
+
if (state === void 0 || state.suppressWrapping) return emitted;
|
|
10544
|
+
const origin = state.origin?.get(token);
|
|
10545
|
+
if (origin === void 0) return emitted;
|
|
10546
|
+
const request = state.request;
|
|
10547
|
+
if (request.end <= origin.start || request.start >= origin.end) return emitted;
|
|
10548
|
+
if (pending) {
|
|
10549
|
+
state.mappingFailure ??= "pending-math";
|
|
10550
|
+
return emitted;
|
|
10551
|
+
}
|
|
10552
|
+
const index = token.raw.indexOf(emitted);
|
|
10553
|
+
if (index < 0 || token.raw.indexOf(emitted, index + 1) >= 0) {
|
|
10554
|
+
state.mappingFailure ??= "rendered-text-not-in-source";
|
|
10555
|
+
return emitted;
|
|
10556
|
+
}
|
|
10557
|
+
return this.proofWrap(token, emitted, index);
|
|
10558
|
+
}
|
|
10559
|
+
/** Resolve the single source line/piece a code-block request maps to, inside the fence content only. */
|
|
10560
|
+
proofCodeTrace(token) {
|
|
10561
|
+
const state = this.proofState;
|
|
10562
|
+
if (state === void 0) return;
|
|
10563
|
+
const origin = state.origin?.get(token);
|
|
10564
|
+
if (origin === void 0) return;
|
|
10565
|
+
const request = state.request;
|
|
10566
|
+
if (request.end <= origin.start || request.start >= origin.end) return;
|
|
10567
|
+
const raw = token.raw;
|
|
10568
|
+
const firstNewline = raw.indexOf("\n");
|
|
10569
|
+
if (firstNewline < 0) {
|
|
10570
|
+
state.mappingFailure ??= "code-without-content";
|
|
10571
|
+
return;
|
|
10572
|
+
}
|
|
10573
|
+
const contentBase = absoluteFromRawOffset(origin, raw.split("\n"), firstNewline + 1);
|
|
10574
|
+
if (contentBase === void 0) {
|
|
10575
|
+
state.mappingFailure ??= "code-source-offset";
|
|
10576
|
+
return;
|
|
10577
|
+
}
|
|
10578
|
+
const codeText = token.text;
|
|
10579
|
+
const view = buildLineView(raw.slice(firstNewline + 1), codeText);
|
|
10580
|
+
if (view === void 0) {
|
|
10581
|
+
state.mappingFailure ??= "code-source-mismatch";
|
|
10582
|
+
return;
|
|
10583
|
+
}
|
|
10584
|
+
const codeLines = codeText.split("\n");
|
|
10585
|
+
let lineIndex = 0;
|
|
10586
|
+
for (let line = 0; line < codeLines.length; line++) {
|
|
10587
|
+
const absolute = contentBase + (view.offsets[lineIndex] ?? view.text.length);
|
|
10588
|
+
const lineEnd = absolute + codeLines[line].length;
|
|
10589
|
+
if (request.start >= lineEnd || request.end <= absolute) {
|
|
10590
|
+
lineIndex += codeLines[line].length + 1;
|
|
10591
|
+
continue;
|
|
10592
|
+
}
|
|
10593
|
+
if (request.start < absolute || request.end > lineEnd) {
|
|
10594
|
+
state.mappingFailure ??= "code-request-crosses-line";
|
|
10595
|
+
return;
|
|
10596
|
+
}
|
|
10597
|
+
return {
|
|
10598
|
+
lineIndex: line,
|
|
10599
|
+
start: request.start - absolute,
|
|
10600
|
+
end: request.end - absolute
|
|
10601
|
+
};
|
|
10602
|
+
}
|
|
10603
|
+
state.mappingFailure ??= "code-fence-or-gap";
|
|
10604
|
+
}
|
|
10605
|
+
/** Insert the proof sentinels into an already styled line whose visible text IS the source line. */
|
|
10606
|
+
insertProofRange(styled, sourceLine, start, end, mismatchReason) {
|
|
10607
|
+
if (stripTerminalSequences(styled) !== sourceLine || start < 0 || end > sourceLine.length || start >= end) {
|
|
10608
|
+
this.proofFail(mismatchReason);
|
|
10609
|
+
return styled;
|
|
10610
|
+
}
|
|
10611
|
+
if (!isGraphemeBoundary(sourceLine, start) || !isGraphemeBoundary(sourceLine, end)) {
|
|
10612
|
+
this.proofFail("grapheme-split");
|
|
10613
|
+
return styled;
|
|
10614
|
+
}
|
|
10615
|
+
let result = "";
|
|
10616
|
+
let plainIndex = 0;
|
|
10617
|
+
let index = 0;
|
|
10618
|
+
while (index < styled.length) {
|
|
10619
|
+
const ansi = extractAnsiCode(styled, index);
|
|
10620
|
+
if (ansi !== null) {
|
|
10621
|
+
result += ansi.code;
|
|
10622
|
+
index += ansi.length;
|
|
10623
|
+
continue;
|
|
10624
|
+
}
|
|
10625
|
+
if (plainIndex === start) result += PROOF_OPEN;
|
|
10626
|
+
if (plainIndex === end) result += PROOF_CLOSE;
|
|
10627
|
+
result += styled[index];
|
|
10628
|
+
plainIndex += 1;
|
|
10629
|
+
index += 1;
|
|
10630
|
+
}
|
|
10631
|
+
if (plainIndex !== sourceLine.length) {
|
|
10632
|
+
this.proofFail(mismatchReason);
|
|
10633
|
+
return styled;
|
|
10634
|
+
}
|
|
10635
|
+
if (plainIndex === end) result += PROOF_CLOSE;
|
|
10636
|
+
const state = this.proofState;
|
|
10637
|
+
if (state !== void 0) {
|
|
10638
|
+
state.wrappedLeaves += 1;
|
|
10639
|
+
if (state.wrappedLeaves > 1) state.mappingFailure ??= "request-spans-multiple-leaves";
|
|
10640
|
+
}
|
|
10641
|
+
return result;
|
|
10642
|
+
}
|
|
10643
|
+
/** Mark a non-inline block leaf the proof seam never traces as an explicit failure. */
|
|
10644
|
+
proofUnsupported(token) {
|
|
10645
|
+
if (token.type === "def" || token.type === "space") return;
|
|
10646
|
+
const state = this.proofState;
|
|
10647
|
+
if (state === void 0) return;
|
|
10648
|
+
const origin = state.origin?.get(token);
|
|
10649
|
+
if (origin === void 0) return;
|
|
10650
|
+
const request = state.request;
|
|
10651
|
+
if (request.start < origin.end && request.end > origin.start) state.mappingFailure ??= "unsupported-block-leaf";
|
|
10652
|
+
}
|
|
10653
|
+
/** A request fully inside the markup delimiters of an inline wrapper is parser-proven markup only. */
|
|
10654
|
+
isMarkupOnlyRange(state) {
|
|
10655
|
+
const wrappers = /* @__PURE__ */ new Set([
|
|
10656
|
+
"strong",
|
|
10657
|
+
"em",
|
|
10658
|
+
"del",
|
|
10659
|
+
"link",
|
|
10660
|
+
"codespan"
|
|
10661
|
+
]);
|
|
10662
|
+
const request = state.request;
|
|
10663
|
+
for (const { token, origin } of state.located) {
|
|
10664
|
+
if (!wrappers.has(token.type)) continue;
|
|
10665
|
+
if (request.start < origin.start || request.end > origin.end) continue;
|
|
10666
|
+
let painted = false;
|
|
10667
|
+
for (const other of state.located) {
|
|
10668
|
+
if (other.token === token) continue;
|
|
10669
|
+
if (other.origin.start < origin.start || other.origin.end > origin.end) continue;
|
|
10670
|
+
if (other.origin.start <= request.start && other.origin.end >= request.end) {
|
|
10671
|
+
painted = true;
|
|
10672
|
+
break;
|
|
10673
|
+
}
|
|
10674
|
+
}
|
|
10675
|
+
if (!painted) return true;
|
|
10676
|
+
}
|
|
10677
|
+
return false;
|
|
10678
|
+
}
|
|
9870
10679
|
/** Render one top-level block to output lines: wrapped, with margins, and padded or backgrounded to the width. */
|
|
9871
10680
|
renderBlock(block, token, nextTokenType, width, contentWidth) {
|
|
9872
10681
|
this.blockHighlightedCode = block.highlightedCode;
|
|
@@ -9968,13 +10777,16 @@ var Markdown = class {
|
|
|
9968
10777
|
const latexToken = token;
|
|
9969
10778
|
let rendered = !latexToken.pending && this.options.renderLatex !== false ? renderLatex(latexToken.text, { display: true }) : void 0;
|
|
9970
10779
|
if (rendered === void 0 || rendered.split("\n").some((line) => visibleWidth(line) > width)) rendered = latexToken.raw.trim();
|
|
9971
|
-
|
|
10780
|
+
const tracedRendered = this.proofWrapRendered(token, rendered, latexToken.pending === true);
|
|
10781
|
+
for (const line of tracedRendered.split("\n")) lines.push(this.applyDefaultStyle(line));
|
|
9972
10782
|
if (nextTokenType && nextTokenType !== "space") lines.push("");
|
|
9973
10783
|
break;
|
|
9974
10784
|
}
|
|
9975
10785
|
case "code": {
|
|
9976
10786
|
const indent = this.theme.codeBlockIndent ?? " ";
|
|
10787
|
+
const trace = this.proofCodeTrace(token);
|
|
9977
10788
|
lines.push(this.theme.codeBlockBorder(`\`\`\`${token.lang || ""}`));
|
|
10789
|
+
const codeLines = token.text.split("\n");
|
|
9978
10790
|
if (this.theme.highlightCode) {
|
|
9979
10791
|
const key = `${token.lang ?? ""}\0${token.text}`;
|
|
9980
10792
|
let highlighted = this.blockHighlightedCode?.get(key);
|
|
@@ -9982,10 +10794,16 @@ var Markdown = class {
|
|
|
9982
10794
|
highlighted = this.theme.highlightCode(token.text, token.lang);
|
|
9983
10795
|
this.blockHighlightedCode?.set(key, highlighted);
|
|
9984
10796
|
}
|
|
9985
|
-
|
|
9986
|
-
|
|
9987
|
-
|
|
9988
|
-
|
|
10797
|
+
if (trace !== void 0 && highlighted.length !== codeLines.length) this.proofFail("code-highlight-line-count");
|
|
10798
|
+
for (let index = 0; index < highlighted.length; index++) {
|
|
10799
|
+
let hlLine = highlighted[index];
|
|
10800
|
+
if (trace !== void 0 && highlighted.length === codeLines.length && trace.lineIndex === index) hlLine = this.insertProofRange(hlLine, codeLines[index], trace.start, trace.end, "code-highlight-mismatch");
|
|
10801
|
+
lines.push(`${indent}${hlLine}`);
|
|
10802
|
+
}
|
|
10803
|
+
} else for (let index = 0; index < codeLines.length; index++) {
|
|
10804
|
+
let codeLine = this.theme.codeBlock(codeLines[index]);
|
|
10805
|
+
if (trace !== void 0 && trace.lineIndex === index) codeLine = this.insertProofRange(codeLine, codeLines[index], trace.start, trace.end, "code-style-mismatch");
|
|
10806
|
+
lines.push(`${indent}${codeLine}`);
|
|
9989
10807
|
}
|
|
9990
10808
|
lines.push(this.theme.codeBlockBorder("```"));
|
|
9991
10809
|
if (nextTokenType && nextTokenType !== "space") lines.push("");
|
|
@@ -10039,12 +10857,15 @@ var Markdown = class {
|
|
|
10039
10857
|
if (nextTokenType && nextTokenType !== "space") lines.push("");
|
|
10040
10858
|
break;
|
|
10041
10859
|
case "html":
|
|
10860
|
+
this.proofUnsupported(token);
|
|
10042
10861
|
if ("raw" in token && typeof token.raw === "string") lines.push(this.applyDefaultStyle(token.raw.trim()));
|
|
10043
10862
|
break;
|
|
10044
10863
|
case "space":
|
|
10045
10864
|
lines.push("");
|
|
10046
10865
|
break;
|
|
10047
|
-
default:
|
|
10866
|
+
default:
|
|
10867
|
+
this.proofUnsupported(token);
|
|
10868
|
+
if ("text" in token && typeof token.text === "string") lines.push(token.text);
|
|
10048
10869
|
}
|
|
10049
10870
|
return lines;
|
|
10050
10871
|
}
|
|
@@ -10059,15 +10880,17 @@ var Markdown = class {
|
|
|
10059
10880
|
case "latex": {
|
|
10060
10881
|
const latexToken = token;
|
|
10061
10882
|
const rendered = !latexToken.pending && this.options.renderLatex !== false ? renderLatex(latexToken.text) ?? latexToken.raw : latexToken.raw;
|
|
10062
|
-
result += applyTextWithNewlines(rendered);
|
|
10883
|
+
result += applyTextWithNewlines(this.proofWrapRendered(token, rendered, latexToken.pending === true));
|
|
10063
10884
|
break;
|
|
10064
10885
|
}
|
|
10065
|
-
case "escape":
|
|
10066
|
-
|
|
10886
|
+
case "escape": {
|
|
10887
|
+
const escaped = this.options.preserveBackslashEscapes ? token.raw : token.text;
|
|
10888
|
+
result += applyTextWithNewlines(this.proofWrap(token, escaped, Math.max(0, token.raw.indexOf(escaped))));
|
|
10067
10889
|
break;
|
|
10890
|
+
}
|
|
10068
10891
|
case "text":
|
|
10069
10892
|
if (token.tokens && token.tokens.length > 0) result += this.renderInlineTokens(token.tokens, resolvedStyleContext);
|
|
10070
|
-
else result += applyTextWithNewlines(token.text);
|
|
10893
|
+
else result += applyTextWithNewlines(this.proofWrap(token, token.text));
|
|
10071
10894
|
break;
|
|
10072
10895
|
case "paragraph":
|
|
10073
10896
|
result += this.renderInlineTokens(token.tokens || [], resolvedStyleContext);
|
|
@@ -10083,7 +10906,7 @@ var Markdown = class {
|
|
|
10083
10906
|
break;
|
|
10084
10907
|
}
|
|
10085
10908
|
case "codespan":
|
|
10086
|
-
result += this.theme.code(token.text) + stylePrefix;
|
|
10909
|
+
result += this.theme.code(this.proofWrap(token, token.text, Math.max(0, token.raw.indexOf(token.text)))) + stylePrefix;
|
|
10087
10910
|
break;
|
|
10088
10911
|
case "link": {
|
|
10089
10912
|
const linkText = this.renderInlineTokens(token.tokens || [], resolvedStyleContext);
|
|
@@ -10092,7 +10915,7 @@ var Markdown = class {
|
|
|
10092
10915
|
else {
|
|
10093
10916
|
const hrefForComparison = token.href.startsWith("mailto:") ? token.href.slice(7) : token.href;
|
|
10094
10917
|
if (token.text === token.href || token.text === hrefForComparison) result += styledLink + stylePrefix;
|
|
10095
|
-
else result += styledLink + this.theme.linkUrl(` (${token
|
|
10918
|
+
else result += styledLink + this.theme.linkUrl(` (${this.printedHref(token)})`) + stylePrefix;
|
|
10096
10919
|
}
|
|
10097
10920
|
break;
|
|
10098
10921
|
}
|
|
@@ -10105,9 +10928,9 @@ var Markdown = class {
|
|
|
10105
10928
|
break;
|
|
10106
10929
|
}
|
|
10107
10930
|
case "html":
|
|
10108
|
-
if ("raw" in token && typeof token.raw === "string") result += applyTextWithNewlines(token.raw);
|
|
10931
|
+
if ("raw" in token && typeof token.raw === "string") result += applyTextWithNewlines(this.proofWrap(token, token.raw));
|
|
10109
10932
|
break;
|
|
10110
|
-
default: if ("text" in token && typeof token.text === "string") result += applyTextWithNewlines(token.text);
|
|
10933
|
+
default: if ("text" in token && typeof token.text === "string") result += applyTextWithNewlines(this.proofWrap(token, token.text));
|
|
10111
10934
|
}
|
|
10112
10935
|
while (stylePrefix && result.endsWith(stylePrefix)) result = result.slice(0, -stylePrefix.length);
|
|
10113
10936
|
return result;
|
|
@@ -10193,15 +11016,21 @@ var Markdown = class {
|
|
|
10193
11016
|
const maxUnbrokenWordWidth = 30;
|
|
10194
11017
|
const naturalWidths = [];
|
|
10195
11018
|
const minWordWidths = [];
|
|
10196
|
-
|
|
10197
|
-
|
|
10198
|
-
|
|
10199
|
-
|
|
10200
|
-
|
|
10201
|
-
|
|
10202
|
-
|
|
10203
|
-
|
|
10204
|
-
|
|
11019
|
+
const proofState = this.proofState;
|
|
11020
|
+
if (proofState !== void 0) proofState.suppressWrapping = true;
|
|
11021
|
+
try {
|
|
11022
|
+
for (let i = 0; i < numCols; i++) {
|
|
11023
|
+
const headerText = this.renderInlineTokens(token.header[i].tokens || [], styleContext);
|
|
11024
|
+
naturalWidths[i] = visibleWidth(headerText);
|
|
11025
|
+
minWordWidths[i] = Math.max(1, this.getLongestWordWidth(headerText, maxUnbrokenWordWidth));
|
|
11026
|
+
}
|
|
11027
|
+
for (const row of token.rows) for (let i = 0; i < row.length; i++) {
|
|
11028
|
+
const cellText = this.renderInlineTokens(row[i].tokens || [], styleContext);
|
|
11029
|
+
naturalWidths[i] = Math.max(naturalWidths[i] || 0, visibleWidth(cellText));
|
|
11030
|
+
minWordWidths[i] = Math.max(minWordWidths[i] || 1, this.getLongestWordWidth(cellText, maxUnbrokenWordWidth));
|
|
11031
|
+
}
|
|
11032
|
+
} finally {
|
|
11033
|
+
if (proofState !== void 0) proofState.suppressWrapping = false;
|
|
10205
11034
|
}
|
|
10206
11035
|
let minColumnWidths = minWordWidths;
|
|
10207
11036
|
let minCellsWidth = minColumnWidths.reduce((a, b) => a + b, 0);
|
|
@@ -12742,7 +13571,6 @@ var TuiAltScreen = class extends TuiBase {
|
|
|
12742
13571
|
imageProtocol = null;
|
|
12743
13572
|
/** Per-instance protocol selection; never mutates the process-wide cache. */
|
|
12744
13573
|
imageProtocolOverride;
|
|
12745
|
-
savedCapabilities;
|
|
12746
13574
|
uploadedKittyImages = /* @__PURE__ */ new Map();
|
|
12747
13575
|
/**
|
|
12748
13576
|
* Per-row trusted SIXEL block height of the LAST painted frame (X074).
|
|
@@ -12951,14 +13779,6 @@ var TuiAltScreen = class extends TuiBase {
|
|
|
12951
13779
|
const capabilities = getCapabilities();
|
|
12952
13780
|
this.imageProtocol = this.imageProtocolOverride !== void 0 ? this.imageProtocolOverride : capabilities.images;
|
|
12953
13781
|
this.uploadedKittyImages.clear();
|
|
12954
|
-
if (capabilities.images === "iterm2") {
|
|
12955
|
-
this.savedCapabilities = capabilities;
|
|
12956
|
-
setCapabilities({
|
|
12957
|
-
...capabilities,
|
|
12958
|
-
images: null
|
|
12959
|
-
});
|
|
12960
|
-
this.invalidate();
|
|
12961
|
-
}
|
|
12962
13782
|
this.lastDocument = [];
|
|
12963
13783
|
this.selectionAnchor = void 0;
|
|
12964
13784
|
this.selectionFocus = void 0;
|
|
@@ -13005,10 +13825,6 @@ var TuiAltScreen = class extends TuiBase {
|
|
|
13005
13825
|
buffer += `\x1b[0m${ENABLE_AUTOWRAP}\r\n\x1b[?25h${END_SYNCHRONIZED_OUTPUT}`;
|
|
13006
13826
|
this.terminal.write(buffer);
|
|
13007
13827
|
}
|
|
13008
|
-
if (this.savedCapabilities) {
|
|
13009
|
-
setCapabilities(this.savedCapabilities);
|
|
13010
|
-
this.savedCapabilities = void 0;
|
|
13011
|
-
}
|
|
13012
13828
|
}
|
|
13013
13829
|
getExitRestorePrefix() {
|
|
13014
13830
|
const prefix = super.getExitRestorePrefix();
|
|
@@ -14578,6 +15394,7 @@ function parseKittyImageHeader(line) {
|
|
|
14578
15394
|
const paramsEnd = line.indexOf(";", paramsStart);
|
|
14579
15395
|
if (paramsEnd === -1) return void 0;
|
|
14580
15396
|
const ids = [];
|
|
15397
|
+
const placementIds = [];
|
|
14581
15398
|
let rows = 1;
|
|
14582
15399
|
for (const param of line.slice(paramsStart, paramsEnd).split(",")) {
|
|
14583
15400
|
const [key, value] = param.split("=", 2);
|
|
@@ -14585,10 +15402,12 @@ function parseKittyImageHeader(line) {
|
|
|
14585
15402
|
const numberValue = Number(value);
|
|
14586
15403
|
if (!Number.isInteger(numberValue) || numberValue <= 0 || numberValue > 4294967295) continue;
|
|
14587
15404
|
if (key === "i") ids.push(numberValue);
|
|
15405
|
+
else if (key === "p") placementIds.push(numberValue);
|
|
14588
15406
|
else if (key === "r") rows = numberValue;
|
|
14589
15407
|
}
|
|
14590
15408
|
return {
|
|
14591
15409
|
ids,
|
|
15410
|
+
placementIds,
|
|
14592
15411
|
rows
|
|
14593
15412
|
};
|
|
14594
15413
|
}
|
|
@@ -14598,6 +15417,15 @@ function extractKittyImageIds(line) {
|
|
|
14598
15417
|
function extractKittyImageRows(line) {
|
|
14599
15418
|
return parseKittyImageHeader(line)?.rows ?? 1;
|
|
14600
15419
|
}
|
|
15420
|
+
/** The explicit placement id of one image line, or undefined when it has none. */
|
|
15421
|
+
function extractKittyPlacementId(line) {
|
|
15422
|
+
return parseKittyImageHeader(line)?.placementIds[0];
|
|
15423
|
+
}
|
|
15424
|
+
/** Whether a line is the same explicit image placement (same image and placement id). */
|
|
15425
|
+
function isSameKittyPlacement(line, imageId, placementId) {
|
|
15426
|
+
const header = parseKittyImageHeader(line);
|
|
15427
|
+
return header !== void 0 && header.ids.includes(imageId) && header.placementIds.includes(placementId);
|
|
15428
|
+
}
|
|
14601
15429
|
function isTermuxSession() {
|
|
14602
15430
|
return Boolean(process.env.TERMUX_VERSION);
|
|
14603
15431
|
}
|
|
@@ -14698,6 +15526,19 @@ var TuiMainScreen = class extends TuiBase {
|
|
|
14698
15526
|
for (const lineIds of lineImageIds) for (const id of lineIds) ids.add(id);
|
|
14699
15527
|
return ids;
|
|
14700
15528
|
}
|
|
15529
|
+
/**
|
|
15530
|
+
* Rows the clamped diff skipped (above the viewport) are committed
|
|
15531
|
+
* scrollback: the terminal still holds their previous text and image state,
|
|
15532
|
+
* so every incremental commit must keep the previous caches for that prefix
|
|
15533
|
+
* instead of claiming the new frame's values were rendered — including the
|
|
15534
|
+
* image-id metadata the kitty cleanup record is built from. A later full
|
|
15535
|
+
* render reprocesses those rows from their current raw, repaints them, and
|
|
15536
|
+
* deletes exactly the images the model still holds. (dsh-pi-tui divergence
|
|
15537
|
+
* X078.)
|
|
15538
|
+
*/
|
|
15539
|
+
mergeSkippedPrefix(previous, next, skipRows) {
|
|
15540
|
+
return skipRows > 0 ? [...previous.slice(0, skipRows), ...next.slice(skipRows)] : next;
|
|
15541
|
+
}
|
|
14701
15542
|
deleteKittyImages(ids) {
|
|
14702
15543
|
let buffer = "";
|
|
14703
15544
|
for (const id of ids) buffer += deleteKittyImage(id);
|
|
@@ -14893,12 +15734,24 @@ var TuiMainScreen = class extends TuiBase {
|
|
|
14893
15734
|
lastChanged: expandedLastChanged
|
|
14894
15735
|
};
|
|
14895
15736
|
}
|
|
14896
|
-
deleteChangedKittyImages(firstChanged, lastChanged) {
|
|
15737
|
+
deleteChangedKittyImages(firstChanged, lastChanged, newLines) {
|
|
14897
15738
|
if (firstChanged < 0 || lastChanged < firstChanged) return "";
|
|
14898
15739
|
const ids = /* @__PURE__ */ new Set();
|
|
15740
|
+
let buffer = "";
|
|
14899
15741
|
const maxLine = Math.min(lastChanged, this.previousLines.length - 1);
|
|
14900
|
-
for (let i = firstChanged; i <= maxLine; i++)
|
|
14901
|
-
|
|
15742
|
+
for (let i = firstChanged; i <= maxLine; i++) {
|
|
15743
|
+
const previousLine = this.previousLines[i] ?? "";
|
|
15744
|
+
const newLine = newLines[i] ?? "";
|
|
15745
|
+
for (const id of this.previousLineImageIds[i] ?? EMPTY_IMAGE_IDS) {
|
|
15746
|
+
const placementId = extractKittyPlacementId(previousLine);
|
|
15747
|
+
if (placementId !== void 0 && (this.preemptedKittyImageIds.has(id) || isSameKittyPlacement(newLine, id, placementId))) {
|
|
15748
|
+
buffer += deleteKittyImagePlacement(id, placementId);
|
|
15749
|
+
continue;
|
|
15750
|
+
}
|
|
15751
|
+
ids.add(id);
|
|
15752
|
+
}
|
|
15753
|
+
}
|
|
15754
|
+
return buffer + this.deleteKittyImages(ids);
|
|
14902
15755
|
}
|
|
14903
15756
|
/**
|
|
14904
15757
|
* Drop the DCS of every trusted SIXEL block that a visible overlay paints
|
|
@@ -14982,6 +15835,7 @@ var TuiMainScreen = class extends TuiBase {
|
|
|
14982
15835
|
return targetRow - viewportTop - currentScreenRow;
|
|
14983
15836
|
};
|
|
14984
15837
|
let rawLines = this.resolveFakeCursors(this.render(width).map((line) => line.replace(OSC133_ZONE_PREFIX, "")));
|
|
15838
|
+
this.preemptedKittyImageIds = /* @__PURE__ */ new Set();
|
|
14985
15839
|
if (this.hasOverlayEntries) {
|
|
14986
15840
|
rawLines = this.compositeOverlays(rawLines, width, height);
|
|
14987
15841
|
this.suppressOverlayCoveredSixelBlocks(rawLines);
|
|
@@ -15096,7 +15950,8 @@ var TuiMainScreen = class extends TuiBase {
|
|
|
15096
15950
|
let firstChanged = -1;
|
|
15097
15951
|
let lastChanged = -1;
|
|
15098
15952
|
const maxLines = Math.max(newLines.length, this.previousLines.length);
|
|
15099
|
-
|
|
15953
|
+
const diffScanStart = heightChanged ? 0 : prevViewportTop;
|
|
15954
|
+
for (let i = diffScanStart; i < maxLines; i++) if ((i < this.previousLines.length ? this.previousLines[i] : "") !== (i < newLines.length ? newLines[i] : "")) {
|
|
15100
15955
|
if (firstChanged === -1) firstChanged = i;
|
|
15101
15956
|
lastChanged = i;
|
|
15102
15957
|
}
|
|
@@ -15115,20 +15970,20 @@ var TuiMainScreen = class extends TuiBase {
|
|
|
15115
15970
|
this.positionHardwareCursor(cursorPos, newLines.length);
|
|
15116
15971
|
this.previousViewportTop = prevViewportTop;
|
|
15117
15972
|
this.previousHeight = height;
|
|
15118
|
-
this.previousRawLines = rawLines;
|
|
15119
|
-
this.previousLineImageIds = lineImageIds;
|
|
15120
|
-
this.previousLineImageRows = lineImageRows;
|
|
15121
|
-
this.previousLineSixelRows = lineSixelRows;
|
|
15973
|
+
this.previousRawLines = this.mergeSkippedPrefix(this.previousRawLines, rawLines, diffScanStart);
|
|
15974
|
+
this.previousLineImageIds = this.mergeSkippedPrefix(this.previousLineImageIds, lineImageIds, diffScanStart);
|
|
15975
|
+
this.previousLineImageRows = this.mergeSkippedPrefix(this.previousLineImageRows, lineImageRows, diffScanStart);
|
|
15976
|
+
this.previousLineSixelRows = this.mergeSkippedPrefix(this.previousLineSixelRows, lineSixelRows, diffScanStart);
|
|
15122
15977
|
return;
|
|
15123
15978
|
}
|
|
15124
15979
|
if (firstChanged >= newLines.length) {
|
|
15125
15980
|
if (this.previousLines.length > newLines.length) {
|
|
15126
15981
|
const output = new BoundedTerminalWriter((data) => this.terminal.write(data));
|
|
15127
15982
|
output.append("\x1B[?2026h");
|
|
15128
|
-
output.append(this.deleteChangedKittyImages(firstChanged, lastChanged));
|
|
15983
|
+
output.append(this.deleteChangedKittyImages(firstChanged, lastChanged, newLines));
|
|
15129
15984
|
const targetRow = Math.max(0, newLines.length - 1);
|
|
15130
|
-
if (
|
|
15131
|
-
logRedraw(`deleted lines moved viewport up (${
|
|
15985
|
+
if (frameViewportTop < prevViewportTop) {
|
|
15986
|
+
logRedraw(`deleted lines moved viewport up (${frameViewportTop} < ${prevViewportTop})`);
|
|
15132
15987
|
fullRender(true);
|
|
15133
15988
|
return;
|
|
15134
15989
|
}
|
|
@@ -15157,25 +16012,25 @@ var TuiMainScreen = class extends TuiBase {
|
|
|
15157
16012
|
this.hardwareCursorRow = targetRow;
|
|
15158
16013
|
}
|
|
15159
16014
|
this.positionHardwareCursor(cursorPos, newLines.length);
|
|
15160
|
-
this.previousLines = newLines;
|
|
15161
|
-
this.previousRawLines = rawLines;
|
|
15162
|
-
this.previousLineImageIds = lineImageIds;
|
|
15163
|
-
this.previousLineImageRows = lineImageRows;
|
|
15164
|
-
this.previousLineSixelRows = lineSixelRows;
|
|
15165
|
-
this.previousKittyImageIds = this.unionKittyImageIds(
|
|
16015
|
+
this.previousLines = this.mergeSkippedPrefix(this.previousLines, newLines, diffScanStart);
|
|
16016
|
+
this.previousRawLines = this.mergeSkippedPrefix(this.previousRawLines, rawLines, diffScanStart);
|
|
16017
|
+
this.previousLineImageIds = this.mergeSkippedPrefix(this.previousLineImageIds, lineImageIds, diffScanStart);
|
|
16018
|
+
this.previousLineImageRows = this.mergeSkippedPrefix(this.previousLineImageRows, lineImageRows, diffScanStart);
|
|
16019
|
+
this.previousLineSixelRows = this.mergeSkippedPrefix(this.previousLineSixelRows, lineSixelRows, diffScanStart);
|
|
16020
|
+
this.previousKittyImageIds = this.unionKittyImageIds(this.previousLineImageIds);
|
|
15166
16021
|
this.previousWidth = width;
|
|
15167
16022
|
this.previousHeight = height;
|
|
15168
16023
|
this.previousViewportTop = prevViewportTop;
|
|
15169
16024
|
return;
|
|
15170
16025
|
}
|
|
15171
|
-
if (firstChanged < prevViewportTop) {
|
|
15172
|
-
logRedraw(`firstChanged < viewportTop (${firstChanged} < ${prevViewportTop})`);
|
|
16026
|
+
if (firstChanged < prevViewportTop || frameViewportTop < prevViewportTop) {
|
|
16027
|
+
logRedraw(firstChanged < prevViewportTop ? `firstChanged < viewportTop (${firstChanged} < ${prevViewportTop})` : `viewport would move up (${frameViewportTop} < ${prevViewportTop})`);
|
|
15173
16028
|
fullRender(true);
|
|
15174
16029
|
return;
|
|
15175
16030
|
}
|
|
15176
16031
|
const output = new BoundedTerminalWriter((data) => this.terminal.write(data));
|
|
15177
16032
|
output.append("\x1B[?2026h");
|
|
15178
|
-
output.append(this.deleteChangedKittyImages(firstChanged, lastChanged));
|
|
16033
|
+
output.append(this.deleteChangedKittyImages(firstChanged, lastChanged, newLines));
|
|
15179
16034
|
const prevViewportBottom = prevViewportTop + height - 1;
|
|
15180
16035
|
const moveTargetRow = appendStart ? firstChanged - 1 : firstChanged;
|
|
15181
16036
|
if (moveTargetRow > prevViewportBottom) {
|
|
@@ -15298,12 +16153,12 @@ var TuiMainScreen = class extends TuiBase {
|
|
|
15298
16153
|
this.maxLinesRendered = Math.max(this.maxLinesRendered, newLines.length);
|
|
15299
16154
|
this.previousViewportTop = Math.max(prevViewportTop, finalCursorRow - height + 1);
|
|
15300
16155
|
this.positionHardwareCursor(cursorPos, newLines.length);
|
|
15301
|
-
this.previousLines = newLines;
|
|
15302
|
-
this.previousRawLines = rawLines;
|
|
15303
|
-
this.previousLineImageIds = lineImageIds;
|
|
15304
|
-
this.previousLineImageRows = lineImageRows;
|
|
15305
|
-
this.previousLineSixelRows = lineSixelRows;
|
|
15306
|
-
this.previousKittyImageIds = this.unionKittyImageIds(
|
|
16156
|
+
this.previousLines = this.mergeSkippedPrefix(this.previousLines, newLines, diffScanStart);
|
|
16157
|
+
this.previousRawLines = this.mergeSkippedPrefix(this.previousRawLines, rawLines, diffScanStart);
|
|
16158
|
+
this.previousLineImageIds = this.mergeSkippedPrefix(this.previousLineImageIds, lineImageIds, diffScanStart);
|
|
16159
|
+
this.previousLineImageRows = this.mergeSkippedPrefix(this.previousLineImageRows, lineImageRows, diffScanStart);
|
|
16160
|
+
this.previousLineSixelRows = this.mergeSkippedPrefix(this.previousLineSixelRows, lineSixelRows, diffScanStart);
|
|
16161
|
+
this.previousKittyImageIds = this.unionKittyImageIds(this.previousLineImageIds);
|
|
15307
16162
|
this.previousWidth = width;
|
|
15308
16163
|
this.previousHeight = height;
|
|
15309
16164
|
}
|
|
@@ -15720,19 +16575,35 @@ const APP_KEYBINDINGS = {
|
|
|
15720
16575
|
"app.exit.request": {
|
|
15721
16576
|
id: "app.exit.request",
|
|
15722
16577
|
defaultKeys: ["ctrl+c", "ctrl+d"],
|
|
15723
|
-
description: "
|
|
16578
|
+
description: "Exit this TUI (a same-key second press confirms; a daemon Host keeps running; the editor keeps its default clear-draft and forward-delete behavior)",
|
|
15724
16579
|
category: "Agent",
|
|
15725
16580
|
scope: "global",
|
|
15726
16581
|
configurable: true
|
|
15727
16582
|
},
|
|
16583
|
+
"app.transcript.search.view": {
|
|
16584
|
+
id: "app.transcript.search.view",
|
|
16585
|
+
defaultKeys: ["ctrl+f"],
|
|
16586
|
+
description: "Search the rendered transcript view",
|
|
16587
|
+
category: "Transcript",
|
|
16588
|
+
scope: "global",
|
|
16589
|
+
configurable: true
|
|
16590
|
+
},
|
|
15728
16591
|
"app.transcript.search": {
|
|
15729
16592
|
id: "app.transcript.search",
|
|
15730
|
-
defaultKeys: ["ctrl+
|
|
15731
|
-
description: "Search the transcript",
|
|
16593
|
+
defaultKeys: ["ctrl+shift+f"],
|
|
16594
|
+
description: "Search the full transcript history",
|
|
15732
16595
|
category: "Transcript",
|
|
15733
16596
|
scope: "global",
|
|
15734
16597
|
configurable: true
|
|
15735
16598
|
},
|
|
16599
|
+
"app.transcript.search.scope": {
|
|
16600
|
+
id: "app.transcript.search.scope",
|
|
16601
|
+
defaultKeys: ["tab"],
|
|
16602
|
+
description: "Switch transcript search scope",
|
|
16603
|
+
category: "Transcript",
|
|
16604
|
+
scope: "search",
|
|
16605
|
+
configurable: false
|
|
16606
|
+
},
|
|
15736
16607
|
"app.transcript.jumpLatest": {
|
|
15737
16608
|
id: "app.transcript.jumpLatest",
|
|
15738
16609
|
defaultKeys: ["ctrl+end"],
|
|
@@ -15853,6 +16724,14 @@ const APP_KEYBINDINGS = {
|
|
|
15853
16724
|
scope: "editor",
|
|
15854
16725
|
configurable: true
|
|
15855
16726
|
},
|
|
16727
|
+
"app.queue.open": {
|
|
16728
|
+
id: "app.queue.open",
|
|
16729
|
+
defaultKeys: ["alt+i"],
|
|
16730
|
+
description: "Manage queued messages",
|
|
16731
|
+
category: "Panels",
|
|
16732
|
+
scope: "global",
|
|
16733
|
+
configurable: true
|
|
16734
|
+
},
|
|
15856
16735
|
"app.history.search": {
|
|
15857
16736
|
id: "app.history.search",
|
|
15858
16737
|
defaultKeys: ["ctrl+r"],
|
|
@@ -16025,18 +16904,34 @@ const APP_KEYBINDINGS = {
|
|
|
16025
16904
|
scope: "tasks",
|
|
16026
16905
|
configurable: false
|
|
16027
16906
|
},
|
|
16028
|
-
"tasks.
|
|
16029
|
-
id: "tasks.
|
|
16907
|
+
"tasks.tab.next": {
|
|
16908
|
+
id: "tasks.tab.next",
|
|
16030
16909
|
defaultKeys: ["tab"],
|
|
16031
|
-
description: "
|
|
16910
|
+
description: "Switch to the Team page of the Task Center",
|
|
16032
16911
|
category: "Tasks",
|
|
16033
16912
|
scope: "tasks",
|
|
16034
16913
|
configurable: false
|
|
16035
16914
|
},
|
|
16036
|
-
"tasks.
|
|
16037
|
-
id: "tasks.
|
|
16915
|
+
"tasks.tab.previous": {
|
|
16916
|
+
id: "tasks.tab.previous",
|
|
16038
16917
|
defaultKeys: ["shift+tab"],
|
|
16039
|
-
description: "
|
|
16918
|
+
description: "Switch back to the Work page of the Task Center",
|
|
16919
|
+
category: "Tasks",
|
|
16920
|
+
scope: "tasks",
|
|
16921
|
+
configurable: false
|
|
16922
|
+
},
|
|
16923
|
+
"tasks.type.filter": {
|
|
16924
|
+
id: "tasks.type.filter",
|
|
16925
|
+
defaultKeys: ["f"],
|
|
16926
|
+
description: "Open the Work type filter list",
|
|
16927
|
+
category: "Tasks",
|
|
16928
|
+
scope: "tasks",
|
|
16929
|
+
configurable: false
|
|
16930
|
+
},
|
|
16931
|
+
"tasks.jobs.toggleHistory": {
|
|
16932
|
+
id: "tasks.jobs.toggleHistory",
|
|
16933
|
+
defaultKeys: ["j"],
|
|
16934
|
+
description: "Show or hide tracked past Jobs",
|
|
16040
16935
|
category: "Tasks",
|
|
16041
16936
|
scope: "tasks",
|
|
16042
16937
|
configurable: false
|
|
@@ -16150,6 +17045,7 @@ const VIEWER_BLOCKED_PARENT_ACTIONS = /* @__PURE__ */ new Set([
|
|
|
16150
17045
|
"app.input.dequeue",
|
|
16151
17046
|
"app.permission.cycle",
|
|
16152
17047
|
"app.transcript.search",
|
|
17048
|
+
"app.transcript.search.view",
|
|
16153
17049
|
"app.visual.selectNext",
|
|
16154
17050
|
"app.visual.copySelected",
|
|
16155
17051
|
"app.visual.openSelected",
|
|
@@ -16826,7 +17722,6 @@ const SESSIONLESS_COMMANDS = /* @__PURE__ */ new Set([
|
|
|
16826
17722
|
"focus",
|
|
16827
17723
|
"footer",
|
|
16828
17724
|
"settings",
|
|
16829
|
-
"help",
|
|
16830
17725
|
"attach",
|
|
16831
17726
|
"image",
|
|
16832
17727
|
"login",
|
|
@@ -16843,13 +17738,56 @@ const SESSIONLESS_COMMANDS = /* @__PURE__ */ new Set([
|
|
|
16843
17738
|
"keybindings",
|
|
16844
17739
|
"plugins",
|
|
16845
17740
|
"web",
|
|
17741
|
+
"acp",
|
|
16846
17742
|
"quit",
|
|
16847
17743
|
"statusline",
|
|
16848
17744
|
"status",
|
|
16849
17745
|
"view-image",
|
|
16850
17746
|
"deliverables",
|
|
16851
17747
|
"reload-client",
|
|
16852
|
-
"schedule"
|
|
17748
|
+
"schedule",
|
|
17749
|
+
"queue"
|
|
17750
|
+
]);
|
|
17751
|
+
/**
|
|
17752
|
+
* Sessionless commands that are IMMEDIATE controls: they do not depend on the
|
|
17753
|
+
* Session identity a pending navigation will publish.
|
|
17754
|
+
*
|
|
17755
|
+
* - `/exit` / `/quit`: the user's quit must not wait for a navigation; a
|
|
17756
|
+
* stuck Workspace pre-selection would otherwise hang the slash exit.
|
|
17757
|
+
* - `/reload-client`: its safety decision reads the live facts synchronously
|
|
17758
|
+
* and must be made at request time. Deferring it past the transition would
|
|
17759
|
+
* re-judge the request after `pending` cleared and reload a Client the
|
|
17760
|
+
* in-flight-transition policy was refusing.
|
|
17761
|
+
*
|
|
17762
|
+
* The submission transition fence must never defer these behind an unsettled
|
|
17763
|
+
* navigation (it would change the control's decision point).
|
|
17764
|
+
*/
|
|
17765
|
+
const IMMEDIATE_SESSIONLESS_COMMANDS = /* @__PURE__ */ new Set([
|
|
17766
|
+
"exit",
|
|
17767
|
+
"quit",
|
|
17768
|
+
"reload-client"
|
|
17769
|
+
]);
|
|
17770
|
+
/**
|
|
17771
|
+
* Session-navigation entries whose SESSIONLESS local route is their OWN
|
|
17772
|
+
* admission: `/new`'s single-flight marker, the session-browser picker
|
|
17773
|
+
* (`/sessions`, `/resume`, `/search`) and the `/fork`/`/rewind` entries.
|
|
17774
|
+
*
|
|
17775
|
+
* The submission transition fence defers a sessionless-capable command until a
|
|
17776
|
+
* pending Session transition settles, so the route decision sees the settled
|
|
17777
|
+
* surface. These names are the navigation authority themselves and must run
|
|
17778
|
+
* IMMEDIATELY: their own guard answers the pending transition (a deferred
|
|
17779
|
+
* `/new` would no longer be the documented "already starting" refusal — it
|
|
17780
|
+
* would create a SECOND Session after the first settled), and their
|
|
17781
|
+
* sessionless effects (a picker, an explicit refusal) are visible without a
|
|
17782
|
+
* command card.
|
|
17783
|
+
*/
|
|
17784
|
+
const SESSION_NAVIGATION_COMMANDS = /* @__PURE__ */ new Set([
|
|
17785
|
+
"new",
|
|
17786
|
+
"sessions",
|
|
17787
|
+
"resume",
|
|
17788
|
+
"search",
|
|
17789
|
+
"fork",
|
|
17790
|
+
"rewind"
|
|
16853
17791
|
]);
|
|
16854
17792
|
/**
|
|
16855
17793
|
* The LOCAL-execute command set (PR5 v2 §1C-6 narrows its semantic role):
|
|
@@ -16882,7 +17820,6 @@ const LOCAL_COMMANDS = /* @__PURE__ */ new Set([
|
|
|
16882
17820
|
"focus",
|
|
16883
17821
|
"footer",
|
|
16884
17822
|
"fork",
|
|
16885
|
-
"help",
|
|
16886
17823
|
"attach",
|
|
16887
17824
|
"image",
|
|
16888
17825
|
"keybindings",
|
|
@@ -16909,11 +17846,13 @@ const LOCAL_COMMANDS = /* @__PURE__ */ new Set([
|
|
|
16909
17846
|
"transcript",
|
|
16910
17847
|
"yolo",
|
|
16911
17848
|
"web",
|
|
17849
|
+
"acp",
|
|
16912
17850
|
"view-image",
|
|
16913
17851
|
"deliverables",
|
|
16914
17852
|
"statusline",
|
|
16915
17853
|
"reload-client",
|
|
16916
|
-
"schedule"
|
|
17854
|
+
"schedule",
|
|
17855
|
+
"queue"
|
|
16917
17856
|
]);
|
|
16918
17857
|
/**
|
|
16919
17858
|
* The STATIC host-owned command catalog (P1-04): the ownership sets
|
|
@@ -17094,6 +18033,24 @@ function isPlainExitPrompt(text) {
|
|
|
17094
18033
|
return text.trim() === "exit";
|
|
17095
18034
|
}
|
|
17096
18035
|
/**
|
|
18036
|
+
* Classify one exit intent against the live authority facts. This is the ONE
|
|
18037
|
+
* exit classifier: Direct and daemon branches differ only in the final
|
|
18038
|
+
* destination, and an unknown activity is NEVER treated as idle (a daemon
|
|
18039
|
+
* Client must not detach as if nothing were running, and a Direct process
|
|
18040
|
+
* must not claim the in-process Host has nothing to retire).
|
|
18041
|
+
* @param input - the captured backend/presence/activity/entry facts.
|
|
18042
|
+
* @returns the single decision the exit-intent coordinator executes.
|
|
18043
|
+
*/
|
|
18044
|
+
function classifyExitIntent(input) {
|
|
18045
|
+
if (input.sessionPresence === "none") {
|
|
18046
|
+
if (input.activity !== "idle") return "show-unknown-choice";
|
|
18047
|
+
return input.currentBackend === "direct" ? "direct-exit" : "client-detach";
|
|
18048
|
+
}
|
|
18049
|
+
if (input.activity === "unknown") return "show-unknown-choice";
|
|
18050
|
+
if (input.activity === "working") return input.currentBackend === "direct" ? "show-direct-choice" : "show-daemon-choice";
|
|
18051
|
+
return input.currentBackend === "direct" ? "direct-exit" : "client-detach";
|
|
18052
|
+
}
|
|
18053
|
+
/**
|
|
17097
18054
|
* The TUI-local commands whose OWN handler performs no persistent Host write
|
|
17098
18055
|
* (they read/browse/stage locally, open a read-only panel, or are the reload
|
|
17099
18056
|
* command itself). Their execution never holds the accepted-command reload
|
|
@@ -17111,7 +18068,6 @@ const READ_ONLY_LOCAL_COMMANDS = /* @__PURE__ */ new Set([
|
|
|
17111
18068
|
"reload",
|
|
17112
18069
|
"exit",
|
|
17113
18070
|
"quit",
|
|
17114
|
-
"help",
|
|
17115
18071
|
"keybindings",
|
|
17116
18072
|
"copy",
|
|
17117
18073
|
"attach",
|
|
@@ -17985,6 +18941,42 @@ var AutocompleteRegistry = class {
|
|
|
17985
18941
|
};
|
|
17986
18942
|
//#endregion
|
|
17987
18943
|
//#region src/extension/internal/settings-registry.ts
|
|
18944
|
+
/** Whether one value is a JSON scalar a persisted choice may write. */
|
|
18945
|
+
function isPersistedScalar(value) {
|
|
18946
|
+
return value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value);
|
|
18947
|
+
}
|
|
18948
|
+
/** Validate and freeze one author-declared persisted descriptor. Every error
|
|
18949
|
+
* is a registration-time failure; the registry never repairs a declaration. */
|
|
18950
|
+
function persistedDescriptorOf(contribution) {
|
|
18951
|
+
const descriptor = contribution.persisted;
|
|
18952
|
+
if (descriptor === null || typeof descriptor !== "object") throw new Error("persisted settings row requires a persisted descriptor");
|
|
18953
|
+
if (contribution.values !== void 0 || contribution.onChange !== void 0) throw new Error("a persisted settings row cannot declare runtime values or onChange");
|
|
18954
|
+
const path = descriptor.path;
|
|
18955
|
+
if (!Array.isArray(path) || path.length === 0) throw new Error("persisted settings path must be a non-empty array");
|
|
18956
|
+
for (const segment of path) if (typeof segment !== "string" || segment === "") throw new Error("persisted settings path segments must be non-empty strings");
|
|
18957
|
+
const choices = descriptor.choices;
|
|
18958
|
+
if (!Array.isArray(choices) || choices.length === 0) throw new Error("persisted settings choices must be a non-empty array");
|
|
18959
|
+
const ids = /* @__PURE__ */ new Set();
|
|
18960
|
+
const frozenChoices = [];
|
|
18961
|
+
for (const choice of choices) {
|
|
18962
|
+
if (choice === null || typeof choice !== "object") throw new Error("persisted settings choices must be objects");
|
|
18963
|
+
if (typeof choice.id !== "string" || choice.id === "") throw new Error("persisted settings choice ids must be non-empty strings");
|
|
18964
|
+
if (ids.has(choice.id)) throw new Error(`duplicate persisted settings choice id "${choice.id}"`);
|
|
18965
|
+
ids.add(choice.id);
|
|
18966
|
+
if (choice.label !== void 0 && typeof choice.label !== "string") throw new Error(`persisted settings choice "${choice.id}" label must be a string`);
|
|
18967
|
+
if (choice.op === "set") {
|
|
18968
|
+
if (!isPersistedScalar(choice.value)) throw new Error(`persisted settings choice "${choice.id}" value must be a JSON scalar`);
|
|
18969
|
+
frozenChoices.push(Object.freeze({ ...choice }));
|
|
18970
|
+
} else if (choice.op === "unset") {
|
|
18971
|
+
if (Object.hasOwn(choice, "value")) throw new Error(`persisted settings choice "${choice.id}" is unset and must not carry a value`);
|
|
18972
|
+
frozenChoices.push(Object.freeze({ ...choice }));
|
|
18973
|
+
} else throw new Error("persisted settings choice has an unsupported op");
|
|
18974
|
+
}
|
|
18975
|
+
return Object.freeze({
|
|
18976
|
+
path: Object.freeze([...path]),
|
|
18977
|
+
choices: Object.freeze(frozenChoices)
|
|
18978
|
+
});
|
|
18979
|
+
}
|
|
17988
18980
|
/**
|
|
17989
18981
|
* The settings registry. One instance backs the runner; the extension
|
|
17990
18982
|
* service exposes registration; the runner asks {@link rows} when
|
|
@@ -18008,18 +19000,21 @@ var SettingsRegistry = class {
|
|
|
18008
19000
|
register(contribution, owner) {
|
|
18009
19001
|
if (this.records.has(contribution.id)) throw new Error(`duplicate settings row id "${contribution.id}"`);
|
|
18010
19002
|
if (contribution.label === "") throw new Error("settings row label must not be empty");
|
|
19003
|
+
const persisted = contribution.persisted === void 0 ? void 0 : persistedDescriptorOf(contribution);
|
|
18011
19004
|
this.nextRegistrationToken += 1;
|
|
18012
19005
|
const record = {
|
|
18013
19006
|
id: contribution.id,
|
|
18014
19007
|
label: contribution.label,
|
|
18015
19008
|
description: contribution.description,
|
|
18016
|
-
values: contribution.values ?? [],
|
|
19009
|
+
values: persisted === void 0 ? contribution.values ?? [] : persisted.choices.map((choice) => choice.id),
|
|
18017
19010
|
order: contribution.order ?? 0,
|
|
18018
19011
|
owner,
|
|
19012
|
+
mode: persisted === void 0 ? "runtime" : "persisted",
|
|
19013
|
+
persisted,
|
|
18019
19014
|
registrationToken: this.nextRegistrationToken,
|
|
18020
19015
|
currentValue: contribution.currentValue,
|
|
18021
19016
|
applyEpoch: 0,
|
|
18022
|
-
onChange: contribution.onChange,
|
|
19017
|
+
onChange: persisted === void 0 ? contribution.onChange : void 0,
|
|
18023
19018
|
disposed: false
|
|
18024
19019
|
};
|
|
18025
19020
|
this.records.set(contribution.id, record);
|
|
@@ -18099,6 +19094,7 @@ var SettingsRegistry = class {
|
|
|
18099
19094
|
async applyInternal(id, value) {
|
|
18100
19095
|
const record = this.records.get(id);
|
|
18101
19096
|
if (record === void 0 || record.disposed) return "gone";
|
|
19097
|
+
if (record.mode === "persisted") return "rejected";
|
|
18102
19098
|
const epoch = record.applyEpoch + 1;
|
|
18103
19099
|
record.applyEpoch = epoch;
|
|
18104
19100
|
const onChange = record.onChange;
|
|
@@ -18126,7 +19122,9 @@ var SettingsRegistry = class {
|
|
|
18126
19122
|
for (const record of this.records.values()) if (!record.disposed) return true;
|
|
18127
19123
|
return false;
|
|
18128
19124
|
}
|
|
18129
|
-
/** An immutable snapshot (Plugin Manager diagnostics).
|
|
19125
|
+
/** An immutable snapshot (Plugin Manager diagnostics). Runtime-only rows
|
|
19126
|
+
* keep their original seven facts; a persisted row adds its frozen mode
|
|
19127
|
+
* and author descriptor. */
|
|
18130
19128
|
snapshot() {
|
|
18131
19129
|
return {
|
|
18132
19130
|
rows: this.rows().map((record) => ({
|
|
@@ -18136,7 +19134,11 @@ var SettingsRegistry = class {
|
|
|
18136
19134
|
currentValue: record.currentValue,
|
|
18137
19135
|
values: record.values,
|
|
18138
19136
|
order: record.order,
|
|
18139
|
-
owner: record.owner
|
|
19137
|
+
owner: record.owner,
|
|
19138
|
+
...record.mode === "persisted" ? {
|
|
19139
|
+
mode: "persisted",
|
|
19140
|
+
persisted: record.persisted
|
|
19141
|
+
} : {}
|
|
18140
19142
|
})),
|
|
18141
19143
|
revision: this.revision
|
|
18142
19144
|
};
|
|
@@ -18333,6 +19335,13 @@ const RESERVED_HOST_KEYS = [
|
|
|
18333
19335
|
shift: false,
|
|
18334
19336
|
super: false
|
|
18335
19337
|
},
|
|
19338
|
+
{
|
|
19339
|
+
key: "i",
|
|
19340
|
+
ctrl: false,
|
|
19341
|
+
alt: true,
|
|
19342
|
+
shift: false,
|
|
19343
|
+
super: false
|
|
19344
|
+
},
|
|
18336
19345
|
{
|
|
18337
19346
|
key: "k",
|
|
18338
19347
|
ctrl: false,
|
|
@@ -20190,4 +21199,4 @@ function apply(ctx) {
|
|
|
20190
21199
|
new PiTuiExtensionServiceImpl(ctx, packageVersion(), () => {}, HOST_COMMAND_CATALOG);
|
|
20191
21200
|
}
|
|
20192
21201
|
//#endregion
|
|
20193
|
-
export {
|
|
21202
|
+
export { decodeKittyPrintable as $, canonicalizeKeyId as A, Image as B, DEFAULT_LEADER_TIMEOUT_MS as C, hideFooterRefInTsp as Ct, parseUserKeybindings as D, stripControlChars as Dt, isTerminalAmbiguousKeyId as E, resolveCommandFooterFallback as Et, CURSOR_MARKER as F, ProcessTerminal as G, Key as H, CombinedAutocompleteProvider as I, Spacer as J, ScrollView as K, Container as L, isTextProducingKeyId as M, isValidKeyId as N, APP_KEYBINDINGS as O, AltScreenSearchIndex as P, VStack as Q, Editor as R, normalizeInputEvent as S, defaultHideInTsp as St, isPhysicalEscapeAction as T, parseFooterLayout as Tt, Markdown as U, Input as V, MouseRegion as W, TuiAltScreen as X, Text as Y, TuiMainScreen as Z, isLocalCommandLine as _, sliceByColumn as _t, API_VERSION as a, getCellDimensions as at, normalizeSkillInvocation as b, visibleWidth as bt, HOST_COMMAND_CATALOG as c, getOsc8LinkAtColumn as ct, SESSIONLESS_COMMANDS as d, isKeyRelease as dt, decodePrintableKey as et, SESSION_NAVIGATION_COMMANDS as f, isKeyRepeat as ft, isBareCommandLine as g, renderFakeCursor as gt, commandIsLocalForAttachments as h, registerKittyImageMetadata as ht, PI_TUI_EXTENSIONS_SERVICE as i, getCapabilities as it, isRuntimeBindableKeyId as j, VIEWER_BLOCKED_PARENT_ACTIONS as k, IMMEDIATE_SESSIONLESS_COMMANDS as l, imageFallback as lt, classifyExitIntent as m, parseKey as mt, inject as n, findAltScreenSearchMatches as nt, describeKey as o, getGraphemeSegmenter as ot, classifyCommandLine as p, matchesKey as pt, SettingsList as q, name as r, fuzzyFilter as rt, InvalidateBatcher as s, getKeybindings as st, apply as t, dispatchMouseEvent as tt, LOCAL_COMMANDS as u, isFocusable as ut, isPlainExitPrompt as v, stripTerminalSequences as vt, isEditorSubmitPreSubmitKey as w, isFooterLayout as wt, shouldConsumeAdvertisedMiss as x, wrapTextWithAnsi as xt, localCommandMayWrite as y, truncateToWidth as yt, HStack as z };
|