@aeondave/pi-theme-1337 0.0.0-stage → 0.6.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 +263 -0
- package/LICENSE +21 -0
- package/README.md +166 -2
- package/assets/banner.png +0 -0
- package/assets/palettes.gif +0 -0
- package/docs/architecture.md +172 -0
- package/docs/configuration.md +103 -0
- package/docs/palette-design.md +51 -0
- package/docs/theme-motion.md +88 -0
- package/package.json +68 -4
- package/src/avatar.ts +174 -0
- package/src/background.ts +82 -0
- package/src/config.ts +400 -0
- package/src/diff-spans.ts +77 -0
- package/src/draft.ts +10 -0
- package/src/editor.ts +545 -0
- package/src/format.ts +464 -0
- package/src/frame.ts +380 -0
- package/src/git-status-cache.ts +198 -0
- package/src/git-status-reader.ts +28 -0
- package/src/git-status.ts +72 -0
- package/src/header-controller.ts +58 -0
- package/src/header.ts +151 -0
- package/src/index.ts +1264 -0
- package/src/quota.ts +581 -0
- package/src/redraw-guard.ts +79 -0
- package/src/run-summary.ts +623 -0
- package/src/spinner.ts +72 -0
- package/src/status-style.ts +26 -0
- package/src/terminal-title.ts +67 -0
- package/src/tool-activity.ts +216 -0
- package/src/tool-adapter.ts +491 -0
- package/src/tool-groups.ts +192 -0
- package/src/tool-lexicon.ts +200 -0
- package/src/tool-view.ts +788 -0
- package/src/width.ts +246 -0
- package/themes/1337-amber.json +94 -0
- package/themes/1337-amber.pi1337 +3 -0
- package/themes/1337-cosmos.json +94 -0
- package/themes/1337-cosmos.pi1337 +3 -0
- package/themes/1337-cyber.json +94 -0
- package/themes/1337-cyber.pi1337 +3 -0
- package/themes/1337-cyberpunk-2077-edgerunner.json +94 -0
- package/themes/1337-cyberpunk-2077-edgerunner.pi1337 +7 -0
- package/themes/1337-cyberpunk-2077.json +94 -0
- package/themes/1337-cyberpunk-2077.pi1337 +7 -0
- package/themes/1337-fallout.json +94 -0
- package/themes/1337-fallout.pi1337 +4 -0
- package/themes/1337-ice.json +94 -0
- package/themes/1337-ice.pi1337 +3 -0
- package/themes/1337-magma.json +94 -0
- package/themes/1337-magma.pi1337 +1 -0
- package/themes/1337-neon.json +94 -0
- package/themes/1337-neon.pi1337 +3 -0
- package/themes/1337-poison.json +94 -0
- package/themes/1337-poison.pi1337 +3 -0
- package/themes/1337-skynet-dark.json +94 -0
- package/themes/1337-skynet-dark.pi1337 +4 -0
- package/themes/1337-skynet.json +94 -0
- package/themes/1337-skynet.pi1337 +4 -0
- package/themes/1337.json +95 -0
- package/themes/1337.pi1337 +3 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one vocabulary for Pi's built-in tools. Transcript rows, the status row's
|
|
3
|
+
* activity label and folded-run tallies all take their words from here, so a
|
|
4
|
+
* tool is named the same way wherever it shows up: imperative on its row
|
|
5
|
+
* ("Read src/width.ts"), progressive while it runs ("Reading width.ts…"), past
|
|
6
|
+
* tense in a tally ("Read 3 files, searched 2 patterns").
|
|
7
|
+
*
|
|
8
|
+
* Data only: extracting the target (path, pattern, command) stays with the
|
|
9
|
+
* module that renders it. Lookups go through a Map because tool names are
|
|
10
|
+
* model-controlled — a plain-object lookup would resolve "constructor".
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { recordOf, sanitizeInlineText, textOf } from "./format.ts";
|
|
14
|
+
|
|
15
|
+
/** One clause of a folded-run tally: "read 3 files". */
|
|
16
|
+
export interface ToolTally {
|
|
17
|
+
readonly verb: string;
|
|
18
|
+
readonly one: string;
|
|
19
|
+
readonly many: string;
|
|
20
|
+
/** The argument naming what the clause counts: paging one file three times is still one file. */
|
|
21
|
+
readonly subject: "path" | "pattern";
|
|
22
|
+
/** The tool acts on the working directory when the argument is absent (`ls`). */
|
|
23
|
+
readonly cwdWhenAbsent?: true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** A call as a tally sees it. */
|
|
27
|
+
export interface TalliedCall {
|
|
28
|
+
readonly name: string;
|
|
29
|
+
/** From `tallySubject`; calls without one each count on their own. */
|
|
30
|
+
readonly subject?: string;
|
|
31
|
+
/** From `tallyName`: how the detailed tally names the subject. Raw text, sanitized where painted. */
|
|
32
|
+
readonly display?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ToolWords {
|
|
36
|
+
/** Row heading verb: "Read src/width.ts". */
|
|
37
|
+
readonly title: string;
|
|
38
|
+
/** Status-row verb while the call runs: "Reading width.ts…". */
|
|
39
|
+
readonly doing: string;
|
|
40
|
+
/** A settled, successful call shows its header only (with what it found); its output waits behind expand. */
|
|
41
|
+
readonly quiet?: true;
|
|
42
|
+
/**
|
|
43
|
+
* Read-only exploration that may fold into a run tally. Tools that share a
|
|
44
|
+
* clause share the object, so grep and find count as one "searched N patterns".
|
|
45
|
+
*/
|
|
46
|
+
readonly tally?: ToolTally;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const SEARCHED: ToolTally = { verb: "searched", one: "pattern", many: "patterns", subject: "pattern" };
|
|
50
|
+
|
|
51
|
+
const WORDS: ReadonlyMap<string, ToolWords> = new Map<string, ToolWords>([
|
|
52
|
+
["bash", { title: "$", doing: "Running", quiet: true }],
|
|
53
|
+
["read", { title: "Read", doing: "Reading", quiet: true, tally: { verb: "read", one: "file", many: "files", subject: "path" } }],
|
|
54
|
+
["grep", { title: "Search", doing: "Searching", quiet: true, tally: SEARCHED }],
|
|
55
|
+
["find", { title: "Find", doing: "Finding", quiet: true, tally: SEARCHED }],
|
|
56
|
+
["ls", { title: "List", doing: "Listing", quiet: true, tally: { verb: "listed", one: "folder", many: "folders", subject: "path", cwdWhenAbsent: true } }],
|
|
57
|
+
["edit", { title: "Update", doing: "Updating" }],
|
|
58
|
+
["write", { title: "Write", doing: "Writing" }],
|
|
59
|
+
]);
|
|
60
|
+
|
|
61
|
+
/** Words for a built-in tool; undefined for extension, MCP and unknown tools. */
|
|
62
|
+
export function toolWords(name: string): ToolWords | undefined {
|
|
63
|
+
return WORDS.get(name);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Built-in tools whose transcript rows this package restyles. */
|
|
67
|
+
export function isPolishedTool(name: string): boolean {
|
|
68
|
+
return WORDS.has(name);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Exploration tools whose settled rows may fold into one tally row. */
|
|
72
|
+
export function isFoldableTool(name: string): boolean {
|
|
73
|
+
return WORDS.get(name)?.tally !== undefined;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Longest subject kept per call; the registry holds one for every folded row of a session. */
|
|
77
|
+
const SUBJECT_LIMIT = 512;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* A path as a comparison key: the spellings Pi's file tools treat as one target
|
|
81
|
+
* — `a.ts`, `./a.ts`, `@a.ts`, `src/../a.ts`, the absolute path under `cwd`,
|
|
82
|
+
* either slash — give one key.
|
|
83
|
+
* Drive-letter paths compare case-insensitively, as their filesystem does.
|
|
84
|
+
* (`~` is left alone: expanding it needs the environment.)
|
|
85
|
+
*/
|
|
86
|
+
function pathKey(path: string, cwd: string): string {
|
|
87
|
+
const key = pathSegments(path, cwd).join("/");
|
|
88
|
+
return /^[a-z]:/i.test(key) ? key.toLowerCase() : key;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The resolved segments of `path` under `cwd`, spelled as given (no case folding). */
|
|
92
|
+
function pathSegments(path: string, cwd: string): string[] {
|
|
93
|
+
const unified = path.replaceAll("\\", "/").replace(/^@/, "");
|
|
94
|
+
const absolute = unified.startsWith("/") || /^[a-z]:\//i.test(unified);
|
|
95
|
+
const segments: string[] = [];
|
|
96
|
+
for (const segment of `${absolute ? "" : `${cwd.replaceAll("\\", "/")}/`}${unified}`.split("/")) {
|
|
97
|
+
if (segment === "..") segments.pop();
|
|
98
|
+
else if (segment && segment !== ".") segments.push(segment);
|
|
99
|
+
}
|
|
100
|
+
return segments;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Longest name kept per call: a basename longer than any row is shown only as a count anyway. */
|
|
104
|
+
const NAME_LIMIT = 128;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* How a detailed tally names a path call: the basename as the model spelled it
|
|
108
|
+
* (`src/../A.ts` → `A.ts`; an absent `ls` path → the cwd's own name). "" for
|
|
109
|
+
* pattern clauses, other tools, and a path that resolves to no name (`/`).
|
|
110
|
+
*/
|
|
111
|
+
export function tallyName(name: string, args: unknown, cwd = ""): string {
|
|
112
|
+
const tally = WORDS.get(name)?.tally;
|
|
113
|
+
if (tally?.subject !== "path") return "";
|
|
114
|
+
const value = textOf(recordOf(args).path).slice(0, SUBJECT_LIMIT);
|
|
115
|
+
if (!value && !tally.cwdWhenAbsent) return "";
|
|
116
|
+
// Sanitized here too, so a name of nothing but controls is no name rather than a gap in the list.
|
|
117
|
+
const base = pathSegments(value || ".", cwd).at(-1) ?? "";
|
|
118
|
+
// A name that would be cut, or that contains the list's own separators, cannot
|
|
119
|
+
// be listed truthfully: no name, and the clause falls back to its count.
|
|
120
|
+
if (base.length > NAME_LIMIT) return "";
|
|
121
|
+
const shown = sanitizeInlineText(base);
|
|
122
|
+
return shown.includes(", ") || shown.includes(" · ") ? "" : shown;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* What a foldable call is about — the path it reads or lists, the pattern it
|
|
127
|
+
* searches — as a bounded comparison key. "" for other tools and for a call
|
|
128
|
+
* that names nothing (each such call then counts on its own).
|
|
129
|
+
*/
|
|
130
|
+
export function tallySubject(name: string, args: unknown, cwd = ""): string {
|
|
131
|
+
const tally = WORDS.get(name)?.tally;
|
|
132
|
+
if (!tally) return "";
|
|
133
|
+
const value = textOf(recordOf(args)[tally.subject]).slice(0, SUBJECT_LIMIT);
|
|
134
|
+
if (tally.subject !== "path") return value;
|
|
135
|
+
if (!value && !tally.cwdWhenAbsent) return "";
|
|
136
|
+
return pathKey(value || ".", cwd) || ".";
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Sentence for a run of exploration calls, clauses in first-appearance order,
|
|
141
|
+
* each counting distinct subjects: two reads of `a.ts`, one of `b.ts`, a grep
|
|
142
|
+
* and a find → "Read 2 files, searched 2 patterns". Calls without a tally
|
|
143
|
+
* clause are ignored; no clauses yields "".
|
|
144
|
+
*/
|
|
145
|
+
export function tallySentence(calls: Iterable<TalliedCall>): string {
|
|
146
|
+
return capitalize(Array.from(tallyClauses(calls), counted).join(", "));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The same run naming its files: each path clause lists its distinct subjects
|
|
151
|
+
* by first-appearance display name, search clauses stay counted, clauses join
|
|
152
|
+
* with " · " — "Read width.ts, frame.ts · searched 2 patterns · listed src".
|
|
153
|
+
* A path clause with a call that has no subject or no name stays counted: a
|
|
154
|
+
* list that silently left one out would read as the whole run. So does one
|
|
155
|
+
* where two files share a basename (`a/index.ts`, `b/index.ts`): "index.ts,
|
|
156
|
+
* index.ts" reads as one file listed twice.
|
|
157
|
+
*/
|
|
158
|
+
export function tallyDetails(calls: Iterable<TalliedCall>): string {
|
|
159
|
+
const clauses = Array.from(tallyClauses(calls));
|
|
160
|
+
const sentence = capitalize(clauses.map(counted).join(", "));
|
|
161
|
+
let listed = false;
|
|
162
|
+
const detailed = capitalize(clauses.map(clause => {
|
|
163
|
+
const names = Array.from(clause.subjects.values());
|
|
164
|
+
if (clause.tally.subject !== "path" || clause.unnamed || !names.every(Boolean) || new Set(names).size !== names.length) return counted(clause);
|
|
165
|
+
listed = true;
|
|
166
|
+
return `${clause.tally.verb} ${names.join(", ")}`;
|
|
167
|
+
}).join(" · "));
|
|
168
|
+
// Nothing to name is the counted sentence itself. Past the limit no row is that
|
|
169
|
+
// wide: the list could only be cut, and a cut list reads as the whole run.
|
|
170
|
+
return listed && detailed.length <= DETAILS_LIMIT ? detailed : sentence;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const DETAILS_LIMIT = 256;
|
|
174
|
+
|
|
175
|
+
interface Clause {
|
|
176
|
+
readonly tally: ToolTally;
|
|
177
|
+
/** Distinct subject key → display name of its first call ("" when it had none). */
|
|
178
|
+
readonly subjects: Map<string, string>;
|
|
179
|
+
unnamed: number;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function tallyClauses(calls: Iterable<TalliedCall>): Iterable<Clause> {
|
|
183
|
+
const clauses = new Map<ToolTally, Clause>();
|
|
184
|
+
for (const call of calls) {
|
|
185
|
+
const tally = WORDS.get(call.name)?.tally;
|
|
186
|
+
if (!tally) continue;
|
|
187
|
+
let clause = clauses.get(tally);
|
|
188
|
+
if (!clause) clauses.set(tally, clause = { tally, subjects: new Map(), unnamed: 0 });
|
|
189
|
+
if (!call.subject) clause.unnamed++;
|
|
190
|
+
else if (!clause.subjects.has(call.subject)) clause.subjects.set(call.subject, call.display ?? "");
|
|
191
|
+
}
|
|
192
|
+
return clauses.values();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function counted({ tally, subjects, unnamed }: Clause): string {
|
|
196
|
+
const count = subjects.size + unnamed;
|
|
197
|
+
return `${tally.verb} ${count} ${count === 1 ? tally.one : tally.many}`;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const capitalize = (sentence: string): string => sentence.charAt(0).toUpperCase() + sentence.slice(1);
|