agent.libx.js 0.89.3 → 0.89.4
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/dist/cli.js +134 -2
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -4639,6 +4639,137 @@ function completePath(listDir, ref) {
|
|
|
4639
4639
|
|
|
4640
4640
|
// cli/lineEditor.ts
|
|
4641
4641
|
import { emitKeypressEvents } from "readline";
|
|
4642
|
+
|
|
4643
|
+
// cli/bidi.ts
|
|
4644
|
+
var RTL_RE = /[--ۿ܀-ݏݐ-ݿࢠ-ࣿיִ-﷿ﹰ-]/;
|
|
4645
|
+
var needsBidi = (s) => RTL_RE.test(s);
|
|
4646
|
+
function classify(c) {
|
|
4647
|
+
if (c >= 1425 && c <= 1469) return "NSM";
|
|
4648
|
+
if (c === 1471 || c === 1473 || c === 1474 || c === 1476 || c === 1477 || c === 1479) return "NSM";
|
|
4649
|
+
if (c >= 1424 && c <= 1535 || c >= 64285 && c <= 64335) return "R";
|
|
4650
|
+
if (c >= 1632 && c <= 1641 || c >= 1776 && c <= 1785) return "AN";
|
|
4651
|
+
if (c >= 1536 && c <= 1791 || c >= 1872 && c <= 1919 || c >= 2208 && c <= 2303 || c >= 64336 && c <= 65023 || c >= 65136 && c <= 65279) return "AL";
|
|
4652
|
+
if (c >= 48 && c <= 57) return "EN";
|
|
4653
|
+
if (c === 43 || c === 45) return "ES";
|
|
4654
|
+
if (c === 35 || c === 36 || c === 37 || c >= 162 && c <= 165) return "ET";
|
|
4655
|
+
if (c === 44 || c === 46 || c === 58 || c === 47 || c === 160) return "CS";
|
|
4656
|
+
if (c === 32 || c === 9 || c === 11 || c === 12) return "WS";
|
|
4657
|
+
if (c >= 33 && c <= 47 || c >= 58 && c <= 64 || c >= 91 && c <= 96 || c >= 123 && c <= 126) return "ON";
|
|
4658
|
+
return "L";
|
|
4659
|
+
}
|
|
4660
|
+
function baseLevel(types) {
|
|
4661
|
+
for (const t of types) {
|
|
4662
|
+
if (t === "L") return 0;
|
|
4663
|
+
if (t === "R" || t === "AL") return 1;
|
|
4664
|
+
}
|
|
4665
|
+
return 0;
|
|
4666
|
+
}
|
|
4667
|
+
function resolveWeak(t, baseDir) {
|
|
4668
|
+
const n = t.length;
|
|
4669
|
+
for (let i = 0; i < n; i++) if (t[i] === "NSM") t[i] = i > 0 ? t[i - 1] : baseDir;
|
|
4670
|
+
for (let i = 0; i < n; i++) if (t[i] === "EN") {
|
|
4671
|
+
for (let j = i - 1; j >= 0; j--) if (t[j] === "L" || t[j] === "R" || t[j] === "AL") {
|
|
4672
|
+
if (t[j] === "AL") t[i] = "AN";
|
|
4673
|
+
break;
|
|
4674
|
+
}
|
|
4675
|
+
}
|
|
4676
|
+
for (let i = 0; i < n; i++) if (t[i] === "AL") t[i] = "R";
|
|
4677
|
+
for (let i = 1; i < n - 1; i++) {
|
|
4678
|
+
if (t[i] === "ES" && t[i - 1] === "EN" && t[i + 1] === "EN") t[i] = "EN";
|
|
4679
|
+
else if (t[i] === "CS" && t[i - 1] === "EN" && t[i + 1] === "EN") t[i] = "EN";
|
|
4680
|
+
else if (t[i] === "CS" && t[i - 1] === "AN" && t[i + 1] === "AN") t[i] = "AN";
|
|
4681
|
+
}
|
|
4682
|
+
for (let i = 0; i < n; i++) if (t[i] === "ET") {
|
|
4683
|
+
let j = i;
|
|
4684
|
+
while (j < n && t[j] === "ET") j++;
|
|
4685
|
+
if (i > 0 && t[i - 1] === "EN" || j < n && t[j] === "EN") for (let k = i; k < j; k++) t[k] = "EN";
|
|
4686
|
+
i = j - 1;
|
|
4687
|
+
}
|
|
4688
|
+
for (let i = 0; i < n; i++) if (t[i] === "ES" || t[i] === "ET" || t[i] === "CS") t[i] = "ON";
|
|
4689
|
+
for (let i = 0; i < n; i++) if (t[i] === "EN") {
|
|
4690
|
+
let strong = baseDir;
|
|
4691
|
+
for (let j = i - 1; j >= 0; j--) if (t[j] === "L" || t[j] === "R") {
|
|
4692
|
+
strong = t[j];
|
|
4693
|
+
break;
|
|
4694
|
+
}
|
|
4695
|
+
if (strong === "L") t[i] = "L";
|
|
4696
|
+
}
|
|
4697
|
+
return t;
|
|
4698
|
+
}
|
|
4699
|
+
function resolveNeutral(t, baseDir) {
|
|
4700
|
+
const n = t.length;
|
|
4701
|
+
const strong = (x) => x === "L" ? "L" : x === "R" || x === "EN" || x === "AN" ? "R" : void 0;
|
|
4702
|
+
for (let i = 0; i < n; i++) if (t[i] === "ON" || t[i] === "WS") {
|
|
4703
|
+
let j = i;
|
|
4704
|
+
while (j < n && (t[j] === "ON" || t[j] === "WS")) j++;
|
|
4705
|
+
const prev = i > 0 ? strong(t[i - 1]) : baseDir;
|
|
4706
|
+
const next = j < n ? strong(t[j]) : baseDir;
|
|
4707
|
+
const dir = prev && next && prev === next ? prev : baseDir;
|
|
4708
|
+
for (let k = i; k < j; k++) t[k] = dir;
|
|
4709
|
+
i = j - 1;
|
|
4710
|
+
}
|
|
4711
|
+
return t;
|
|
4712
|
+
}
|
|
4713
|
+
function implicitLevels(t, e) {
|
|
4714
|
+
return t.map((x) => e % 2 === 0 ? x === "R" ? e + 1 : x === "EN" || x === "AN" ? e + 2 : e : x === "L" || x === "EN" || x === "AN" ? e + 1 : e);
|
|
4715
|
+
}
|
|
4716
|
+
function reorder(levels) {
|
|
4717
|
+
const n = levels.length;
|
|
4718
|
+
const order = Array.from({ length: n }, (_, i) => i);
|
|
4719
|
+
let highest = 0, lowestOdd = Infinity;
|
|
4720
|
+
for (const l of levels) {
|
|
4721
|
+
if (l > highest) highest = l;
|
|
4722
|
+
if (l % 2 && l < lowestOdd) lowestOdd = l;
|
|
4723
|
+
}
|
|
4724
|
+
for (let lvl = highest; lvl >= lowestOdd; lvl--) {
|
|
4725
|
+
let i = 0;
|
|
4726
|
+
while (i < n) {
|
|
4727
|
+
if (levels[i] >= lvl) {
|
|
4728
|
+
let j = i;
|
|
4729
|
+
while (j < n && levels[j] >= lvl) j++;
|
|
4730
|
+
for (let a = i, b = j - 1; a < b; a++, b--) {
|
|
4731
|
+
const tmp = order[a];
|
|
4732
|
+
order[a] = order[b];
|
|
4733
|
+
order[b] = tmp;
|
|
4734
|
+
}
|
|
4735
|
+
i = j;
|
|
4736
|
+
} else i++;
|
|
4737
|
+
}
|
|
4738
|
+
}
|
|
4739
|
+
return order;
|
|
4740
|
+
}
|
|
4741
|
+
function bidiLine(line) {
|
|
4742
|
+
const n = line.length;
|
|
4743
|
+
if (n === 0) return { visual: "", caret: [0] };
|
|
4744
|
+
const types = Array.from({ length: n }, (_, i) => classify(line.charCodeAt(i)));
|
|
4745
|
+
const e = baseLevel(types);
|
|
4746
|
+
const baseDir = e % 2 ? "R" : "L";
|
|
4747
|
+
const levels = implicitLevels(resolveNeutral(resolveWeak(types, baseDir), baseDir), e);
|
|
4748
|
+
const order = reorder(levels);
|
|
4749
|
+
const logToVis = new Array(n);
|
|
4750
|
+
for (let v = 0; v < n; v++) logToVis[order[v]] = v;
|
|
4751
|
+
const caret = new Array(n + 1);
|
|
4752
|
+
for (let c = 0; c < n; c++) caret[c] = levels[c] % 2 === 0 ? logToVis[c] : logToVis[c] + 1;
|
|
4753
|
+
caret[n] = levels[n - 1] % 2 === 0 ? logToVis[n - 1] + 1 : logToVis[n - 1];
|
|
4754
|
+
const visual = order.map((li) => line[li]).join("");
|
|
4755
|
+
return { visual, caret };
|
|
4756
|
+
}
|
|
4757
|
+
function applyBidi(buf, cursor) {
|
|
4758
|
+
if (!needsBidi(buf)) return { text: buf, cursor };
|
|
4759
|
+
const lines = buf.split("\n");
|
|
4760
|
+
const out = [];
|
|
4761
|
+
let visCursor = cursor, logBase = 0, visBase = 0;
|
|
4762
|
+
for (const line of lines) {
|
|
4763
|
+
const { visual, caret } = bidiLine(line);
|
|
4764
|
+
out.push(visual);
|
|
4765
|
+
if (cursor >= logBase && cursor <= logBase + line.length) visCursor = visBase + caret[cursor - logBase];
|
|
4766
|
+
logBase += line.length + 1;
|
|
4767
|
+
visBase += visual.length + 1;
|
|
4768
|
+
}
|
|
4769
|
+
return { text: out.join("\n"), cursor: visCursor };
|
|
4770
|
+
}
|
|
4771
|
+
|
|
4772
|
+
// cli/lineEditor.ts
|
|
4642
4773
|
var visibleWidth = (s) => s.replace(/\x1b\[[0-9;]*m/g, "").length;
|
|
4643
4774
|
var isPrintable = (str) => !!str && !/[\x00-\x1f\x7f]/.test(str);
|
|
4644
4775
|
var EditorState = class _EditorState {
|
|
@@ -5210,8 +5341,9 @@ function createLineEditor(out) {
|
|
|
5210
5341
|
const prompt = s.searching ? dim2(`(${s.searchMiss ? "failing " : ""}reverse-i-search)\`${s.searchQuery}': `) : mode ? COLOR[mode.name](`${mode.pfx} ${mode.name} \u203A `) : vimTag + promptArg;
|
|
5211
5342
|
if (curRow > 0) out.write(`\x1B[${curRow}A`);
|
|
5212
5343
|
out.write("\r\x1B[J");
|
|
5213
|
-
const
|
|
5214
|
-
const
|
|
5344
|
+
const rawBuf = mode ? s.buf.slice(mode.pfx.length) : s.buf;
|
|
5345
|
+
const rawCursor = mode ? Math.max(0, s.cursor - mode.pfx.length) : s.cursor;
|
|
5346
|
+
const { text: viewBuf, cursor: viewCursor } = applyBidi(rawBuf, rawCursor);
|
|
5215
5347
|
const { rows, cursorRow, cursorCol } = wrapLayout(visibleWidth(prompt), viewBuf, viewCursor, cols);
|
|
5216
5348
|
const ghost = !mode && !s.searching ? s.ghost() : "";
|
|
5217
5349
|
const ghostFits = ghost && rows.length === 1 && visibleWidth(prompt) + viewBuf.length + ghost.length < cols;
|