@bismawy/pi-arnative 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/extensions/arnative.ts +75 -4
- package/extensions/tools.ts +228 -15
- package/lib/preset-store.ts +3 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.15.0] - 2026-11-19
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
- **Side-by-side `edit` diff view (`Before │ After`) with intra-line highlights and `/arnative` toggle.** Expanded `edit` tool boxes render removed and added lines in two aligned columns at terminal inner widths >= 50 columns (with a `─┼─` header separator, stripped `+`/`-` prefixes, and `inverse` highlighting on changed tokens), falling back to unified diff on narrower terminals. Added `/arnative` → **Appearance** → **Diffs** (`Split` default / `Unified`) with live preview saved to `config.json` (`editDiff`) (`extensions/tools.ts`, `extensions/arnative.ts`, `lib/preset-store.ts`).
|
|
9
|
+
|
|
5
10
|
## [0.14.0] - 2026-11-19
|
|
6
11
|
|
|
7
12
|
### Added
|
package/extensions/arnative.ts
CHANGED
|
@@ -24,7 +24,8 @@ import {
|
|
|
24
24
|
setSpinnerGradient,
|
|
25
25
|
setSpinnerPreset,
|
|
26
26
|
} from "./animations.ts";
|
|
27
|
-
import { CHATBOX_DIALOG_KEY, CHATBOX_PRESET_KEY, CHATBOX_PROMPT_KEY, FOOTER_COST_KEY, FOOTER_PRESET_KEY, HEADER_PRESET_KEY, BUDGET_DAY_KEY, BUDGET_ENFORCE_KEY, BUDGET_MONTH_KEY, PAYLOAD_LIMIT_KEY, RENDER_CACHE_KEY, ensureChoices } from "../lib/preset-store.ts";
|
|
27
|
+
import { CHATBOX_DIALOG_KEY, CHATBOX_PRESET_KEY, CHATBOX_PROMPT_KEY, EDIT_DIFF_KEY, FOOTER_COST_KEY, FOOTER_PRESET_KEY, HEADER_PRESET_KEY, BUDGET_DAY_KEY, BUDGET_ENFORCE_KEY, BUDGET_MONTH_KEY, PAYLOAD_LIMIT_KEY, RENDER_CACHE_KEY, ensureChoices } from "../lib/preset-store.ts";
|
|
28
|
+
import { EDIT_DIFF_CHOICES, activeEditDiff, setEditDiff, type EditDiffMode } from "./tools.ts";
|
|
28
29
|
import { CHATBOX_DIALOGS, CHATBOX_PRESETS, CHATBOX_PROMPTS, DEFAULT_CHATBOX_DIALOG, FOOTER_PRESETS, activeChatboxDialog, activeChatboxPreset, activeChatboxPrompt, activeFooterCost, activeFooterPreset, nextChatboxDialog, nextChatboxPrompt, setChatboxDialog, setChatboxPreset, setChatboxPrompt, setFooterCost, setFooterPreset, type ChatboxPreset, type FooterPreset } from "./footer.ts";
|
|
29
30
|
import { activeBudgetDay, activeBudgetEnforce, activeBudgetMonth, openBudget } from "./budget.ts";
|
|
30
31
|
import { HEADER_PRESETS, activeHeaderPreset, setHeaderPreset, type HeaderPreset } from "./section-headers.ts";
|
|
@@ -66,7 +67,7 @@ export interface MenuCategory {
|
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
export const MENU_CATEGORIES: readonly MenuCategory[] = [
|
|
69
|
-
{ label: "Appearance", description: "themes, headers, footers, chatbox, animations" },
|
|
70
|
+
{ label: "Appearance", description: "themes, headers, footers, chatbox, animations, diffs" },
|
|
70
71
|
{ label: "Performance", description: "auto-compact, render cache, payload limit" },
|
|
71
72
|
{ label: "Models", description: "custom providers, model heal" },
|
|
72
73
|
{ label: "Spend", description: "usage dashboard, budget caps" },
|
|
@@ -554,6 +555,66 @@ export function renderCacheRows(opened: RenderCacheChoice): ListRow[] {
|
|
|
554
555
|
return RENDER_CACHE_CHOICES.map((c) => ({ label: c, note: RENDER_CACHE_NOTES[c], chosen: c === opened }));
|
|
555
556
|
}
|
|
556
557
|
|
|
558
|
+
const DIFFS_PICKER_TEXT: ListPickerText = {
|
|
559
|
+
title: screenTitle("Diffs"),
|
|
560
|
+
description: "Selection previews live — side-by-side Before │ After or unified +/- diff.",
|
|
561
|
+
legend: LIST_LEGEND_LIVE,
|
|
562
|
+
};
|
|
563
|
+
|
|
564
|
+
const EDIT_DIFF_NOTES: Record<EditDiffMode, string> = {
|
|
565
|
+
Split: "side-by-side Before │ After columns (default)",
|
|
566
|
+
Unified: "single-column +/- diff, easier to copy-paste",
|
|
567
|
+
};
|
|
568
|
+
|
|
569
|
+
/** Rows for `/arnative` → Diffs: Split / Unified. */
|
|
570
|
+
export function diffRows(): ListRow[] {
|
|
571
|
+
return EDIT_DIFF_CHOICES.map((c) => ({
|
|
572
|
+
label: c,
|
|
573
|
+
note: EDIT_DIFF_NOTES[c],
|
|
574
|
+
}));
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
const openDiffs = async (ctx: ExtensionCommandContext): Promise<boolean | void> => {
|
|
578
|
+
const opened = activeEditDiff();
|
|
579
|
+
|
|
580
|
+
if (ctx.mode !== "tui") {
|
|
581
|
+
const labels = EDIT_DIFF_CHOICES.map((c) => (c === opened ? `${c} ✓` : c));
|
|
582
|
+
const pick = await ctx.ui.select(DIFFS_PICKER_TEXT.title, labels);
|
|
583
|
+
if (pick === undefined) return;
|
|
584
|
+
const choice = EDIT_DIFF_CHOICES[labels.indexOf(pick)]!;
|
|
585
|
+
setEditDiff(choice);
|
|
586
|
+
ctx.ui.notify(`[arnative] Diffs: ${choice}`, "info");
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
const goBack = await ctx.ui.custom<boolean>((tui, theme, _kb, done) => {
|
|
591
|
+
const picker = new ListPicker(
|
|
592
|
+
theme,
|
|
593
|
+
diffRows(),
|
|
594
|
+
opened,
|
|
595
|
+
{
|
|
596
|
+
preview: (name) => setEditDiff(name as EditDiffMode),
|
|
597
|
+
revert: () => setEditDiff(opened),
|
|
598
|
+
done: () => {
|
|
599
|
+
announce(ctx.ui, `Diffs: ${activeEditDiff()}.`);
|
|
600
|
+
done(false);
|
|
601
|
+
},
|
|
602
|
+
cancel: () => done(false),
|
|
603
|
+
back: () => {
|
|
604
|
+
if (activeEditDiff() !== opened) setEditDiff(opened);
|
|
605
|
+
done(true);
|
|
606
|
+
},
|
|
607
|
+
requestRender: () => tui.requestRender(),
|
|
608
|
+
},
|
|
609
|
+
DIFFS_PICKER_TEXT,
|
|
610
|
+
true,
|
|
611
|
+
ctx.thinkingLevel,
|
|
612
|
+
);
|
|
613
|
+
return picker;
|
|
614
|
+
});
|
|
615
|
+
return goBack === true;
|
|
616
|
+
};
|
|
617
|
+
|
|
557
618
|
const openRenderCache = async (ctx: ExtensionCommandContext): Promise<boolean | void> => {
|
|
558
619
|
const opened = activeRenderCache();
|
|
559
620
|
|
|
@@ -760,6 +821,13 @@ export const MENUS: ArnativeMenu[] = [
|
|
|
760
821
|
group: "Appearance",
|
|
761
822
|
open: openAnimations,
|
|
762
823
|
},
|
|
824
|
+
{
|
|
825
|
+
value: "diffs",
|
|
826
|
+
label: "Diffs",
|
|
827
|
+
description: "side-by-side Before/After or unified diff",
|
|
828
|
+
group: "Appearance",
|
|
829
|
+
open: openDiffs,
|
|
830
|
+
},
|
|
763
831
|
{
|
|
764
832
|
value: "compact",
|
|
765
833
|
label: "Auto-compact",
|
|
@@ -957,6 +1025,7 @@ export function recordProfile(): void {
|
|
|
957
1025
|
[CHATBOX_DIALOG_KEY]: activeChatboxDialog(),
|
|
958
1026
|
[SPINNER_PRESET_KEY]: activeSpinnerPreset(),
|
|
959
1027
|
[SPINNER_GRADIENT_KEY]: activeSpinnerGradient() ? "on" : "off",
|
|
1028
|
+
[EDIT_DIFF_KEY]: activeEditDiff(),
|
|
960
1029
|
[AUTO_COMPACT_KEY]: activeAutoCompact(),
|
|
961
1030
|
[PAYLOAD_LIMIT_KEY]: savedPayloadLimit(),
|
|
962
1031
|
[MODEL_HEAL_KEY]: activeModelHeal(),
|
|
@@ -1001,7 +1070,7 @@ if (isMain(import.meta.url)) {
|
|
|
1001
1070
|
assert(MENU_DESC === "Themes, headers, footers, chatbox, animations, auto-compact, render, payload, providers, usage, budget", `the menu description is the pinned string, got ${MENU_DESC}`);
|
|
1002
1071
|
// Every menu row is reachable and the description names them all, so a new screen cannot
|
|
1003
1072
|
// be added to MENUS and forgotten in the copy a user reads first.
|
|
1004
|
-
assert(MENUS.length ===
|
|
1073
|
+
assert(MENUS.length === 13, "thirteen settings screens");
|
|
1005
1074
|
{
|
|
1006
1075
|
const catRows = menuRows([...MENU_CATEGORIES]);
|
|
1007
1076
|
assert(catRows.map((r) => r.label).join(",") === "Appearance,Performance,Models,Spend", "root menu lists the four categories in order");
|
|
@@ -1015,6 +1084,8 @@ if (isMain(import.meta.url)) {
|
|
|
1015
1084
|
const rc = renderCacheRows("On");
|
|
1016
1085
|
assert(rc.map((r) => r.label).join(",") === "On,Off", "Render cache rows: On then Off");
|
|
1017
1086
|
assert(rc.filter((r) => r.chosen).map((r) => r.label).join(",") === "On", "Render cache marks only the saved mode");
|
|
1087
|
+
const dRows = diffRows();
|
|
1088
|
+
assert(dRows.map((r) => r.label).join(",") === "Split,Unified", "Diffs rows: Split then Unified");
|
|
1018
1089
|
const pl = payloadLimitRows("16 MB");
|
|
1019
1090
|
assert(pl.map((r) => r.label).join(",") === "Off,1 MB,4 MB,8 MB,16 MB,32 MB,Custom", "Payload limit rows list presets then Custom");
|
|
1020
1091
|
assert(pl.filter((r) => r.chosen).map((r) => r.label).join(",") === "16 MB", "Payload limit marks the active preset");
|
|
@@ -1022,7 +1093,7 @@ if (isMain(import.meta.url)) {
|
|
|
1022
1093
|
assert(plCustom.filter((r) => r.chosen).map((r) => r.label).join(",") === "Custom", "Payload limit marks Custom when a non-preset MB is active");
|
|
1023
1094
|
assert(plCustom[plCustom.length - 1]!.note!.includes("11 MB"), "Custom row displays the active custom MB");
|
|
1024
1095
|
}
|
|
1025
|
-
for (const label of ["Themes", "Headers", "Footers", "Chatbox", "Animations", "Auto-compact", "Render cache", "Payload limit", "Providers", "Usage", "Budget"]) {
|
|
1096
|
+
for (const label of ["Themes", "Headers", "Footers", "Chatbox", "Animations", "Diffs", "Auto-compact", "Render cache", "Payload limit", "Providers", "Usage", "Budget"]) {
|
|
1026
1097
|
assert(MENUS.some((m) => m.label === label), `MENUS carries the ${label} screen`);
|
|
1027
1098
|
}
|
|
1028
1099
|
assert(/^Settings - Arnative/.test(MENU_TITLE), "title follows `<setting> - <extension>`");
|
package/extensions/tools.ts
CHANGED
|
@@ -37,14 +37,18 @@ import {
|
|
|
37
37
|
ToolExecutionComponent,
|
|
38
38
|
} from "@earendil-works/pi-coding-agent";
|
|
39
39
|
import { Markdown, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
40
|
-
import {
|
|
40
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
41
|
+
import { homedir, tmpdir } from "node:os";
|
|
42
|
+
import { join } from "node:path";
|
|
41
43
|
import { inSpans, renderBoxLines as box, type TextSpan, textSpans } from "../lib/box.ts";
|
|
42
44
|
import { getActiveTheme, stripAnsi, softSecondaryOf } from "../lib/ansi.ts";
|
|
43
45
|
import { actionWord } from "../lib/todos.ts";
|
|
46
|
+
import { EDIT_DIFF_KEY, loadChoice, resetPresetCache, saveChoice } from "../lib/preset-store.ts";
|
|
47
|
+
import { clearRenderCache } from "./render-cache.ts";
|
|
44
48
|
import { assert, isMain } from "../lib/check.ts";
|
|
45
49
|
import { markPatched, originalOf } from "../lib/patch.ts";
|
|
46
50
|
|
|
47
|
-
type Theme = { fg(color: string, text: string): string; bg?(color: string, text: string): string };
|
|
51
|
+
type Theme = { fg(color: string, text: string): string; bg?(color: string, text: string): string; inverse?(text: string): string };
|
|
48
52
|
type TResult = { content: Array<{ type: string; text?: string }>; isError?: boolean; details?: any };
|
|
49
53
|
type TCtx = { isError?: boolean; toolCallId?: string; args?: any; state?: Record<string, unknown>; durationMs?: number };
|
|
50
54
|
type Res = (r: TResult, th: Theme, soft: (s: string) => string, isErr: boolean, expanded: boolean) => string;
|
|
@@ -881,7 +885,7 @@ function minimal(
|
|
|
881
885
|
name: (th: Theme, soft: (s: string) => string) => string,
|
|
882
886
|
call: (a: any, th: Theme, soft: (s: string) => string, expanded: boolean) => string,
|
|
883
887
|
res: Res = resText,
|
|
884
|
-
full: (r: TResult, th: Theme) => string[] = fullText,
|
|
888
|
+
full: (r: TResult, th: Theme, inner: number) => string[] = fullText,
|
|
885
889
|
): void {
|
|
886
890
|
OWN_BOX.add(String(tool.name ?? ""));
|
|
887
891
|
pi.registerTool({
|
|
@@ -950,7 +954,7 @@ function minimal(
|
|
|
950
954
|
label,
|
|
951
955
|
);
|
|
952
956
|
const resLine = res(result, theme, soft, isErr, expanded);
|
|
953
|
-
if (expanded) rows.push(...full(result, theme));
|
|
957
|
+
if (expanded) rows.push(...full(result, theme, inner));
|
|
954
958
|
else if (resLine) rows.push(oneRow(resLine, inner));
|
|
955
959
|
return box(theme, width, rows);
|
|
956
960
|
});
|
|
@@ -1080,20 +1084,195 @@ function arnativeTools(pi: ExtensionAPI) {
|
|
|
1080
1084
|
}
|
|
1081
1085
|
return `${resHead(th)} ${th.fg("toolDiffAdded", `+${add}`)} / ${th.fg("toolDiffRemoved", `-${del}`)}`;
|
|
1082
1086
|
},
|
|
1083
|
-
(r, th) =>
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1087
|
+
(r, th, inner) => formatEditDiff(r, th, inner),
|
|
1088
|
+
);
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
const EDIT_DIFF_CONFIG_KEY = Symbol.for("pi-arnative.editDiff");
|
|
1092
|
+
const SPLIT_DIFF_MIN_WIDTH = 50;
|
|
1093
|
+
const INTRA_LINE_MAX_TOKENS = 200;
|
|
1094
|
+
|
|
1095
|
+
export type EditDiffMode = "Split" | "Unified";
|
|
1096
|
+
export const EDIT_DIFF_CHOICES: readonly EditDiffMode[] = ["Split", "Unified"];
|
|
1097
|
+
|
|
1098
|
+
export function activeEditDiff(): EditDiffMode {
|
|
1099
|
+
const stored =
|
|
1100
|
+
(globalThis as Record<symbol, unknown>)[EDIT_DIFF_CONFIG_KEY] ??
|
|
1101
|
+
loadChoice(EDIT_DIFF_KEY, EDIT_DIFF_CHOICES);
|
|
1102
|
+
return EDIT_DIFF_CHOICES.includes(stored as EditDiffMode)
|
|
1103
|
+
? (stored as EditDiffMode)
|
|
1104
|
+
: "Split";
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
export function setEditDiff(mode: EditDiffMode): void {
|
|
1108
|
+
(globalThis as Record<symbol, unknown>)[EDIT_DIFF_CONFIG_KEY] = mode;
|
|
1109
|
+
saveChoice(EDIT_DIFF_KEY, mode);
|
|
1110
|
+
clearRenderCache();
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
type DiffSide = { styled: string } | null;
|
|
1114
|
+
|
|
1115
|
+
function unifiedDiffLines(diff: string, th: Theme): string[] {
|
|
1116
|
+
return diff.split("\n").map((l) =>
|
|
1117
|
+
l.startsWith("+") && !l.startsWith("+++")
|
|
1118
|
+
? th.fg("toolDiffAdded", l)
|
|
1119
|
+
: l.startsWith("-") && !l.startsWith("---")
|
|
1120
|
+
? th.fg("toolDiffRemoved", l)
|
|
1121
|
+
: th.fg("toolDiffContext", l),
|
|
1094
1122
|
);
|
|
1095
1123
|
}
|
|
1096
1124
|
|
|
1125
|
+
function tokenizeDiffLine(s: string): string[] {
|
|
1126
|
+
return s.match(/[A-Za-z0-9_]+|\s+|[^\sA-Za-z0-9_]/g) ?? [];
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
/**
|
|
1130
|
+
* Highlights changed tokens between paired old/new lines using `inverse`,
|
|
1131
|
+
* keeping leading indentation un-highlighted.
|
|
1132
|
+
*/
|
|
1133
|
+
function highlightLinePair(oldText: string, newText: string, th: Theme): { left: string; right: string } {
|
|
1134
|
+
const a = tokenizeDiffLine(oldText);
|
|
1135
|
+
const b = tokenizeDiffLine(newText);
|
|
1136
|
+
if (a.length === 0 || b.length === 0 || a.length > INTRA_LINE_MAX_TOKENS || b.length > INTRA_LINE_MAX_TOKENS) {
|
|
1137
|
+
return { left: th.fg("toolDiffRemoved", oldText), right: th.fg("toolDiffAdded", newText) };
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
const m = a.length;
|
|
1141
|
+
const n = b.length;
|
|
1142
|
+
const dp: Uint16Array[] = Array.from({ length: m + 1 }, () => new Uint16Array(n + 1));
|
|
1143
|
+
for (let i = m - 1; i >= 0; i--) {
|
|
1144
|
+
for (let j = n - 1; j >= 0; j--) {
|
|
1145
|
+
dp[i]![j] = a[i] === b[j] ? dp[i + 1]![j + 1]! + 1 : Math.max(dp[i + 1]![j]!, dp[i]![j + 1]!);
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
const inv = (s: string) => (th.inverse ? th.inverse(s) : `\x1b[7m${s}\x1b[27m`);
|
|
1150
|
+
let left = "";
|
|
1151
|
+
let right = "";
|
|
1152
|
+
let i = 0;
|
|
1153
|
+
let j = 0;
|
|
1154
|
+
let seenNonWsLeft = false;
|
|
1155
|
+
let seenNonWsRight = false;
|
|
1156
|
+
|
|
1157
|
+
const emitChanged = (tok: string, color: string, seenNonWs: boolean): [string, boolean] => {
|
|
1158
|
+
if (!seenNonWs && /^\s+$/.test(tok)) return [th.fg(color, tok), false];
|
|
1159
|
+
return [th.fg(color, inv(tok)), true];
|
|
1160
|
+
};
|
|
1161
|
+
|
|
1162
|
+
while (i < m && j < n) {
|
|
1163
|
+
if (a[i] === b[j]) {
|
|
1164
|
+
const tok = a[i]!;
|
|
1165
|
+
if (tok.trim()) {
|
|
1166
|
+
seenNonWsLeft = true;
|
|
1167
|
+
seenNonWsRight = true;
|
|
1168
|
+
}
|
|
1169
|
+
left += th.fg("toolDiffRemoved", tok);
|
|
1170
|
+
right += th.fg("toolDiffAdded", tok);
|
|
1171
|
+
i++;
|
|
1172
|
+
j++;
|
|
1173
|
+
} else if (dp[i + 1]![j]! >= dp[i]![j + 1]!) {
|
|
1174
|
+
const [chunk, seen] = emitChanged(a[i]!, "toolDiffRemoved", seenNonWsLeft);
|
|
1175
|
+
left += chunk;
|
|
1176
|
+
seenNonWsLeft = seen;
|
|
1177
|
+
i++;
|
|
1178
|
+
} else {
|
|
1179
|
+
const [chunk, seen] = emitChanged(b[j]!, "toolDiffAdded", seenNonWsRight);
|
|
1180
|
+
right += chunk;
|
|
1181
|
+
seenNonWsRight = seen;
|
|
1182
|
+
j++;
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
while (i < m) {
|
|
1186
|
+
const [chunk, seen] = emitChanged(a[i]!, "toolDiffRemoved", seenNonWsLeft);
|
|
1187
|
+
left += chunk;
|
|
1188
|
+
seenNonWsLeft = seen;
|
|
1189
|
+
i++;
|
|
1190
|
+
}
|
|
1191
|
+
while (j < n) {
|
|
1192
|
+
const [chunk, seen] = emitChanged(b[j]!, "toolDiffAdded", seenNonWsRight);
|
|
1193
|
+
right += chunk;
|
|
1194
|
+
seenNonWsRight = seen;
|
|
1195
|
+
j++;
|
|
1196
|
+
}
|
|
1197
|
+
return { left, right };
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
function wrapDiffCell(side: DiffSide, width: number): string[] {
|
|
1201
|
+
if (!side) return [""];
|
|
1202
|
+
const clean = side.styled.replace(/\t/g, " ");
|
|
1203
|
+
return clean === "" ? [""] : wrapTextWithAnsi(clean, width);
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
function renderSplitPair(left: DiffSide, right: DiffSide, leftW: number, rightW: number, sep: string): string[] {
|
|
1207
|
+
const leftLines = wrapDiffCell(left, leftW);
|
|
1208
|
+
const rightLines = wrapDiffCell(right, rightW);
|
|
1209
|
+
const count = Math.max(leftLines.length, rightLines.length);
|
|
1210
|
+
const rows: string[] = [];
|
|
1211
|
+
for (let i = 0; i < count; i++) {
|
|
1212
|
+
const l = leftLines[i] ?? "";
|
|
1213
|
+
const r = rightLines[i] ?? "";
|
|
1214
|
+
const pad = " ".repeat(Math.max(0, leftW - visibleWidth(l)));
|
|
1215
|
+
rows.push(`${l}${pad}${sep}${r}`);
|
|
1216
|
+
}
|
|
1217
|
+
return rows;
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
/**
|
|
1221
|
+
* Formats an `edit` diff side-by-side (Before | After) when the box inner width
|
|
1222
|
+
* is at least {@link SPLIT_DIFF_MIN_WIDTH}, falling back to unified diff on
|
|
1223
|
+
* narrow terminals or when `details.diff` is absent.
|
|
1224
|
+
*/
|
|
1225
|
+
export function formatEditDiff(r: TResult, th: Theme, inner: number, mode: EditDiffMode = activeEditDiff()): string[] {
|
|
1226
|
+
const diff: string = r.details?.diff ?? "";
|
|
1227
|
+
if (!diff) return fullText(r, th);
|
|
1228
|
+
if (mode === "Unified" || inner < SPLIT_DIFF_MIN_WIDTH) return unifiedDiffLines(diff, th);
|
|
1229
|
+
|
|
1230
|
+
const sep = th.fg("dim", " │ ");
|
|
1231
|
+
const leftW = Math.floor((inner - 3) / 2);
|
|
1232
|
+
const rightW = inner - 3 - leftW;
|
|
1233
|
+
const out: string[] = [
|
|
1234
|
+
`${th.fg("dim", "Before")}${" ".repeat(Math.max(0, leftW - 6))}${sep}${th.fg("dim", "After")}`,
|
|
1235
|
+
th.fg("dim", `${"─".repeat(leftW)}─┼─${"─".repeat(rightW)}`),
|
|
1236
|
+
];
|
|
1237
|
+
|
|
1238
|
+
let dels: string[] = [];
|
|
1239
|
+
let adds: string[] = [];
|
|
1240
|
+
const flushChanges = () => {
|
|
1241
|
+
const count = Math.max(dels.length, adds.length);
|
|
1242
|
+
for (let i = 0; i < count; i++) {
|
|
1243
|
+
const d = dels[i];
|
|
1244
|
+
const a = adds[i];
|
|
1245
|
+
if (d !== undefined && a !== undefined) {
|
|
1246
|
+
const { left, right } = highlightLinePair(d, a, th);
|
|
1247
|
+
out.push(...renderSplitPair({ styled: left }, { styled: right }, leftW, rightW, sep));
|
|
1248
|
+
} else {
|
|
1249
|
+
const left: DiffSide = d !== undefined ? { styled: th.fg("toolDiffRemoved", d) } : null;
|
|
1250
|
+
const right: DiffSide = a !== undefined ? { styled: th.fg("toolDiffAdded", a) } : null;
|
|
1251
|
+
out.push(...renderSplitPair(left, right, leftW, rightW, sep));
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
dels = [];
|
|
1255
|
+
adds = [];
|
|
1256
|
+
};
|
|
1257
|
+
|
|
1258
|
+
for (const line of diff.split("\n")) {
|
|
1259
|
+
if (line.startsWith("-") && !line.startsWith("---")) {
|
|
1260
|
+
dels.push(line.slice(1));
|
|
1261
|
+
} else if (line.startsWith("+") && !line.startsWith("+++")) {
|
|
1262
|
+
adds.push(line.slice(1));
|
|
1263
|
+
} else if (line.startsWith(" ")) {
|
|
1264
|
+
flushChanges();
|
|
1265
|
+
const side: DiffSide = { styled: th.fg("toolDiffContext", line.slice(1)) };
|
|
1266
|
+
out.push(...renderSplitPair(side, side, leftW, rightW, sep));
|
|
1267
|
+
} else {
|
|
1268
|
+
flushChanges();
|
|
1269
|
+
out.push(th.fg("toolDiffContext", line));
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
flushChanges();
|
|
1273
|
+
return out;
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1097
1276
|
// codemode: pi's renderer wrapped in our box. renderShell "self" keeps the
|
|
1098
1277
|
// execution defaults; renderCall/renderResult draw the box. state.hasResult
|
|
1099
1278
|
// guarantees one box per call, also after reload/restore.
|
|
@@ -1734,6 +1913,40 @@ if (isMain(import.meta.url)) {
|
|
|
1734
1913
|
minRender("edit", { path: "README.md" }, diffRes).every((l) => visibleWidth(l) === 74),
|
|
1735
1914
|
"minimal(): hint row still fills the box width",
|
|
1736
1915
|
);
|
|
1916
|
+
// Side-by-side edit diff: Before | After at wide widths, unified fallback when narrow
|
|
1917
|
+
const diffTmp = mkdtempSync(join(tmpdir(), "arnative-editdiff-"));
|
|
1918
|
+
const prevAgentDir = process.env.PI_CODING_AGENT_DIR;
|
|
1919
|
+
process.env.PI_CODING_AGENT_DIR = diffTmp;
|
|
1920
|
+
delete (globalThis as Record<symbol, unknown>)[EDIT_DIFF_CONFIG_KEY];
|
|
1921
|
+
resetPresetCache();
|
|
1922
|
+
try {
|
|
1923
|
+
const openedIsolated = minRender("edit", { path: "README.md" }, diffRes, true);
|
|
1924
|
+
assert(openedIsolated.some((l) => l.includes("Before") && l.includes("│") && l.includes("After")), "edit: expanded view shows Before | After header");
|
|
1925
|
+
assert(openedIsolated.some((l) => l.includes("─┼─")), "edit: expanded view shows header separator");
|
|
1926
|
+
assert(openedIsolated.some((l) => l.includes("old") && !l.includes("-old") && l.includes("│") && l.includes("new") && !l.includes("+new")), "edit: expanded view pairs old and new without +/- prefix");
|
|
1927
|
+
const intraRes = { content: [{ type: "text", text: "ok" }], details: { diff: "-const x = 1;\n+const x = 2;" } };
|
|
1928
|
+
const intraLines = formatEditDiff(intraRes, th, 70);
|
|
1929
|
+
assert(intraLines.some((l) => l.includes("const x = \x1b[7m1\x1b[27m;") && l.includes("const x = \x1b[7m2\x1b[27m;")), "edit: intra-line diff highlights only changed tokens");
|
|
1930
|
+
const pureAdd = minRender("edit", { path: "README.md" }, { content: [{ type: "text", text: "ok" }], details: { diff: "+ 10 added\n 11 ctx" } }, true);
|
|
1931
|
+
assert(pureAdd.some((l) => /^\│\s+\│\s+10 added/.test(l)), "edit: pure addition leaves Before column blank and strips +");
|
|
1932
|
+
assert(pureAdd.some((l) => l.includes("11 ctx") && l.indexOf("11 ctx") !== l.lastIndexOf("11 ctx")), "edit: context line appears in both columns");
|
|
1933
|
+
assert(pureAdd.every((l) => visibleWidth(l) === 74), "edit: side-by-side rows keep exact box width");
|
|
1934
|
+
const narrow = formatEditDiff(diffRes, th, 40);
|
|
1935
|
+
assert(!narrow.some((l) => l.includes("Before") && l.includes("After")), "edit: narrow width falls back to unified diff");
|
|
1936
|
+
setEditDiff("Unified");
|
|
1937
|
+
const liveUnified = minRender("edit", { path: "README.md" }, diffRes, true);
|
|
1938
|
+
assert(!liveUnified.some((l) => l.includes("Before") && l.includes("After")), "edit: setEditDiff('Unified') switches immediately");
|
|
1939
|
+
assert(liveUnified.some((l) => l.includes("-old")) && liveUnified.some((l) => l.includes("+new")), "edit: Unified mode keeps +/- lines");
|
|
1940
|
+
setEditDiff("Split");
|
|
1941
|
+
const liveSplit = minRender("edit", { path: "README.md" }, diffRes, true);
|
|
1942
|
+
assert(liveSplit.some((l) => l.includes("Before") && l.includes("After")), "edit: setEditDiff('Split') switches back immediately");
|
|
1943
|
+
} finally {
|
|
1944
|
+
if (prevAgentDir === undefined) delete process.env.PI_CODING_AGENT_DIR;
|
|
1945
|
+
else process.env.PI_CODING_AGENT_DIR = prevAgentDir;
|
|
1946
|
+
delete (globalThis as Record<symbol, unknown>)[EDIT_DIFF_CONFIG_KEY];
|
|
1947
|
+
resetPresetCache();
|
|
1948
|
+
rmSync(diffTmp, { recursive: true, force: true });
|
|
1949
|
+
}
|
|
1737
1950
|
}
|
|
1738
1951
|
|
|
1739
1952
|
// Chrome DevTools: their bare renderers are replaced by our box (title + summary).
|
package/lib/preset-store.ts
CHANGED
|
@@ -30,6 +30,8 @@ export const BUDGET_ENFORCE_KEY = "budgetEnforce";
|
|
|
30
30
|
export const RENDER_CACHE_KEY = "renderCache";
|
|
31
31
|
/** Remote proxy payload limit: `"Off"` or `"<N> MB"`, absent reads as `"1 MB"`. */
|
|
32
32
|
export const PAYLOAD_LIMIT_KEY = "payloadLimit";
|
|
33
|
+
/** Expanded `edit` diff layout: `"Split"` (default) or `"Unified"`. */
|
|
34
|
+
export const EDIT_DIFF_KEY = "editDiff";
|
|
33
35
|
|
|
34
36
|
// Resolved per call, not at import: the self-check points getAgentDir() at a fixture dir.
|
|
35
37
|
// Everything pi-arnative writes lives in one folder (agent dir/arnative); the config moved
|
|
@@ -102,7 +104,7 @@ export function loadNumber(key: string, range: { min: number; max: number }): nu
|
|
|
102
104
|
/** Reading order of `config.json`: the presets in the order the settings menu shows them,
|
|
103
105
|
* then `layoutVersion`, then anything else (a key from another module or a newer version).
|
|
104
106
|
* Times a user edits the file by hand or reads it back. */
|
|
105
|
-
const KEY_ORDER = ["headerPreset", "footerPreset", "footerCost", "chatboxPreset", "chatboxPrompt", "chatboxDialog", "budgetDay", "budgetMonth", "budgetEnforce", "spinnerPreset", "spinnerGradient", "layoutVersion", "autoCompact", "payloadLimit", "modelHeal", "renderCache"];
|
|
107
|
+
const KEY_ORDER = ["headerPreset", "footerPreset", "footerCost", "chatboxPreset", "chatboxPrompt", "chatboxDialog", "budgetDay", "budgetMonth", "budgetEnforce", "spinnerPreset", "spinnerGradient", "layoutVersion", "autoCompact", "payloadLimit", "modelHeal", "renderCache", "editDiff"];
|
|
106
108
|
|
|
107
109
|
/** The record in {@link KEY_ORDER}; unknown keys keep the order they were written in. */
|
|
108
110
|
function ordered(record: Record<string, unknown>): Record<string, unknown> {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bismawy/pi-arnative",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "Refined aesthetics. Cohesive tools. Built for Pi. Warm themes, rounded tool boxes, tabbed header, compact footer and a /usage dashboard.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|