pi-fold 4.1.5 → 4.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -5
- package/extensions/active-context.ts +16 -1
- package/extensions/index.js +1 -1
- package/extensions/lib/live-settings.ts +2 -0
- package/extensions/lib/status-widget.ts +323 -40
- package/extensions/settings.ts +73 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,14 +37,14 @@ In an interactive session one compact, full-height bar sits directly above Pi's
|
|
|
37
37
|
|
|
38
38
|
<picture>
|
|
39
39
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/shaneconner/fold/main/media/fold-bar-dark.svg">
|
|
40
|
-
<img alt="A single full-height usage bar. Batlow colours group consolidated folds, span folds, tool folds,
|
|
40
|
+
<img alt="A single full-height usage bar. Batlow colours group consolidated folds, span folds, tool folds, marked content, raw context and pinned content in that order. The suffix shows percentage, commit point, and fold, mark, and pin counts." src="https://raw.githubusercontent.com/shaneconner/fold/main/media/fold-bar-light.svg">
|
|
41
41
|
</picture>
|
|
42
42
|
|
|
43
|
-
The forty-column bar uses full-height half-blocks for eighty steps of fill, following the provider's measured count against the serving budget. Within that fill, colours show the estimated visible composition, grouped
|
|
43
|
+
The forty-column bar uses full-height half-blocks for eighty steps of fill, following the provider's measured count against the serving budget. Within that fill, colours show the estimated visible composition, grouped by distance from compression: **Consolidated Folds, Span Folds, Tool Folds, Marked, Raw, Pinned**. The first three are compressed now, deepest first; marked content folds at the next commit; raw content is eligible later; pinned content is held against every commit until released. The six shades, from consolidated to pinned, are read off a colour map, [Crameri's Batlow](https://www.fabiocrameri.ch/colourmaps/) end to end by default, so the bar reads as a gradient from most compressed to most settled. `/fold-settings` offers Batlow, viridis, plasma, magma and cividis, and where on the chosen map the two ends sit, so a slice of a map or a reversed one is a keypress away; the bar repaints on each step. Whatever the choice, each shade's lightness is moved away from the background, hue held, until it clears 4.5:1 on dark and light terminals, and label colours match the bar. Each nonempty category keeps at least one half-cell when the measured fill has room; remaining width follows relative mass. This visibility floor makes small compressed categories visible, so individual category widths are not token-exact. At very low occupancy, the largest shares take the available space. There are no individual fold edges, scores, or height differences.
|
|
44
44
|
|
|
45
|
-
The suffix reads `34% · commit at 55% · N Folds (X Cons., Y Span, Z Tool, X
|
|
45
|
+
The suffix reads `34% · commit at 55% · N Folds (X Cons., Y Span, Z Tool, X Mark, Y Pin)`, naming only the kinds with something to count, in the bar's order; a fresh session reads `0 Folds`. `N Folds` counts visible compressed folds; `Mark` counts pending marks and `Pin` counts protected entries, not additional compressed folds. A tool fold is lossless compression of tool-result context, not a count of tool calls. `/fold-status` retains the detailed token and nesting figures.
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
Two dotted marks stand in the band's edge cells: one at `minTarget`, where a commit aims to land, and one at `maxTarget`, where automatic folding is triggered. Each is drawn over the fill's own colour in a deeper tone of that same hue, so the fill continues behind the mark; on the empty track they stand in muted ink. Neither takes a colour of its own or a warning colour. Before a measurement the row says `not measured yet`; after a commit it identifies the old reading until the provider measures again. Crossing the target is routine runtime work, not a user action item. On reload, saved session context supplies the fold counts and composition without a new model message; the next real context event replaces that read-only view. Unavailable composition is stated as `mapping`; if folding stops, `FOLDING STOPPED` replaces the bar. Non-truecolor terminals use the theme's own colours.
|
|
48
48
|
|
|
49
49
|
## Results
|
|
50
50
|
|
|
@@ -80,7 +80,7 @@ Four papers with figure sources, redacted per-request ledgers and campaign logs
|
|
|
80
80
|
|
|
81
81
|
The one thing worth adding is a long-term memory store. Rotation and retention are different jobs: folding gets stale material out of the window, a store keeps what the session learned. A handoff summary tries to do both in one record, written once under time pressure, bounded by the window it has to fit in. Folding is the rotation half and only that half.
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
Seven options, and every other name is refused.
|
|
84
84
|
|
|
85
85
|
| Option | Default | Effect |
|
|
86
86
|
| --- | --- | --- |
|
|
@@ -90,6 +90,7 @@ Six options, and every other name is refused.
|
|
|
90
90
|
| `toolFoldThreshold` | `0.50` | The tool-call diet: a share in `[0, 1)` naming the oldest fraction of the window whose tool results are clipped in view. `0` turns it off. |
|
|
91
91
|
| `preCommitNotice` | `false` | The notice switch. False is the shape that won the campaign above: no carrier reaches the projection and every fold ships the runtime's own words. `true` states the window's status to the agent once per approach to a commit: where the commit fires, how far away it is, what is staged, what that frees, what is pinned and what the pin costs, with the verbs listed and no argument made for using any of them. |
|
|
92
92
|
| `noticeLeadShare` | `0.10` | How far below the commit trigger that notice speaks, as a share of the serving budget. A distance rather than a point, so it follows a band that moves. Read only when `preCommitNotice` is on. |
|
|
93
|
+
| `palette` | `{ map: "batlow", start: 0, end: 1 }` | The fold bar's colours, and nothing about folding. `map` is one of `batlow`, `viridis`, `plasma`, `magma`, `cividis`; `start` and `end` are positions on it in `[0, 1]` for the most compressed and the pinned shade, which may not coincide and may run backwards. Set whole or not at all. |
|
|
93
94
|
|
|
94
95
|
Four commands ship for the human: `/fold-status`, `/fold` (commit every staged mark now), `/fold-editor` (the interactive map of the window) and `/fold-settings` (edit the options above; each change is saved to `~/.config/pi-fold/settings.json` and takes effect in the running session).
|
|
95
96
|
|
|
@@ -64,7 +64,10 @@ import {
|
|
|
64
64
|
stringIds,
|
|
65
65
|
toolPayload,
|
|
66
66
|
} from "./lib/measurement.ts";
|
|
67
|
-
import {
|
|
67
|
+
import {
|
|
68
|
+
emptyFoldBarMass, renderFoldBar, resolveFoldBarPalette,
|
|
69
|
+
type FoldBarKind, type FoldBarModel, type FoldBarPalette,
|
|
70
|
+
} from "./lib/status-widget.ts";
|
|
68
71
|
import type {
|
|
69
72
|
NativeCompactionCompletionReceipt,
|
|
70
73
|
NativeCompactionDecisionReceipt,
|
|
@@ -303,6 +306,12 @@ export function registerActiveContext(pi: any, options: {
|
|
|
303
306
|
* rather than a point, so it tracks a band that moves. Read only when preCommitNotice
|
|
304
307
|
* is true. */
|
|
305
308
|
noticeLeadShare?: number;
|
|
309
|
+
/** THE FOLD BAR'S COLOURS (2026-09-06, Shane): which colour map the status bar shades
|
|
310
|
+
* its five folded-to-raw categories from and where on that map the two ends of the
|
|
311
|
+
* ramp sit. A display preference: it moves nothing about folding, and it is here only
|
|
312
|
+
* because the settings file is handed to registration whole. Absent means Batlow end
|
|
313
|
+
* to end. */
|
|
314
|
+
palette?: FoldBarPalette;
|
|
306
315
|
}): {
|
|
307
316
|
projectionCandidates: (ctx: any) => Array<Record<string, unknown>>;
|
|
308
317
|
} {
|
|
@@ -320,6 +329,7 @@ export function registerActiveContext(pi: any, options: {
|
|
|
320
329
|
let preCommitNotice = resolvedPreCommitNotice(options.preCommitNotice);
|
|
321
330
|
let noticeLeadShare = resolveNoticeLeadShare(options.noticeLeadShare);
|
|
322
331
|
let toolFoldThreshold = resolvedToolFoldThreshold(options.toolFoldThreshold);
|
|
332
|
+
let palette = resolveFoldBarPalette(options.palette);
|
|
323
333
|
// THE RENAMED OPTION IS REFUSED BY NAME, not ignored (2026-08-30). postFoldNotice was
|
|
324
334
|
// public for three days and named a carrier that no longer exists in that shape: it
|
|
325
335
|
// fired on a fold count, after the cut, and asked for briefs. Silently accepting the
|
|
@@ -777,6 +787,7 @@ export function registerActiveContext(pi: any, options: {
|
|
|
777
787
|
staleAfterCommit: input.share !== null && foldBar.staleSince !== null &&
|
|
778
788
|
foldBar.staleSince === measurements.lastProviderMeasurement,
|
|
779
789
|
stopped: ladder.automaticFailure?.message ?? null,
|
|
790
|
+
palette,
|
|
780
791
|
};
|
|
781
792
|
if (!state || !snapshot) return model;
|
|
782
793
|
model.mapped = true;
|
|
@@ -928,6 +939,7 @@ export function registerActiveContext(pi: any, options: {
|
|
|
928
939
|
const nextToolFoldThreshold = resolvedToolFoldThreshold(settings?.toolFoldThreshold);
|
|
929
940
|
const nextPreCommitNotice = resolvedPreCommitNotice(settings?.preCommitNotice);
|
|
930
941
|
const nextNoticeLeadShare = resolveNoticeLeadShare(settings?.noticeLeadShare);
|
|
942
|
+
const nextPalette = resolveFoldBarPalette(settings?.palette);
|
|
931
943
|
const changed: string[] = [];
|
|
932
944
|
for (const field of ["maxTarget", "minTarget", "consolidateAfter", "minFoldChars"] as const) {
|
|
933
945
|
if (nextThresholds[field] !== thresholds[field]) changed.push(field);
|
|
@@ -935,6 +947,7 @@ export function registerActiveContext(pi: any, options: {
|
|
|
935
947
|
if (nextToolFoldThreshold !== toolFoldThreshold) changed.push("toolFoldThreshold");
|
|
936
948
|
if (nextPreCommitNotice !== preCommitNotice) changed.push("preCommitNotice");
|
|
937
949
|
if (nextNoticeLeadShare !== noticeLeadShare) changed.push("noticeLeadShare");
|
|
950
|
+
if (nextPalette.map !== palette.map || nextPalette.start !== palette.start || nextPalette.end !== palette.end) changed.push("palette");
|
|
938
951
|
// A SAVE THAT MOVED NOTHING IS NOT AN EVENT. The screen saves every keystroke that
|
|
939
952
|
// lands, including a row stepped back to where it started.
|
|
940
953
|
if (!changed.length) return;
|
|
@@ -942,6 +955,7 @@ export function registerActiveContext(pi: any, options: {
|
|
|
942
955
|
toolFoldThreshold = nextToolFoldThreshold;
|
|
943
956
|
preCommitNotice = nextPreCommitNotice;
|
|
944
957
|
noticeLeadShare = nextNoticeLeadShare;
|
|
958
|
+
palette = nextPalette;
|
|
945
959
|
dropDerivationMemo();
|
|
946
960
|
// THE STREAM CARRIES IT, because from here on the session's commits fire at a point
|
|
947
961
|
// no earlier record explains, and an archive reading this run later has no other way
|
|
@@ -955,6 +969,7 @@ export function registerActiveContext(pi: any, options: {
|
|
|
955
969
|
tool_fold_threshold: toolFoldThreshold,
|
|
956
970
|
pre_commit_notice: preCommitNotice,
|
|
957
971
|
notice_lead_share: noticeLeadShare,
|
|
972
|
+
palette: { ...palette },
|
|
958
973
|
});
|
|
959
974
|
// The person is standing in the settings screen, so the line they will look at next
|
|
960
975
|
// is the status line. Without this it keeps the old number until a context event.
|
package/extensions/index.js
CHANGED
|
@@ -11,7 +11,7 @@ export {
|
|
|
11
11
|
|
|
12
12
|
const PUBLIC_OPTIONS = Object.freeze([
|
|
13
13
|
"thresholds", "providerInputBudget", "blacklistAutoFoldTools", "toolFoldThreshold",
|
|
14
|
-
"preCommitNotice", "noticeLeadShare",
|
|
14
|
+
"preCommitNotice", "noticeLeadShare", "palette",
|
|
15
15
|
]);
|
|
16
16
|
|
|
17
17
|
const GENERATOR_DELETED = "the model brief generator is deleted (2026-08-14): across 15 sealed " +
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
// deployment) still agrees on the property.
|
|
26
26
|
|
|
27
27
|
import type { ActiveContextThresholds } from "./policy.ts";
|
|
28
|
+
import type { FoldBarPalette } from "./status-widget.ts";
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* What the settings screen hands the runtime: exactly the settings FILE's shape, where an
|
|
@@ -37,6 +38,7 @@ export interface LiveFoldSettings {
|
|
|
37
38
|
toolFoldThreshold?: number;
|
|
38
39
|
preCommitNotice?: boolean;
|
|
39
40
|
noticeLeadShare?: number;
|
|
41
|
+
palette?: FoldBarPalette;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
/** Refuses by throwing, exactly as registration does, and leaves the runtime untouched. */
|
|
@@ -2,11 +2,254 @@
|
|
|
2
2
|
import { truncateToWidth } from "@earendil-works/pi-tui";
|
|
3
3
|
|
|
4
4
|
export const FOLD_BAR_WIDTH = 40;
|
|
5
|
-
//
|
|
6
|
-
|
|
5
|
+
// GROUPED BY DISTANCE FROM COMPRESSION, left to right (Shane 2026-09-06). Consolidated,
|
|
6
|
+
// span and tool folds are compressed now, deepest first. Marked content is raw now and
|
|
7
|
+
// folds at the next commit. Raw content is raw now and eligible later. Pinned content is
|
|
8
|
+
// raw and HELD against every commit until released, so it is the farthest from
|
|
9
|
+
// compression of all, and it sits at the fresh edge of the bar.
|
|
10
|
+
export const FOLD_BAR_KINDS = ["consolidated", "span", "tool", "marked", "raw", "pinned"] as const;
|
|
7
11
|
export type FoldBarKind = typeof FOLD_BAR_KINDS[number];
|
|
8
12
|
export type FoldBarMass = Record<FoldBarKind, number>;
|
|
9
|
-
export const emptyFoldBarMass = (): FoldBarMass => ({ consolidated: 0, span: 0, tool: 0,
|
|
13
|
+
export const emptyFoldBarMass = (): FoldBarMass => ({ consolidated: 0, span: 0, tool: 0, marked: 0, raw: 0, pinned: 0 });
|
|
14
|
+
|
|
15
|
+
// ALL SIX KINDS TAKE THEIR SHADE FROM THE MAP, in that order (Shane 2026-09-06, second
|
|
16
|
+
// pass). A pin sat off the ramp in the theme accent for one build; Shane put it back at
|
|
17
|
+
// the far end, because a pin is the MOST settled state of all, decided and held, and the
|
|
18
|
+
// map's last shade reads as separate from the rest of the fill on its own.
|
|
19
|
+
|
|
20
|
+
// THE COLOUR MAPS, sampled at 64 positions by lab/generate_colour_maps.py: Batlow from
|
|
21
|
+
// Crameri's own 256-step table, the other four from matplotlib. Five shades are read off
|
|
22
|
+
// the chosen map by linear interpolation between a start and an end position, so a
|
|
23
|
+
// person can use the whole map, a slice of it, or run it backwards. No palette library
|
|
24
|
+
// ships: these tables are the whole dependency.
|
|
25
|
+
export const COLOUR_MAP_NAMES = ["batlow", "viridis", "plasma", "magma", "cividis"] as const;
|
|
26
|
+
export type ColourMapName = typeof COLOUR_MAP_NAMES[number];
|
|
27
|
+
const COLOUR_MAPS: Record<ColourMapName, readonly string[]> = {
|
|
28
|
+
batlow: [
|
|
29
|
+
"#011959", "#051F5A", "#08265B", "#0B2B5C", "#0D315D", "#0E365E", "#0F3B5F", "#103F60",
|
|
30
|
+
"#114360", "#124761", "#134B61", "#154F62", "#175362", "#195662", "#1C5A62", "#1F5D61",
|
|
31
|
+
"#236061", "#27635F", "#2C665D", "#31695B", "#376B59", "#3C6D56", "#426F52", "#49714F",
|
|
32
|
+
"#4F734C", "#557548", "#5C7744", "#627941", "#697B3D", "#707D3A", "#777F36", "#7E8133",
|
|
33
|
+
"#858330", "#8D852E", "#94872C", "#9C892B", "#A48B2C", "#AC8C2D", "#B48E30", "#BC8F34",
|
|
34
|
+
"#C49138", "#CB923E", "#D29343", "#D9954A", "#E09651", "#E69858", "#EC9A61", "#F19C69",
|
|
35
|
+
"#F59F73", "#F8A17C", "#FAA486", "#FCA78F", "#FDAB98", "#FDAEA1", "#FDB1AA", "#FDB3B3",
|
|
36
|
+
"#FDB6BB", "#FDB9C4", "#FDBCCC", "#FCBFD5", "#FCC2DE", "#FBC6E7", "#FBC9F1", "#FACCFA",
|
|
37
|
+
],
|
|
38
|
+
viridis: [
|
|
39
|
+
"#440154", "#46075A", "#470D60", "#471365", "#48186B", "#481E6F", "#482374", "#482878",
|
|
40
|
+
"#472D7C", "#46327F", "#453782", "#433C84", "#424186", "#404688", "#3E4A89", "#3C4F8A",
|
|
41
|
+
"#3A538B", "#38578C", "#365C8D", "#34608D", "#32648E", "#31688E", "#2F6C8E", "#2D708E",
|
|
42
|
+
"#2C748E", "#2A778E", "#297B8E", "#277F8E", "#26838E", "#24878E", "#238A8D", "#218E8D",
|
|
43
|
+
"#20928C", "#1F968B", "#1F9A8A", "#1F9D89", "#1FA187", "#21A586", "#23A984", "#26AC81",
|
|
44
|
+
"#2AB07F", "#2FB47C", "#35B779", "#3BBB75", "#42BE71", "#4AC26D", "#52C569", "#5AC864",
|
|
45
|
+
"#63CB5F", "#6CCE59", "#76D054", "#80D34D", "#8AD547", "#94D841", "#9FDA3A", "#A9DC33",
|
|
46
|
+
"#B4DD2C", "#BFDF25", "#CAE01F", "#D4E21A", "#DFE318", "#E9E41A", "#F3E61E", "#FDE725",
|
|
47
|
+
],
|
|
48
|
+
plasma: [
|
|
49
|
+
"#0D0887", "#19068C", "#220690", "#2A0593", "#320597", "#39049A", "#40049C", "#46039F",
|
|
50
|
+
"#4D02A1", "#5402A3", "#5A01A5", "#6001A6", "#6700A7", "#6D00A8", "#7301A8", "#7902A8",
|
|
51
|
+
"#7F03A8", "#8506A7", "#8B0AA5", "#910EA3", "#9613A1", "#9C179E", "#A11C9B", "#A62098",
|
|
52
|
+
"#AB2594", "#B02991", "#B42E8D", "#B93289", "#BD3785", "#C13B82", "#C5407E", "#C9457A",
|
|
53
|
+
"#CD4976", "#D14E73", "#D4526F", "#D8576C", "#DB5C68", "#DE6065", "#E16561", "#E46A5E",
|
|
54
|
+
"#E76F5A", "#EA7457", "#ED7953", "#EF7E50", "#F2834C", "#F48849", "#F68D45", "#F89342",
|
|
55
|
+
"#F9993E", "#FA9E3B", "#FCA437", "#FDAA34", "#FDB031", "#FEB62E", "#FEBC2B", "#FDC328",
|
|
56
|
+
"#FDC926", "#FCD025", "#FBD624", "#F9DD25", "#F7E425", "#F5EB27", "#F2F227", "#F0F921",
|
|
57
|
+
],
|
|
58
|
+
magma: [
|
|
59
|
+
"#000004", "#02010A", "#040312", "#06051A", "#0A0822", "#0F0B2B", "#130D34", "#180F3E",
|
|
60
|
+
"#1D1148", "#231151", "#29115B", "#301164", "#37106C", "#3E0F72", "#450F76", "#4B117A",
|
|
61
|
+
"#52137C", "#58157E", "#5F187F", "#651A80", "#6B1D81", "#721F81", "#782281", "#7E2482",
|
|
62
|
+
"#852681", "#8B2981", "#922B81", "#982D80", "#9F2F7F", "#A5317E", "#AC337C", "#B3357A",
|
|
63
|
+
"#B93878", "#C03A76", "#C63D74", "#CD3F71", "#D3436E", "#D9466B", "#DF4A68", "#E44F65",
|
|
64
|
+
"#E95462", "#ED5A5F", "#F1605D", "#F4675C", "#F66E5C", "#F8765C", "#FA7E5E", "#FB8560",
|
|
65
|
+
"#FC8D63", "#FD9567", "#FD9C6B", "#FEA470", "#FEAB75", "#FEB37A", "#FEBA80", "#FEC286",
|
|
66
|
+
"#FEC98D", "#FED193", "#FED89A", "#FDDFA1", "#FDE7A8", "#FCEEB0", "#FCF5B7", "#FCFDBF",
|
|
67
|
+
],
|
|
68
|
+
cividis: [
|
|
69
|
+
"#00224E", "#002554", "#00285B", "#002B63", "#002E6A", "#003070", "#063370", "#123670",
|
|
70
|
+
"#1B386F", "#223B6E", "#283E6E", "#2D416D", "#32446D", "#37476C", "#3C496C", "#404C6C",
|
|
71
|
+
"#444F6C", "#48526C", "#4C556C", "#50576C", "#545A6D", "#575D6D", "#5B606E", "#5F636F",
|
|
72
|
+
"#62666F", "#666870", "#696B71", "#6D6E72", "#707173", "#747475", "#777776", "#7A7A78",
|
|
73
|
+
"#7E7D78", "#828078", "#868379", "#898678", "#8D8978", "#918C78", "#958F77", "#999277",
|
|
74
|
+
"#9D9576", "#A19875", "#A59C74", "#A99F73", "#ADA272", "#B2A570", "#B6A96F", "#BAAC6D",
|
|
75
|
+
"#BEAF6B", "#C2B369", "#C7B667", "#CBBA64", "#CFBD62", "#D4C15F", "#D8C45C", "#DDC859",
|
|
76
|
+
"#E1CC55", "#E5CF51", "#EAD34D", "#EFD748", "#F3DB42", "#F8DF3C", "#FDE234", "#FEE838",
|
|
77
|
+
],
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/** Which map the bar reads and where on it the two ends of the ramp sit. `start` is the
|
|
81
|
+
* position of the most compressed shade and `end` the position of raw; a start above
|
|
82
|
+
* its end runs the map backwards. Both are positions in [0, 1] and may not coincide,
|
|
83
|
+
* because six shades read at one position are one shade. */
|
|
84
|
+
export interface FoldBarPalette { map: ColourMapName; start: number; end: number; }
|
|
85
|
+
export const DEFAULT_FOLD_BAR_PALETTE: Readonly<FoldBarPalette> = Object.freeze({ map: "batlow", start: 0, end: 1 });
|
|
86
|
+
|
|
87
|
+
export class FoldBarPaletteError extends Error {}
|
|
88
|
+
|
|
89
|
+
/** One resolver for every path a palette arrives by: registration, the settings file and
|
|
90
|
+
* a live edit. Absent means the package default; anything present is validated whole. */
|
|
91
|
+
export function resolveFoldBarPalette(value: unknown): FoldBarPalette {
|
|
92
|
+
if (value === undefined) return { ...DEFAULT_FOLD_BAR_PALETTE };
|
|
93
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
94
|
+
throw new FoldBarPaletteError("palette must be an object { map, start, end }");
|
|
95
|
+
}
|
|
96
|
+
const candidate = value as Record<string, unknown>;
|
|
97
|
+
for (const key of Object.keys(candidate)) {
|
|
98
|
+
if (key !== "map" && key !== "start" && key !== "end") {
|
|
99
|
+
throw new FoldBarPaletteError(`palette has no ${key} field: the fields are map, start, end`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const { map, start, end } = candidate;
|
|
103
|
+
if (typeof map !== "string" || !(COLOUR_MAP_NAMES as readonly string[]).includes(map)) {
|
|
104
|
+
throw new FoldBarPaletteError(`palette.map must be one of ${COLOUR_MAP_NAMES.join(", ")}`);
|
|
105
|
+
}
|
|
106
|
+
for (const [name, position] of [["start", start], ["end", end]] as const) {
|
|
107
|
+
if (typeof position !== "number" || !Number.isFinite(position) || position < 0 || position > 1) {
|
|
108
|
+
throw new FoldBarPaletteError(`palette.${name} must be a position on the map from 0 to 1`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (start === end) {
|
|
112
|
+
throw new FoldBarPaletteError("palette.start and palette.end must differ: six shades read at one position are one shade");
|
|
113
|
+
}
|
|
114
|
+
return { map: map as ColourMapName, start: start as number, end: end as number };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// sRGB <-> linear <-> OKLab, enough to hold a hue while moving its lightness.
|
|
118
|
+
const hexToRgb = (hex: string): number[] => [1, 3, 5].map((at) => parseInt(hex.slice(at, at + 2), 16) / 255);
|
|
119
|
+
const rgbToHex = (rgb: number[]): string =>
|
|
120
|
+
"#" + rgb.map((v) => Math.round(Math.max(0, Math.min(1, v)) * 255).toString(16).padStart(2, "0").toUpperCase()).join("");
|
|
121
|
+
const toLinear = (c: number): number => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
|
|
122
|
+
const fromLinear = (c: number): number => (c <= 0.0031308 ? 12.92 * c : 1.055 * c ** (1 / 2.4) - 0.055);
|
|
123
|
+
const luminanceOf = (hex: string): number => {
|
|
124
|
+
const [r, g, b] = hexToRgb(hex).map(toLinear);
|
|
125
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
126
|
+
};
|
|
127
|
+
/** WCAG contrast ratio between two colours, the measure gate 165 has always applied. */
|
|
128
|
+
export function contrastRatio(a: string, b: string): number {
|
|
129
|
+
const [la, lb] = [luminanceOf(a), luminanceOf(b)];
|
|
130
|
+
return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
|
|
131
|
+
}
|
|
132
|
+
const linearToOklab = ([r, g, b]: number[]): number[] => {
|
|
133
|
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
134
|
+
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
135
|
+
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
136
|
+
return [
|
|
137
|
+
0.2104542553 * l + 0.7936177850 * m - 0.0040720468 * s,
|
|
138
|
+
1.9779984951 * l - 2.4285922050 * m + 0.4505937099 * s,
|
|
139
|
+
0.0259040371 * l + 0.7827717662 * m - 0.8086757660 * s,
|
|
140
|
+
];
|
|
141
|
+
};
|
|
142
|
+
const oklabToLinear = ([L, a, b]: number[]): number[] => {
|
|
143
|
+
const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;
|
|
144
|
+
const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3;
|
|
145
|
+
const s = (L - 0.0894841775 * a - 1.2914855480 * b) ** 3;
|
|
146
|
+
return [
|
|
147
|
+
4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
|
|
148
|
+
-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
|
|
149
|
+
-0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s,
|
|
150
|
+
];
|
|
151
|
+
};
|
|
152
|
+
/** An OKLab colour brought into the sRGB gamut by shrinking its chroma, hue held. */
|
|
153
|
+
const inGamut = (L: number, a: number, b: number): number[] => {
|
|
154
|
+
const inside = (rgb: number[]): boolean => rgb.every((v) => v >= -1e-6 && v <= 1 + 1e-6);
|
|
155
|
+
let rgb = oklabToLinear([L, a, b]);
|
|
156
|
+
if (inside(rgb)) return rgb.map(fromLinear);
|
|
157
|
+
let lo = 0, hi = 1;
|
|
158
|
+
for (let i = 0; i < 16; i += 1) {
|
|
159
|
+
const mid = (lo + hi) / 2;
|
|
160
|
+
if (inside(oklabToLinear([L, a * mid, b * mid]))) lo = mid; else hi = mid;
|
|
161
|
+
}
|
|
162
|
+
rgb = oklabToLinear([L, a * lo, b * lo]);
|
|
163
|
+
return rgb.map((v) => fromLinear(Math.max(0, Math.min(1, v))));
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
/** The two reference backgrounds the readability floor is measured against. */
|
|
167
|
+
export const READABILITY = Object.freeze({ dark: "#202122", light: "#FFFFFF", contrast: 4.5 });
|
|
168
|
+
|
|
169
|
+
/** THE READABILITY CLAMP. A map's dark end vanishes on a dark terminal and its pale end
|
|
170
|
+
* on a light one, and the old build carried two hand-adjusted hex tables to cover that
|
|
171
|
+
* for one map at one range. With the map and the range a choice, the adjustment runs
|
|
172
|
+
* here: lightness moves away from the background, hue held and chroma shrunk only as far
|
|
173
|
+
* as the gamut needs, until the shade clears 4.5:1 against the reference background. A
|
|
174
|
+
* shade that already clears it is returned untouched. */
|
|
175
|
+
export function readableOn(hex: string, dark: boolean): string {
|
|
176
|
+
const background = dark ? READABILITY.dark : READABILITY.light;
|
|
177
|
+
if (contrastRatio(hex, background) >= READABILITY.contrast) return hex.toUpperCase();
|
|
178
|
+
const [L, a, b] = linearToOklab(hexToRgb(hex).map(toLinear));
|
|
179
|
+
// Lightness is monotone in luminance at held hue, so the boundary is found by bisection
|
|
180
|
+
// between the shade's own lightness and the far end, which always clears the floor.
|
|
181
|
+
let fails = L;
|
|
182
|
+
let passes = dark ? 1 : 0;
|
|
183
|
+
for (let i = 0; i < 24; i += 1) {
|
|
184
|
+
const mid = (fails + passes) / 2;
|
|
185
|
+
if (contrastRatio(rgbToHex(inGamut(mid, a, b)), background) >= READABILITY.contrast) passes = mid;
|
|
186
|
+
else fails = mid;
|
|
187
|
+
}
|
|
188
|
+
return rgbToHex(inGamut(passes, a, b));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** The glyph a guide draws. Marks, not breaks: the fill's own colour stays behind them.
|
|
192
|
+
* DOTTED, NOT A LINE (Shane 2026-09-06, sixth pass): a full-height one-pixel stroke
|
|
193
|
+
* inside a solid colour is exactly what the boundary between two folds of that colour
|
|
194
|
+
* looks like, so the edge strokes "read as fold segments"; a mark that does not span
|
|
195
|
+
* the cell's height cannot be a boundary. The dotted vertical is centred in its cell,
|
|
196
|
+
* so each guide stands just inside the band's edge: the aim in the cell whose left edge
|
|
197
|
+
* is the aim share, the commit in the cell whose right edge is the commit share, a
|
|
198
|
+
* quarter cell in from each line. Earlier passes: a text-ink hairline "too pronounced",
|
|
199
|
+
* a notch "confusing", brackets off their lines because a font insets them. The ink is
|
|
200
|
+
* the fill's own hue toned toward the background, muted on the track. */
|
|
201
|
+
export const GUIDE_GLYPHS = Object.freeze({ aim: "┊", commit: "┊" });
|
|
202
|
+
/** How far a bracket's ink is pulled from the shade under it toward the reference
|
|
203
|
+
* background. Shane 2026-09-06, fourth pass: black brackets were too heavy, and no one
|
|
204
|
+
* fixed accent is legible over a map that runs from navy to pale pink (the theme's teal
|
|
205
|
+
* vanished over the teal span shade, violet over the blue, white over the pink). The
|
|
206
|
+
* fill's own hue, darkened on a dark theme and lightened on a light one, is legible over
|
|
207
|
+
* every shade because the readability clamp holds each shade at 4.5:1 against that
|
|
208
|
+
* background: at this depth the floor is 3:1 over the darkest shade a map can carry. */
|
|
209
|
+
export const GUIDE_TONE = 0.75;
|
|
210
|
+
/** A guide's ink over a shade: the same hue, most of the way to the reference
|
|
211
|
+
* background, so a bracket over salmon is a dark salmon and one over navy a deeper navy.
|
|
212
|
+
* Never a hue of its own, so no guide competes with a category. */
|
|
213
|
+
export function guideInk(under: string, dark: boolean): string {
|
|
214
|
+
const background = hexToRgb(dark ? READABILITY.dark : READABILITY.light);
|
|
215
|
+
return rgbToHex(hexToRgb(under).map((v, i) => v * (1 - GUIDE_TONE) + background[i] * GUIDE_TONE));
|
|
216
|
+
}
|
|
217
|
+
/** How far the dim ink is pulled toward the reference background to stand in for the
|
|
218
|
+
* ░ texture it replaces: a quarter-coverage glyph reads as about a quarter of its ink. */
|
|
219
|
+
export const TRACK_DEPTH = 0.7;
|
|
220
|
+
/** The empty track's one shade, or null when the theme's dim ink is not an RGB escape. */
|
|
221
|
+
export function trackShade(theme: FoldBarTheme, dark: boolean): string | null {
|
|
222
|
+
const match = /^\x1b\[38;2;(\d+);(\d+);(\d+)m$/.exec(theme.getFgAnsi?.("dim") ?? "");
|
|
223
|
+
if (!match) return null;
|
|
224
|
+
const dim = match.slice(1, 4).map((v) => Number(v) / 255);
|
|
225
|
+
const background = hexToRgb(dark ? READABILITY.dark : READABILITY.light);
|
|
226
|
+
return rgbToHex(dim.map((v, i) => v * (1 - TRACK_DEPTH) + background[i] * TRACK_DEPTH));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** The shade a map holds at a position in [0, 1], interpolated between its samples. */
|
|
230
|
+
export function sampleColourMap(map: ColourMapName, position: number): string {
|
|
231
|
+
const table = COLOUR_MAPS[map];
|
|
232
|
+
const at = Math.max(0, Math.min(1, position)) * (table.length - 1);
|
|
233
|
+
const lo = Math.floor(at), hi = Math.min(table.length - 1, lo + 1), t = at - lo;
|
|
234
|
+
const a = hexToRgb(table[lo]), b = hexToRgb(table[hi]);
|
|
235
|
+
return rgbToHex(a.map((v, i) => v * (1 - t) + b[i] * t));
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const shadeMemo = new Map<string, Record<FoldBarKind, string>>();
|
|
239
|
+
/** The six shades for a palette on a background: read off the map at evenly spaced
|
|
240
|
+
* positions from start to end, then brought up to the readability floor. Memoized on
|
|
241
|
+
* the palette and background, since the bar renders many times per choice. */
|
|
242
|
+
export function foldBarShades(palette: FoldBarPalette, dark: boolean): Record<FoldBarKind, string> {
|
|
243
|
+
const key = `${palette.map}:${palette.start}:${palette.end}:${dark ? "dark" : "light"}`;
|
|
244
|
+
const held = shadeMemo.get(key);
|
|
245
|
+
if (held) return held;
|
|
246
|
+
const shades = Object.fromEntries(FOLD_BAR_KINDS.map((kind, i) => {
|
|
247
|
+
const position = palette.start + (palette.end - palette.start) * (i / (FOLD_BAR_KINDS.length - 1));
|
|
248
|
+
return [kind, readableOn(sampleColourMap(palette.map, position), dark)];
|
|
249
|
+
})) as Record<FoldBarKind, string>;
|
|
250
|
+
shadeMemo.set(key, shades);
|
|
251
|
+
return shades;
|
|
252
|
+
}
|
|
10
253
|
|
|
11
254
|
export interface FoldBarModel {
|
|
12
255
|
brand: string;
|
|
@@ -26,27 +269,17 @@ export interface FoldBarModel {
|
|
|
26
269
|
weighed: boolean;
|
|
27
270
|
staleAfterCommit: boolean;
|
|
28
271
|
stopped: string | null;
|
|
272
|
+
/** Absent means the package default, exactly as it does in the settings file. */
|
|
273
|
+
palette?: FoldBarPalette;
|
|
29
274
|
}
|
|
30
275
|
export interface FoldBarTheme {
|
|
31
276
|
fg(color: "dim" | "muted" | "text" | "warning" | "error" | "accent", text: string): string;
|
|
32
277
|
bold(text: string): string;
|
|
33
278
|
getColorMode?(): "truecolor" | "256color";
|
|
34
|
-
getFgAnsi?(color: "text" | "muted" | "accent"): string;
|
|
279
|
+
getFgAnsi?(color: "text" | "muted" | "accent" | "dim"): string;
|
|
35
280
|
name?: string;
|
|
36
281
|
}
|
|
37
282
|
|
|
38
|
-
// Batlow samples at 0, .2, .4 | .6, .8, 1, in the requested category order.
|
|
39
|
-
// Static foreground lightness adjustments retain readable labels on dark/white
|
|
40
|
-
// reference backgrounds. No palette generator or new dependency ships.
|
|
41
|
-
const ON_DARK: Record<FoldBarKind, string> = {
|
|
42
|
-
consolidated: "#6C89C7", span: "#5B919F", tool: "#729261",
|
|
43
|
-
pinned: "#B38E2F", marked: "#FBA689", raw: "#FACCFA",
|
|
44
|
-
};
|
|
45
|
-
const ON_LIGHT: Record<FoldBarKind, string> = {
|
|
46
|
-
consolidated: "#011959", span: "#185562", tool: "#577647",
|
|
47
|
-
pinned: "#927012", marked: "#AA624A", raw: "#8F6891",
|
|
48
|
-
};
|
|
49
|
-
|
|
50
283
|
export function lightBackground(theme: FoldBarTheme): boolean {
|
|
51
284
|
try {
|
|
52
285
|
const match = /38;2;(\d+);(\d+);(\d+)/.exec(theme.getFgAnsi?.("text") ?? "");
|
|
@@ -65,7 +298,9 @@ const truecolor = (hex: string, text: string): string => {
|
|
|
65
298
|
/** Two half-cell samples per terminal column. The measured fill never grows to fit
|
|
66
299
|
* inventory. Each nonempty CATEGORY gets one half-cell when there is room, then quotas
|
|
67
300
|
* follow relative mass. This is a visibility floor, not a per-fold width or token-exact
|
|
68
|
-
* proportion.
|
|
301
|
+
* proportion. A guide reserves the RIGHT half of its column only: the hairline is drawn
|
|
302
|
+
* at that column's right edge, which is the exact share the guide names, over whatever
|
|
303
|
+
* colour the left half holds, so a guide costs one half-cell and erases no category.
|
|
69
304
|
*/
|
|
70
305
|
export function foldBarCells(model: FoldBarModel, width = FOLD_BAR_WIDTH): Array<FoldBarKind | "empty" | "unknown" | "tick"> {
|
|
71
306
|
const samples = 2 * width;
|
|
@@ -73,7 +308,7 @@ export function foldBarCells(model: FoldBarModel, width = FOLD_BAR_WIDTH): Array
|
|
|
73
308
|
const ticks = foldBarTicks(model, width);
|
|
74
309
|
const total = FOLD_BAR_KINDS.reduce((sum, kind) => sum + model.mass[kind], 0);
|
|
75
310
|
const cells: Array<FoldBarKind | "empty" | "unknown" | "tick"> = Array.from({ length: samples }, (_, i) =>
|
|
76
|
-
ticks.has(Math.floor(i / 2)) ? "tick" : i < filled ? "unknown" : "empty");
|
|
311
|
+
i % 2 === 1 && ticks.has(Math.floor(i / 2)) ? "tick" : i < filled ? "unknown" : "empty");
|
|
77
312
|
const slots = cells.flatMap((kind, i) => kind === "unknown" ? [i] : []);
|
|
78
313
|
if (!model.mapped || total <= 0 || !slots.length) return cells;
|
|
79
314
|
const allocation = FOLD_BAR_KINDS.filter((kind) => model.mass[kind] > 0)
|
|
@@ -99,9 +334,16 @@ export function foldBarCells(model: FoldBarModel, width = FOLD_BAR_WIDTH): Array
|
|
|
99
334
|
}
|
|
100
335
|
return cells;
|
|
101
336
|
}
|
|
337
|
+
/** Each guide stands in the band's own edge cell: the aim in the column whose LEFT edge
|
|
338
|
+
* is the aim share, the commit in the column whose RIGHT edge is the commit share, so
|
|
339
|
+
* the band is the run of cells from one mark to the other inclusive. When both land on
|
|
340
|
+
* one column the commit wins, since it is the one the label also names. */
|
|
102
341
|
export function foldBarTicks(model: FoldBarModel, width = FOLD_BAR_WIDTH): Map<number, "aim" | "commit"> {
|
|
103
|
-
const
|
|
104
|
-
return new Map([
|
|
342
|
+
const column = (value: number): number => Math.max(0, Math.min(width - 1, value));
|
|
343
|
+
return new Map([
|
|
344
|
+
[column(Math.round(model.aimShare * width)), "aim"],
|
|
345
|
+
[column(Math.round(model.commitShare * width) - 1), "commit"],
|
|
346
|
+
]);
|
|
105
347
|
}
|
|
106
348
|
export function foldBarPlainText(model: FoldBarModel): string {
|
|
107
349
|
return renderFoldBar(model, Number.POSITIVE_INFINITY, { fg: (_c, t) => t, bold: (t) => t });
|
|
@@ -115,37 +357,73 @@ export function renderFoldBar(model: FoldBarModel, width: number, theme: FoldBar
|
|
|
115
357
|
if (model.stopped) return cut(`${brand} ${theme.fg("error", theme.bold("FOLDING STOPPED"))}` +
|
|
116
358
|
(model.share === null ? "" : neutral(` · ${Math.round(model.share * 100)}% full`)));
|
|
117
359
|
if (model.share === null) return cut(`${brand} ${muted(`not measured yet · folds automatically at ${Math.round(model.commitShare * 100)}%`)}`);
|
|
118
|
-
const
|
|
360
|
+
const truecolorMode = theme.getColorMode?.() === "truecolor";
|
|
361
|
+
const dark = !lightBackground(theme);
|
|
362
|
+
const shades = foldBarShades(model.palette ?? DEFAULT_FOLD_BAR_PALETTE, dark);
|
|
363
|
+
// Without truecolor the theme's own inks stand in: pinned takes the accent, raw the
|
|
364
|
+
// muted ink, everything compressed or marked the text ink.
|
|
119
365
|
const ink = (kind: FoldBarKind, text: string): string => {
|
|
120
|
-
if (
|
|
121
|
-
|
|
122
|
-
return theme.fg(kind === "raw" ? "muted" : "text", text);
|
|
366
|
+
if (truecolorMode) return truecolor(shades[kind], text);
|
|
367
|
+
return theme.fg(kind === "pinned" ? "accent" : kind === "raw" ? "muted" : "text", text);
|
|
123
368
|
};
|
|
124
369
|
const cells = foldBarCells(model);
|
|
370
|
+
const ticks = foldBarTicks(model);
|
|
371
|
+
// THE TRACK IS SOLID (Shane 2026-09-06, fourth pass): a guide cell on a ░ track was a
|
|
372
|
+
// blank cell with a bracket in it, which read as a hole. With an RGB dim ink the empty
|
|
373
|
+
// track is one shade, the dim ink pulled most of the way to the reference background
|
|
374
|
+
// so it sits where ░ used to, and a bracket on it stands on that same shade. Without
|
|
375
|
+
// an RGB dim ink the ░ texture stays, and the guide cell there is bare.
|
|
376
|
+
const track = trackShade(theme, dark);
|
|
377
|
+
const trackBg = track ? truecolor(track, "").replace("[38;", "[48;") : null;
|
|
125
378
|
const solid = (kind: typeof cells[number]): string => {
|
|
126
|
-
if (kind === "
|
|
127
|
-
if (kind === "empty") return theme.fg("dim", "░");
|
|
379
|
+
if (kind === "empty") return trackBg ? `${trackBg} \x1b[49m` : theme.fg("dim", "░");
|
|
128
380
|
if (kind === "unknown") return muted("█");
|
|
129
|
-
return ink(kind, "█");
|
|
381
|
+
return ink(kind as FoldBarKind, "█");
|
|
130
382
|
};
|
|
131
|
-
const background = (kind: FoldBarKind): string | null => {
|
|
132
|
-
if (
|
|
133
|
-
// Pi exposes the same theme ink in 256-colour mode
|
|
134
|
-
// to background, without assuming an RGB theme or
|
|
135
|
-
|
|
383
|
+
const background = (kind: FoldBarKind | "unknown"): string | null => {
|
|
384
|
+
if (truecolorMode && kind !== "unknown") return truecolor(shades[kind], "").replace("[38;", "[48;");
|
|
385
|
+
// Pi exposes the same theme ink in 256-colour mode, and the accent for a pin there.
|
|
386
|
+
// Convert its foreground escape to background, without assuming an RGB theme or
|
|
387
|
+
// leaking styles into the label.
|
|
388
|
+
const fg = theme.getFgAnsi?.(kind === "pinned" ? "accent" : kind === "raw" || kind === "unknown" ? "muted" : "text") ?? "";
|
|
136
389
|
const extended = /^\x1b\[38;(?:2;\d+;\d+;\d+|5;\d+)m$/.test(fg);
|
|
137
390
|
if (extended) return fg.replace("[38;", "[48;");
|
|
138
391
|
const basic = /^\x1b\[(3[0-7]|9[0-7])m$/.exec(fg);
|
|
139
392
|
return basic ? `\x1b[${Number(basic[1]) + 10}m` : null;
|
|
140
393
|
};
|
|
394
|
+
// THE GUIDES ARE MARKS ON THE AXIS, NOT BREAKS IN THE FILL (Shane 2026-09-06, third
|
|
395
|
+
// pass). A hairline in text ink read as a white bar; a notch cut into the fill read as
|
|
396
|
+
// a boundary between two kinds of content, which a threshold is not. The band is an
|
|
397
|
+
// interval, so a dotted mark stands in each of its edge cells, drawn over the fill's
|
|
398
|
+
// own colour in that colour's own hue pulled toward the background. No hue of its
|
|
399
|
+
// own, since a coloured guide competes with a category; never the warning ink, since
|
|
400
|
+
// folding is automatic and the person has nothing to do about it. On the track the
|
|
401
|
+
// muted ink stands on the track's shade; without truecolor the mark stands on the
|
|
402
|
+
// default background, because the theme's inks are the fill.
|
|
403
|
+
const shadeUnder = (left: typeof cells[number]): string | null =>
|
|
404
|
+
truecolorMode && (FOLD_BAR_KINDS as readonly string[]).includes(left) ? shades[left as FoldBarKind] : null;
|
|
405
|
+
const guide = (column: number, left: typeof cells[number]): string => {
|
|
406
|
+
const glyph = GUIDE_GLYPHS[ticks.get(column) ?? "aim"];
|
|
407
|
+
const under = shadeUnder(left);
|
|
408
|
+
if (under) return `${background(left as FoldBarKind)}${truecolor(guideInk(under, dark), glyph)}\x1b[49m`;
|
|
409
|
+
if (left === "empty" && trackBg) return `${trackBg}${theme.fg("muted", glyph)}\x1b[49m`;
|
|
410
|
+
return theme.fg("muted", glyph);
|
|
411
|
+
};
|
|
141
412
|
let bar = "";
|
|
142
413
|
for (let i = 0; i < cells.length; i += 2) {
|
|
143
414
|
const left = cells[i], right = cells[i + 1];
|
|
415
|
+
if (right === "tick") {
|
|
416
|
+
// The mark over the left half's own colour: the guide stands in the band's edge
|
|
417
|
+
// cell and hides no fill. Off the fill it stands on the track.
|
|
418
|
+
bar += guide(i / 2, left);
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
144
421
|
if (left === right) { bar += solid(left); continue; }
|
|
145
422
|
// One full-height left-half glyph, right colour supplied by the cell background:
|
|
146
423
|
// two colours in one column, never a notch, gap, score, or extra terminal column.
|
|
147
424
|
if (right === "empty") {
|
|
148
|
-
|
|
425
|
+
const half = left === "unknown" ? muted("▌") : ink(left as FoldBarKind, "▌");
|
|
426
|
+
bar += trackBg ? `${trackBg}${half}\x1b[49m` : half;
|
|
149
427
|
} else {
|
|
150
428
|
const bg = background(right as FoldBarKind);
|
|
151
429
|
bar += bg ? `${bg}${ink(left as FoldBarKind, "▌")}\x1b[49m` : solid(left);
|
|
@@ -160,13 +438,18 @@ export function renderFoldBar(model: FoldBarModel, width: number, theme: FoldBar
|
|
|
160
438
|
parts.push(neutral(`${pct}%`), muted(when));
|
|
161
439
|
}
|
|
162
440
|
if (model.mapped) {
|
|
163
|
-
// N counts compressed folds. Pin
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
441
|
+
// N counts compressed folds. Mark/Pin are accompanying states, not added to N, and
|
|
442
|
+
// they are named in the bar's own order. A kind with nothing to count is not named
|
|
443
|
+
// (Shane 2026-09-06): the row's width is the scarce thing, and "0 Tool" tells a
|
|
444
|
+
// person nothing the bar does not already show by its absence.
|
|
445
|
+
const counts = ([
|
|
446
|
+
["consolidated", model.foldConsolidations, "Cons."], ["span", model.foldSpans, "Span"],
|
|
447
|
+
["tool", model.foldTruncations, "Tool"], ["marked", model.stagedMarks, "Mark"],
|
|
448
|
+
["pinned", model.pinnedRefs, "Pin"],
|
|
449
|
+
] as const).filter(([, count]) => count > 0).map(([kind, count, word]) => ink(kind, `${count} ${word}`));
|
|
450
|
+
parts.push(counts.length
|
|
451
|
+
? neutral(`${model.folds} Folds (`) + counts.join(muted(", ")) + neutral(")")
|
|
452
|
+
: neutral(`${model.folds} Folds`));
|
|
170
453
|
if (model.unplacedItems > 0) parts.push(muted(`${model.unplacedItems} not mapped`));
|
|
171
454
|
} else parts.push(muted("mapping"));
|
|
172
455
|
return cut(`${bar} ${parts.join(theme.fg("dim", " · "))}`);
|
package/extensions/settings.ts
CHANGED
|
@@ -29,6 +29,13 @@ import {
|
|
|
29
29
|
type ActiveContextThresholds,
|
|
30
30
|
} from "./lib/policy.ts";
|
|
31
31
|
import { applyLiveSettings, liveSettingsReachable } from "./lib/live-settings.ts";
|
|
32
|
+
import {
|
|
33
|
+
COLOUR_MAP_NAMES,
|
|
34
|
+
DEFAULT_FOLD_BAR_PALETTE,
|
|
35
|
+
FoldBarPaletteError,
|
|
36
|
+
resolveFoldBarPalette,
|
|
37
|
+
type FoldBarPalette,
|
|
38
|
+
} from "./lib/status-widget.ts";
|
|
32
39
|
|
|
33
40
|
export const DEFAULT_FOLD_SETTINGS_PATH = join(
|
|
34
41
|
homedir(),
|
|
@@ -47,6 +54,11 @@ export interface FoldSettingsFile {
|
|
|
47
54
|
toolFoldThreshold?: number;
|
|
48
55
|
preCommitNotice?: boolean;
|
|
49
56
|
noticeLeadShare?: number;
|
|
57
|
+
// THE BAR'S COLOURS, stored whole for the same reason the thresholds are (2026-09-06):
|
|
58
|
+
// start and end may not coincide, which is a cross-field invariant, so a partial object
|
|
59
|
+
// would mean whatever the defaults are at read time. Absent means the package default.
|
|
60
|
+
// It is a display preference and moves nothing about folding.
|
|
61
|
+
palette?: FoldBarPalette;
|
|
50
62
|
}
|
|
51
63
|
|
|
52
64
|
// The four settings, named once. This was a hand-written union until the migration
|
|
@@ -63,11 +75,17 @@ const THRESHOLD_FIELDS = [
|
|
|
63
75
|
// validation and no relationship to any other value on the screen.
|
|
64
76
|
const SCALAR_FIELDS = ["toolFoldThreshold", "preCommitNotice", "noticeLeadShare"] as const;
|
|
65
77
|
|
|
66
|
-
|
|
78
|
+
// The three rows that edit the palette object, each naming the field it moves.
|
|
79
|
+
const PALETTE_FIELDS = { paletteMap: "map", paletteStart: "start", paletteEnd: "end" } as const;
|
|
80
|
+
|
|
81
|
+
export type FoldSettingId = typeof THRESHOLD_FIELDS[number] | typeof SCALAR_FIELDS[number] | keyof typeof PALETTE_FIELDS;
|
|
67
82
|
|
|
68
83
|
function isThresholdField(id: FoldSettingId): id is typeof THRESHOLD_FIELDS[number] {
|
|
69
84
|
return (THRESHOLD_FIELDS as readonly string[]).includes(id);
|
|
70
85
|
}
|
|
86
|
+
function isPaletteField(id: FoldSettingId): id is keyof typeof PALETTE_FIELDS {
|
|
87
|
+
return Object.hasOwn(PALETTE_FIELDS, id);
|
|
88
|
+
}
|
|
71
89
|
|
|
72
90
|
// One edit, applied against the WHOLE draft: the merged thresholds object is
|
|
73
91
|
// re-validated through resolveThresholds so cross-field invariants
|
|
@@ -105,6 +123,20 @@ export function applyFoldSettingsEdit(
|
|
|
105
123
|
}
|
|
106
124
|
return { ok: true, draft: { ...draft, toolFoldThreshold: value } };
|
|
107
125
|
}
|
|
126
|
+
if (isPaletteField(id)) {
|
|
127
|
+
// The palette is re-validated WHOLE through the runtime's own resolver, so the
|
|
128
|
+
// cross-field rule (start and end differ) holds at every saved state.
|
|
129
|
+
const field = PALETTE_FIELDS[id];
|
|
130
|
+
const raw = rawValue.trim();
|
|
131
|
+
const value = field === "map" ? raw : Number(raw);
|
|
132
|
+
try {
|
|
133
|
+
const palette = resolveFoldBarPalette({ ...(draft.palette ?? DEFAULT_FOLD_BAR_PALETTE), [field]: value });
|
|
134
|
+
return { ok: true, draft: { ...draft, palette } };
|
|
135
|
+
} catch (error) {
|
|
136
|
+
if (error instanceof FoldBarPaletteError) return { ok: false, error: error.message };
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
108
140
|
try {
|
|
109
141
|
const value = Number(rawValue.trim());
|
|
110
142
|
if ((id === "consolidateAfter" || id === "minFoldChars") && !Number.isSafeInteger(value)) {
|
|
@@ -209,10 +241,10 @@ export function readFoldSettingsFile(path: string = DEFAULT_FOLD_SETTINGS_PATH):
|
|
|
209
241
|
dropped = true;
|
|
210
242
|
}
|
|
211
243
|
for (const key of Object.keys(parsed)) {
|
|
212
|
-
if (key === "thresholds" || (SCALAR_FIELDS as readonly string[]).includes(key)) continue;
|
|
244
|
+
if (key === "thresholds" || key === "palette" || (SCALAR_FIELDS as readonly string[]).includes(key)) continue;
|
|
213
245
|
if (RETIRED_FILE_KEYS.includes(key)) { delete parsed[key]; dropped = true; continue; }
|
|
214
246
|
return refused(`fold settings file has no ${key} field: the surface is ` +
|
|
215
|
-
`thresholds, ${SCALAR_FIELDS.join(", ")}`);
|
|
247
|
+
`thresholds, ${SCALAR_FIELDS.join(", ")}, palette`);
|
|
216
248
|
}
|
|
217
249
|
// The two scalars are validated the same way the editor validates them, through the
|
|
218
250
|
// one path, so a hand-edited file cannot hold a value the screen would refuse.
|
|
@@ -232,6 +264,12 @@ export function readFoldSettingsFile(path: string = DEFAULT_FOLD_SETTINGS_PATH):
|
|
|
232
264
|
}
|
|
233
265
|
Object.assign(scalars, applied.draft);
|
|
234
266
|
}
|
|
267
|
+
// The palette goes through the one resolver the runtime and the editor use, so a
|
|
268
|
+
// hand-edited file cannot hold a map name or a range the screen would refuse.
|
|
269
|
+
if (parsed.palette !== undefined) {
|
|
270
|
+
try { scalars.palette = resolveFoldBarPalette(parsed.palette); }
|
|
271
|
+
catch (error: any) { return refused(`fold settings palette is invalid: ${error?.message ?? error}`); }
|
|
272
|
+
}
|
|
235
273
|
if (parsed.thresholds === undefined) {
|
|
236
274
|
if (dropped) { try { saveFoldSettingsFile(path, scalars); } catch { } }
|
|
237
275
|
return { settings: scalars, refusal: null, migrated: dropped };
|
|
@@ -271,6 +309,7 @@ export function saveFoldSettingsFile(path: string, settings: FoldSettingsFile):
|
|
|
271
309
|
if (settings.toolFoldThreshold !== undefined) clean.toolFoldThreshold = settings.toolFoldThreshold;
|
|
272
310
|
if (settings.preCommitNotice !== undefined) clean.preCommitNotice = settings.preCommitNotice;
|
|
273
311
|
if (settings.noticeLeadShare !== undefined) clean.noticeLeadShare = settings.noticeLeadShare;
|
|
312
|
+
if (settings.palette !== undefined) clean.palette = settings.palette;
|
|
274
313
|
mkdirSync(dirname(path), { recursive: true });
|
|
275
314
|
const temporary = `${path}.tmp`;
|
|
276
315
|
writeFileSync(temporary, `${JSON.stringify(clean, null, 2)}\n`);
|
|
@@ -297,6 +336,12 @@ const EDITOR_ROWS: readonly EditorRow[] = [
|
|
|
297
336
|
{ id: "toolFoldThreshold", label: "Clip old tool results", description: "The oldest share of the window shows tool results shortened, still recoverable in full. Off keeps them whole (toolFoldThreshold)" },
|
|
298
337
|
{ id: "preCommitNotice", label: "Tell the model before folding", description: "Show the model the window's status once as a fold approaches: what is staged, what is pinned, what it can change. Off is what the measured runs used (preCommitNotice)" },
|
|
299
338
|
{ id: "noticeLeadShare", label: "How early to tell it", description: "How far below the folding point that status appears. Only used when the notice is on (noticeLeadShare)" },
|
|
339
|
+
// THE BAR'S COLOURS ARE A CHOICE (Shane 2026-09-06). Three rows over one stored object:
|
|
340
|
+
// which map, and where on it the two ends of the ramp sit. The status line repaints on
|
|
341
|
+
// every step, so the bar itself is the preview.
|
|
342
|
+
{ id: "paletteMap", label: "Bar colours", description: "The colour map the status bar reads its six shades from, most compressed first and pinned last (palette.map)" },
|
|
343
|
+
{ id: "paletteStart", label: "Folded shade at", description: "Where on that map the most compressed content sits. Put it past the pinned end to run the map backwards (palette.start)" },
|
|
344
|
+
{ id: "paletteEnd", label: "Pinned shade at", description: "Where on that map pinned content sits, with raw just before it. The shades between are spaced evenly (palette.end)" },
|
|
300
345
|
];
|
|
301
346
|
|
|
302
347
|
// The cycle lattice for both shares. Shares step in cents so no float drift reaches a
|
|
@@ -326,6 +371,9 @@ const MIN_FOLD_CHOICES = [2_000, 4_000, 6_000, 8_000, 12_000, 16_000, 24_000, 32
|
|
|
326
371
|
// off: without a 0 here the only way to decline in-view clipping would be the file.
|
|
327
372
|
const TOOL_FOLD_CHOICES = [0, 0.25, 0.35, 0.50, 0.65, 0.75, 0.90];
|
|
328
373
|
|
|
374
|
+
// Positions on a colour map, the whole of it in twentieths, ends included.
|
|
375
|
+
const MAP_POSITION_CHOICES = Array.from({ length: 21 }, (_, i) => i / 20);
|
|
376
|
+
|
|
329
377
|
function shareCandidates(): number[] {
|
|
330
378
|
const { min, max, step } = SHARE_LATTICE;
|
|
331
379
|
const values: number[] = [];
|
|
@@ -337,8 +385,13 @@ function shareCandidates(): number[] {
|
|
|
337
385
|
|
|
338
386
|
// The lattice a row steps along, as numbers. Display belongs to rowDisplayValue and
|
|
339
387
|
// only to it: this list is stepped, never shown.
|
|
340
|
-
function allowedValues(id: FoldSettingId, thresholds: ActiveContextThresholds): number[] {
|
|
388
|
+
function allowedValues(id: FoldSettingId, thresholds: ActiveContextThresholds, palette: FoldBarPalette): number[] {
|
|
341
389
|
if (id === "toolFoldThreshold") return TOOL_FOLD_CHOICES;
|
|
390
|
+
// Each end of the ramp may step anywhere on the map except onto the other end: the
|
|
391
|
+
// cross-field rule is the filter, so stepping across the other end is one keypress.
|
|
392
|
+
if (id === "paletteStart") return MAP_POSITION_CHOICES.filter((v) => Math.abs(v - palette.end) > 1e-9);
|
|
393
|
+
if (id === "paletteEnd") return MAP_POSITION_CHOICES.filter((v) => Math.abs(v - palette.start) > 1e-9);
|
|
394
|
+
if (id === "paletteMap") return [];
|
|
342
395
|
// THE LEAD STEPS THE ONE SHARE LATTICE, unfiltered. It answers to nothing but its own
|
|
343
396
|
// range: a lead wider than the trigger is legal and means "speak from the first
|
|
344
397
|
// measurement", which the runtime floors rather than refuses, so there is no
|
|
@@ -359,6 +412,7 @@ function rowRawValue(settings: FoldSettingsFile, id: FoldSettingId): string {
|
|
|
359
412
|
// A SCALAR THAT IS ABSENT READS AS THE PACKAGE DEFAULT, never as zero or false. The
|
|
360
413
|
// file omits what was never set on purpose, so the screen has to supply the same
|
|
361
414
|
// value the runtime would, or the row would show a setting nobody chose.
|
|
415
|
+
if (isPaletteField(id)) return String((settings.palette ?? DEFAULT_FOLD_BAR_PALETTE)[PALETTE_FIELDS[id]]);
|
|
362
416
|
if (!isThresholdField(id)) {
|
|
363
417
|
if (id === "toolFoldThreshold") return String(settings.toolFoldThreshold ?? DEFAULT_TOOL_FOLD_THRESHOLD);
|
|
364
418
|
if (id === "noticeLeadShare") return String(settings.noticeLeadShare ?? DEFAULT_NOTICE_LEAD_SHARE);
|
|
@@ -384,6 +438,13 @@ function rowDisplayValue(settings: FoldSettingsFile, id: FoldSettingId, budgetTo
|
|
|
384
438
|
}
|
|
385
439
|
if (id === "consolidateAfter") return raw;
|
|
386
440
|
if (id === "minFoldChars") return `${Number(raw).toLocaleString("en-US")} characters`;
|
|
441
|
+
if (id === "paletteMap") return raw;
|
|
442
|
+
if (id === "paletteStart" || id === "paletteEnd") {
|
|
443
|
+
// A POSITION ON THE MAP, not a share of the window: the percentages elsewhere on this
|
|
444
|
+
// screen are occupancy, and this one is not, so it says what it is along.
|
|
445
|
+
const position = Number(raw);
|
|
446
|
+
return position === 0 ? "start of the map" : position === 1 ? "end of the map" : `${Math.round(position * 100)}% along the map`;
|
|
447
|
+
}
|
|
387
448
|
// A PERCENTAGE, like every other human surface. The screen used to read "0.80" while
|
|
388
449
|
// the status line, /fold-status and the editor header all said "80%", so the one place
|
|
389
450
|
// a person CHANGES the number spoke a different dialect from the three that report it.
|
|
@@ -539,8 +600,14 @@ export class FoldSettingsEditor extends Container {
|
|
|
539
600
|
this.applyAndSave(id, rowRawValue(this.draft, id) === "true" ? "false" : "true");
|
|
540
601
|
return;
|
|
541
602
|
}
|
|
603
|
+
// A NAMED LIST steps by index, clamped at its ends like every other row.
|
|
604
|
+
if (id === "paletteMap") {
|
|
605
|
+
const at = (COLOUR_MAP_NAMES as readonly string[]).indexOf(rowRawValue(this.draft, id)) + direction;
|
|
606
|
+
if (at >= 0 && at < COLOUR_MAP_NAMES.length) this.applyAndSave(id, COLOUR_MAP_NAMES[at]);
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
542
609
|
const thresholds = this.draft.thresholds ?? DEFAULT_THRESHOLDS;
|
|
543
|
-
const candidates = allowedValues(id, thresholds);
|
|
610
|
+
const candidates = allowedValues(id, thresholds, this.draft.palette ?? DEFAULT_FOLD_BAR_PALETTE);
|
|
544
611
|
const current = Number(rowRawValue(this.draft, id));
|
|
545
612
|
const target = direction > 0
|
|
546
613
|
? candidates.find((candidate) => candidate > current + 1e-9)
|
|
@@ -595,7 +662,7 @@ export function registerFoldSettings(
|
|
|
595
662
|
): void {
|
|
596
663
|
const settingsPath = options.settingsPath ?? DEFAULT_FOLD_SETTINGS_PATH;
|
|
597
664
|
pi.registerCommand("fold-settings", {
|
|
598
|
-
description: "Configure pi-fold: commit band, consolidation, fold size, tool-result clipping,
|
|
665
|
+
description: "Configure pi-fold: commit band, consolidation, fold size, tool-result clipping, the pre-commit notice, bar colours",
|
|
599
666
|
handler: async (_args: string, ctx: any) => {
|
|
600
667
|
if (typeof ctx.ui?.custom !== "function") {
|
|
601
668
|
throw new Error("/fold-settings needs an interactive UI; set thresholds in the settings file instead");
|