@pi-unipi/utility 0.2.6 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -1
- package/package.json +7 -2
- package/src/commands.ts +41 -3
- package/src/diff/highlighter.ts +352 -0
- package/src/diff/parser.ts +191 -0
- package/src/diff/renderer.ts +395 -0
- package/src/diff/settings.ts +199 -0
- package/src/diff/theme.ts +319 -0
- package/src/diff/wrapper.ts +339 -0
- package/src/index.ts +11 -0
- package/src/tui/badge-settings.ts +17 -58
- package/src/tui/util-settings-tui.ts +498 -0
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @pi-unipi/utility — Diff Tool Wrapper
|
|
3
|
+
*
|
|
4
|
+
* Wraps the default Pi write/edit tools with Shiki-powered diff rendering.
|
|
5
|
+
* When enabled, enhanced tools are registered that:
|
|
6
|
+
* 1. Read old content before write
|
|
7
|
+
* 2. Delegate to the original tool
|
|
8
|
+
* 3. Compute diff
|
|
9
|
+
* 4. Store diff in result.details for async rendering
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import * as fs from "node:fs";
|
|
13
|
+
import * as path from "node:path";
|
|
14
|
+
import type { ExtensionAPI, ToolDefinition, AgentToolResult } from "@mariozechner/pi-coding-agent";
|
|
15
|
+
import { visibleWidth as piVisibleWidth, truncateToWidth as piTruncateToWidth } from "@mariozechner/pi-tui";
|
|
16
|
+
import { readDiffSettings } from "./settings.js";
|
|
17
|
+
import { parseDiff } from "./parser.js";
|
|
18
|
+
import { resolveDiffColors, applyDiffPalette } from "./theme.js";
|
|
19
|
+
import { renderSplit, renderUnified, termW, SPLIT_MIN_WIDTH, truncateToTermWidth } from "./renderer.js";
|
|
20
|
+
import { detectLanguageFromPath, hlBlock, MAX_HL_CHARS } from "./highlighter.js";
|
|
21
|
+
|
|
22
|
+
// ─── Types ──────────────────────────────────────────────────────────────────────
|
|
23
|
+
|
|
24
|
+
/** Extended tool result with diff data */
|
|
25
|
+
interface DiffToolDetails {
|
|
26
|
+
/** Old file content (null for new files) */
|
|
27
|
+
oldContent: string | null;
|
|
28
|
+
/** New file content */
|
|
29
|
+
newContent: string;
|
|
30
|
+
/** Parsed diff */
|
|
31
|
+
diff: ReturnType<typeof parseDiff>;
|
|
32
|
+
/** File path */
|
|
33
|
+
filePath: string;
|
|
34
|
+
/** Detected language */
|
|
35
|
+
language: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Edit operation from the edit tool */
|
|
39
|
+
export interface EditOperation {
|
|
40
|
+
oldText: string;
|
|
41
|
+
newText: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ─── Helpers ────────────────────────────────────────────────────────────────────
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Normalize edit tool input to get the list of edit operations.
|
|
48
|
+
* Handles both single-edit and multi-edit parameter formats.
|
|
49
|
+
*/
|
|
50
|
+
export function getEditOperations(input: any): EditOperation[] {
|
|
51
|
+
if (Array.isArray(input?.edits)) {
|
|
52
|
+
return input.edits.map((e: any) => ({
|
|
53
|
+
oldText: e.oldText ?? e.old_text ?? "",
|
|
54
|
+
newText: e.newText ?? e.new_text ?? "",
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
if (input?.oldText !== undefined || input?.old_text !== undefined) {
|
|
58
|
+
return [{
|
|
59
|
+
oldText: input.oldText ?? input.old_text ?? "",
|
|
60
|
+
newText: input.newText ?? input.new_text ?? "",
|
|
61
|
+
}];
|
|
62
|
+
}
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Summarize edit operations into aggregate diff stats.
|
|
68
|
+
*/
|
|
69
|
+
export function summarizeEditOperations(operations: EditOperation[]): {
|
|
70
|
+
totalEdits: number;
|
|
71
|
+
totalAdditions: number;
|
|
72
|
+
totalDeletions: number;
|
|
73
|
+
} {
|
|
74
|
+
let totalAdditions = 0;
|
|
75
|
+
let totalDeletions = 0;
|
|
76
|
+
|
|
77
|
+
for (const op of operations) {
|
|
78
|
+
const oldLines = op.oldText.split("\n");
|
|
79
|
+
const newLines = op.newText.split("\n");
|
|
80
|
+
totalDeletions += oldLines.length;
|
|
81
|
+
totalAdditions += newLines.length;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
totalEdits: operations.length,
|
|
86
|
+
totalAdditions,
|
|
87
|
+
totalDeletions,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Read file content safely. Returns null if file doesn't exist.
|
|
93
|
+
*/
|
|
94
|
+
function readFileSafe(filePath: string): string | null {
|
|
95
|
+
try {
|
|
96
|
+
if (fs.existsSync(filePath)) {
|
|
97
|
+
return fs.readFileSync(filePath, "utf-8");
|
|
98
|
+
}
|
|
99
|
+
} catch {
|
|
100
|
+
// Ignore read errors
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// ─── Tool Registration ──────────────────────────────────────────────────────────
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Register the enhanced write tool that wraps the default with diff rendering.
|
|
109
|
+
*/
|
|
110
|
+
export function registerEnhancedWriteTool(pi: ExtensionAPI, cwd: string): void {
|
|
111
|
+
// We need to re-register a tool with the same name "write" to override it.
|
|
112
|
+
// The approach: register our own tool that reads old content, writes the file,
|
|
113
|
+
// computes the diff, and stores it for rendering.
|
|
114
|
+
|
|
115
|
+
pi.registerTool({
|
|
116
|
+
name: "write",
|
|
117
|
+
label: "Write File",
|
|
118
|
+
description: "Write content to a file at the given path. Creates parent directories if needed. Shows a syntax-highlighted diff of the changes.",
|
|
119
|
+
parameters: {
|
|
120
|
+
type: "object",
|
|
121
|
+
properties: {
|
|
122
|
+
path: { type: "string", description: "Path to the file to write" },
|
|
123
|
+
content: { type: "string", description: "Content to write to the file" },
|
|
124
|
+
},
|
|
125
|
+
required: ["path", "content"],
|
|
126
|
+
} as any,
|
|
127
|
+
async execute(toolCallId: string, params: any, signal: any, _onUpdate: any, _ctx: any): Promise<any> {
|
|
128
|
+
const { path: filePath, content } = params;
|
|
129
|
+
const absolutePath = path.resolve(cwd, filePath);
|
|
130
|
+
const dir = path.dirname(absolutePath);
|
|
131
|
+
|
|
132
|
+
// Read old content before write
|
|
133
|
+
const oldContent = readFileSafe(absolutePath);
|
|
134
|
+
|
|
135
|
+
// Write the file
|
|
136
|
+
if (!fs.existsSync(dir)) {
|
|
137
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
138
|
+
}
|
|
139
|
+
fs.writeFileSync(absolutePath, content, "utf-8");
|
|
140
|
+
|
|
141
|
+
// Compute diff
|
|
142
|
+
const language = detectLanguageFromPath(filePath);
|
|
143
|
+
const diff = parseDiff(oldContent ?? "", content, 3, filePath, filePath);
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
content: [
|
|
147
|
+
{ type: "text", text: `Successfully wrote ${content.length} bytes to ${filePath}` },
|
|
148
|
+
],
|
|
149
|
+
details: {
|
|
150
|
+
oldContent,
|
|
151
|
+
newContent: content,
|
|
152
|
+
diff,
|
|
153
|
+
filePath,
|
|
154
|
+
language,
|
|
155
|
+
} as DiffToolDetails,
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
renderResult(result: any, _options: any, theme: any): any {
|
|
159
|
+
const details = result?.details as DiffToolDetails | undefined;
|
|
160
|
+
if (!details || !details.diff || !details.diff.lines || details.diff.lines.length === 0) {
|
|
161
|
+
// Error or empty-diff case: render the message from result.content so the
|
|
162
|
+
// user sees "Could not find text to replace..." etc. Never return null here
|
|
163
|
+
// because Container.render() will crash on null child.
|
|
164
|
+
const msg = result?.content?.[0]?.text ?? "";
|
|
165
|
+
return {
|
|
166
|
+
setText: () => {},
|
|
167
|
+
text: msg,
|
|
168
|
+
render: (width: number) => (width > 0 ? [msg.slice(0, width)] : [msg]),
|
|
169
|
+
} as any;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
try {
|
|
173
|
+
const dc = resolveDiffColors(theme);
|
|
174
|
+
const tw = termW();
|
|
175
|
+
const max = 60;
|
|
176
|
+
|
|
177
|
+
const rendered: string = tw >= SPLIT_MIN_WIDTH
|
|
178
|
+
? renderSplit(details.diff, details.language, max, dc)
|
|
179
|
+
: renderUnified(details.diff, details.language, max, dc);
|
|
180
|
+
|
|
181
|
+
// Split into lines and cache for width-aware rendering.
|
|
182
|
+
// Each line is already truncated to terminal width by
|
|
183
|
+
// truncateToTermWidth() in the renderer, but we also
|
|
184
|
+
// respect the width parameter from Box.render().
|
|
185
|
+
const cachedLines = rendered.split("\n");
|
|
186
|
+
|
|
187
|
+
return {
|
|
188
|
+
setText: () => {},
|
|
189
|
+
text: rendered,
|
|
190
|
+
render: (width: number) => {
|
|
191
|
+
// If width is provided, re-truncate lines that
|
|
192
|
+
// still exceed it (e.g., inside nested Boxes)
|
|
193
|
+
const maxW = width > 0 ? width : tw;
|
|
194
|
+
return cachedLines.map((line: string) => {
|
|
195
|
+
if (piVisibleWidth(line) > maxW) {
|
|
196
|
+
return piTruncateToWidth(line, maxW, "…");
|
|
197
|
+
}
|
|
198
|
+
return line;
|
|
199
|
+
});
|
|
200
|
+
},
|
|
201
|
+
} as any;
|
|
202
|
+
} catch {
|
|
203
|
+
const fallback = "(diff rendering failed)";
|
|
204
|
+
return {
|
|
205
|
+
setText: () => {},
|
|
206
|
+
text: fallback,
|
|
207
|
+
render: (width: number) => (width > 0 ? [fallback.slice(0, width)] : [fallback]),
|
|
208
|
+
} as any;
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Register the enhanced edit tool that wraps the default with diff rendering.
|
|
216
|
+
*/
|
|
217
|
+
export function registerEnhancedEditTool(pi: ExtensionAPI, cwd: string): void {
|
|
218
|
+
pi.registerTool({
|
|
219
|
+
name: "edit",
|
|
220
|
+
label: "Edit File",
|
|
221
|
+
description: "Edit a file by replacing text. Shows a syntax-highlighted diff of the changes.",
|
|
222
|
+
parameters: {
|
|
223
|
+
type: "object",
|
|
224
|
+
properties: {
|
|
225
|
+
path: { type: "string", description: "Path to the file to edit" },
|
|
226
|
+
edits: {
|
|
227
|
+
type: "array",
|
|
228
|
+
items: {
|
|
229
|
+
type: "object",
|
|
230
|
+
properties: {
|
|
231
|
+
oldText: { type: "string", description: "Text to replace" },
|
|
232
|
+
newText: { type: "string", description: "Replacement text" },
|
|
233
|
+
},
|
|
234
|
+
required: ["oldText", "newText"],
|
|
235
|
+
},
|
|
236
|
+
description: "Array of edit operations",
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
required: ["path", "edits"],
|
|
240
|
+
} as any,
|
|
241
|
+
async execute(toolCallId: string, params: any, signal: any, _onUpdate: any, _ctx: any): Promise<any> {
|
|
242
|
+
const { path: filePath, edits } = params;
|
|
243
|
+
const absolutePath = path.resolve(cwd, filePath);
|
|
244
|
+
|
|
245
|
+
// Read old content
|
|
246
|
+
const oldContent = readFileSafe(absolutePath);
|
|
247
|
+
if (oldContent === null) {
|
|
248
|
+
return {
|
|
249
|
+
content: [{ type: "text", text: `Error: File not found: ${filePath}` }],
|
|
250
|
+
details: undefined,
|
|
251
|
+
isError: true,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Apply edits
|
|
256
|
+
let newContent = oldContent;
|
|
257
|
+
const operations = getEditOperations(params);
|
|
258
|
+
for (const op of operations) {
|
|
259
|
+
const idx = newContent.indexOf(op.oldText);
|
|
260
|
+
if (idx === -1) {
|
|
261
|
+
return {
|
|
262
|
+
content: [{ type: "text", text: `Error: Could not find text to replace in ${filePath}` }],
|
|
263
|
+
details: undefined,
|
|
264
|
+
isError: true,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
newContent = newContent.substring(0, idx) + op.newText + newContent.substring(idx + op.oldText.length);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// Write the modified content
|
|
271
|
+
fs.writeFileSync(absolutePath, newContent, "utf-8");
|
|
272
|
+
|
|
273
|
+
// Compute diff
|
|
274
|
+
const language = detectLanguageFromPath(filePath);
|
|
275
|
+
const diff = parseDiff(oldContent, newContent, 3, filePath, filePath);
|
|
276
|
+
const summary = summarizeEditOperations(operations);
|
|
277
|
+
|
|
278
|
+
return {
|
|
279
|
+
content: [
|
|
280
|
+
{ type: "text", text: `Successfully edited ${filePath} (${summary.totalEdits} edit${summary.totalEdits !== 1 ? "s" : ""})` },
|
|
281
|
+
],
|
|
282
|
+
details: {
|
|
283
|
+
oldContent,
|
|
284
|
+
newContent,
|
|
285
|
+
diff,
|
|
286
|
+
filePath,
|
|
287
|
+
language,
|
|
288
|
+
} as DiffToolDetails,
|
|
289
|
+
};
|
|
290
|
+
},
|
|
291
|
+
renderResult(result: any, _options: any, theme: any): any {
|
|
292
|
+
const details = result?.details as DiffToolDetails | undefined;
|
|
293
|
+
if (!details || !details.diff || !details.diff.lines || details.diff.lines.length === 0) {
|
|
294
|
+
// Error or empty-diff case: render the message from result.content so the
|
|
295
|
+
// user sees "Could not find text to replace..." etc. Never return null here
|
|
296
|
+
// because Container.render() will crash on null child.
|
|
297
|
+
const msg = result?.content?.[0]?.text ?? "";
|
|
298
|
+
return {
|
|
299
|
+
setText: () => {},
|
|
300
|
+
text: msg,
|
|
301
|
+
render: (width: number) => (width > 0 ? [msg.slice(0, width)] : [msg]),
|
|
302
|
+
} as any;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
try {
|
|
306
|
+
const dc = resolveDiffColors(theme);
|
|
307
|
+
const tw = termW();
|
|
308
|
+
const max = 60;
|
|
309
|
+
|
|
310
|
+
const rendered: string = tw >= SPLIT_MIN_WIDTH
|
|
311
|
+
? renderSplit(details.diff, details.language, max, dc)
|
|
312
|
+
: renderUnified(details.diff, details.language, max, dc);
|
|
313
|
+
|
|
314
|
+
const cachedLines = rendered.split("\n");
|
|
315
|
+
|
|
316
|
+
return {
|
|
317
|
+
setText: () => {},
|
|
318
|
+
text: rendered,
|
|
319
|
+
render: (width: number) => {
|
|
320
|
+
const maxW = width > 0 ? width : tw;
|
|
321
|
+
return cachedLines.map((line: string) => {
|
|
322
|
+
if (piVisibleWidth(line) > maxW) {
|
|
323
|
+
return piTruncateToWidth(line, maxW, "…");
|
|
324
|
+
}
|
|
325
|
+
return line;
|
|
326
|
+
});
|
|
327
|
+
},
|
|
328
|
+
} as any;
|
|
329
|
+
} catch {
|
|
330
|
+
const fallback = "(diff rendering failed)";
|
|
331
|
+
return {
|
|
332
|
+
setText: () => {},
|
|
333
|
+
text: fallback,
|
|
334
|
+
render: (width: number) => (width > 0 ? [fallback.slice(0, width)] : [fallback]),
|
|
335
|
+
} as any;
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
});
|
|
339
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -25,6 +25,8 @@ import {
|
|
|
25
25
|
import { registerUtilityCommands, registerNameBadgeCommands } from "./commands.js";
|
|
26
26
|
import { NameBadgeState } from "./tui/name-badge-state.js";
|
|
27
27
|
import { readBadgeSettings } from "./tui/badge-settings.js";
|
|
28
|
+
import { readDiffSettings } from "./diff/settings.js";
|
|
29
|
+
import { registerEnhancedWriteTool, registerEnhancedEditTool } from "./diff/wrapper.js";
|
|
28
30
|
import { getLifecycle } from "./lifecycle/process.js";
|
|
29
31
|
import { getAnalyticsCollector } from "./analytics/collector.js";
|
|
30
32
|
import { registerInfoScreen } from "./info-screen.js";
|
|
@@ -56,6 +58,7 @@ const ALL_COMMANDS = [
|
|
|
56
58
|
UTILITY_COMMANDS.BADGE_GEN,
|
|
57
59
|
UTILITY_COMMANDS.BADGE_TOGGLE,
|
|
58
60
|
UTILITY_COMMANDS.BADGE_SETTINGS,
|
|
61
|
+
UTILITY_COMMANDS.UTIL_SETTINGS,
|
|
59
62
|
].map((cmd) => `unipi:${cmd}`);
|
|
60
63
|
|
|
61
64
|
/** All tools registered by this module */
|
|
@@ -102,6 +105,14 @@ export default function (pi: ExtensionAPI) {
|
|
|
102
105
|
// Restore name badge if it was visible in previous session
|
|
103
106
|
await nameBadgeState.restore(pi, ctx);
|
|
104
107
|
|
|
108
|
+
// Register diff-enhanced tools if enabled
|
|
109
|
+
const diffSettings = readDiffSettings();
|
|
110
|
+
if (diffSettings.enabled) {
|
|
111
|
+
const cwd = process.cwd();
|
|
112
|
+
registerEnhancedWriteTool(pi, cwd);
|
|
113
|
+
registerEnhancedEditTool(pi, cwd);
|
|
114
|
+
}
|
|
115
|
+
|
|
105
116
|
// Write model cache for TUI components
|
|
106
117
|
if ((ctx as any).modelRegistry) {
|
|
107
118
|
const { writeModelCache } = await import("@pi-unipi/core");
|
|
@@ -1,78 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @pi-unipi/utility — Badge Settings Manager
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Thin wrappers over the unified settings manager (util-settings.json).
|
|
5
|
+
* Existing callers continue to work unchanged.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import
|
|
9
|
-
|
|
8
|
+
import {
|
|
9
|
+
readUtilSettings,
|
|
10
|
+
writeUtilSettings,
|
|
11
|
+
type BadgeSettingsSection,
|
|
12
|
+
} from "../diff/settings.js";
|
|
10
13
|
|
|
11
|
-
/** Badge settings interface */
|
|
12
|
-
export
|
|
13
|
-
/** Auto-generate session name on first user message */
|
|
14
|
-
autoGen: boolean;
|
|
15
|
-
/** Show the badge overlay */
|
|
16
|
-
badgeEnabled: boolean;
|
|
17
|
-
/** Enable the set_session_name tool for agents */
|
|
18
|
-
agentTool: boolean;
|
|
19
|
-
/** Model to use for badge name generation. "inherit" = parent model, or "provider/model-id" */
|
|
20
|
-
generationModel: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** Default badge settings */
|
|
24
|
-
const DEFAULT_SETTINGS: BadgeSettings = {
|
|
25
|
-
autoGen: true,
|
|
26
|
-
badgeEnabled: true,
|
|
27
|
-
agentTool: true,
|
|
28
|
-
generationModel: "inherit",
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
/** Badge settings file name */
|
|
32
|
-
const BADGE_CONFIG_FILE = ".unipi/config/badge.json";
|
|
14
|
+
/** Badge settings interface (re-exports BadgeSettingsSection for backward compat) */
|
|
15
|
+
export type BadgeSettings = BadgeSettingsSection;
|
|
33
16
|
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
*/
|
|
37
|
-
function getConfigPath(): string {
|
|
38
|
-
return path.resolve(process.cwd(), BADGE_CONFIG_FILE);
|
|
39
|
-
}
|
|
17
|
+
/** Default badge settings for formatBadgeSettings display */
|
|
18
|
+
const BADGE_CONFIG_FILE = ".unipi/config/util-settings.json";
|
|
40
19
|
|
|
41
20
|
/**
|
|
42
|
-
* Read badge settings from
|
|
21
|
+
* Read badge settings from unified config.
|
|
43
22
|
* Returns defaults if file doesn't exist or is malformed.
|
|
44
23
|
*/
|
|
45
24
|
export function readBadgeSettings(): BadgeSettings {
|
|
46
|
-
|
|
47
|
-
const configPath = getConfigPath();
|
|
48
|
-
if (!fs.existsSync(configPath)) return { ...DEFAULT_SETTINGS };
|
|
49
|
-
const parsed = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
50
|
-
return {
|
|
51
|
-
autoGen: typeof parsed.autoGen === "boolean" ? parsed.autoGen : DEFAULT_SETTINGS.autoGen,
|
|
52
|
-
badgeEnabled: typeof parsed.badgeEnabled === "boolean" ? parsed.badgeEnabled : DEFAULT_SETTINGS.badgeEnabled,
|
|
53
|
-
agentTool: typeof parsed.agentTool === "boolean" ? parsed.agentTool : DEFAULT_SETTINGS.agentTool,
|
|
54
|
-
generationModel: typeof parsed.generationModel === "string" ? parsed.generationModel : DEFAULT_SETTINGS.generationModel,
|
|
55
|
-
};
|
|
56
|
-
} catch {
|
|
57
|
-
return { ...DEFAULT_SETTINGS };
|
|
58
|
-
}
|
|
25
|
+
return readUtilSettings().badge;
|
|
59
26
|
}
|
|
60
27
|
|
|
61
28
|
/**
|
|
62
|
-
* Write badge settings to
|
|
63
|
-
* Creates .unipi/config/ directory if needed.
|
|
29
|
+
* Write badge settings to unified config.
|
|
64
30
|
*/
|
|
65
31
|
export function writeBadgeSettings(settings: BadgeSettings): void {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (!fs.existsSync(dir)) {
|
|
70
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
71
|
-
}
|
|
72
|
-
fs.writeFileSync(configPath, JSON.stringify(settings, null, 2) + "\n", "utf-8");
|
|
73
|
-
} catch {
|
|
74
|
-
// Best effort
|
|
75
|
-
}
|
|
32
|
+
const util = readUtilSettings();
|
|
33
|
+
util.badge = settings;
|
|
34
|
+
writeUtilSettings(util);
|
|
76
35
|
}
|
|
77
36
|
|
|
78
37
|
/**
|