chore: Lint extensions folder.

This commit is contained in:
cpojer
2026-01-31 22:13:48 +09:00
parent 4f2166c503
commit 230ca789e2
221 changed files with 4006 additions and 1583 deletions

View File

@@ -50,20 +50,30 @@ export default function (pi: ExtensionAPI) {
const files: FileInfo[] = [];
for (const line of lines) {
if (line.length < 4) continue; // Need at least "XY f"
if (line.length < 4) {
continue;
} // Need at least "XY f"
const status = line.slice(0, 2);
const file = line.slice(2).trimStart();
// Translate status codes to short labels
let statusLabel: string;
if (status.includes("M")) statusLabel = "M";
else if (status.includes("A")) statusLabel = "A";
else if (status.includes("D")) statusLabel = "D";
else if (status.includes("?")) statusLabel = "?";
else if (status.includes("R")) statusLabel = "R";
else if (status.includes("C")) statusLabel = "C";
else statusLabel = status.trim() || "~";
if (status.includes("M")) {
statusLabel = "M";
} else if (status.includes("A")) {
statusLabel = "A";
} else if (status.includes("D")) {
statusLabel = "D";
} else if (status.includes("?")) {
statusLabel = "?";
} else if (status.includes("R")) {
statusLabel = "R";
} else if (status.includes("C")) {
statusLabel = "C";
} else {
statusLabel = status.trim() || "~";
}
files.push({ status: statusLabel, statusLabel, file });
}

View File

@@ -40,7 +40,9 @@ export default function (pi: ExtensionAPI) {
const toolCalls = new Map<string, { path: string; name: FileToolName; timestamp: number }>();
for (const entry of branch) {
if (entry.type !== "message") continue;
if (entry.type !== "message") {
continue;
}
const msg = entry.message;
if (msg.role === "assistant" && Array.isArray(msg.content)) {
@@ -62,12 +64,16 @@ export default function (pi: ExtensionAPI) {
const fileMap = new Map<string, FileEntry>();
for (const entry of branch) {
if (entry.type !== "message") continue;
if (entry.type !== "message") {
continue;
}
const msg = entry.message;
if (msg.role === "toolResult") {
const toolCall = toolCalls.get(msg.toolCallId);
if (!toolCall) continue;
if (!toolCall) {
continue;
}
const { path, name } = toolCall;
const timestamp = msg.timestamp;
@@ -94,7 +100,9 @@ export default function (pi: ExtensionAPI) {
}
// Sort by most recent first
const files = Array.from(fileMap.values()).sort((a, b) => b.lastTimestamp - a.lastTimestamp);
const files = Array.from(fileMap.values()).toSorted(
(a, b) => b.lastTimestamp - a.lastTimestamp,
);
const openSelected = async (file: FileEntry): Promise<void> => {
try {
@@ -118,9 +126,15 @@ export default function (pi: ExtensionAPI) {
// Build select items with colored operations
const items: SelectItem[] = files.map((f) => {
const ops: string[] = [];
if (f.operations.has("read")) ops.push(theme.fg("muted", "R"));
if (f.operations.has("write")) ops.push(theme.fg("success", "W"));
if (f.operations.has("edit")) ops.push(theme.fg("warning", "E"));
if (f.operations.has("read")) {
ops.push(theme.fg("muted", "R"));
}
if (f.operations.has("write")) {
ops.push(theme.fg("success", "W"));
}
if (f.operations.has("edit")) {
ops.push(theme.fg("warning", "E"));
}
const opsLabel = ops.join("");
return {
value: f,

View File

@@ -47,7 +47,9 @@ async function fetchGhMetadata(
try {
const result = await pi.exec("gh", args);
if (result.code !== 0 || !result.stdout) return undefined;
if (result.code !== 0 || !result.stdout) {
return undefined;
}
return JSON.parse(result.stdout) as GhMetadata;
} catch {
return undefined;
@@ -55,12 +57,20 @@ async function fetchGhMetadata(
}
function formatAuthor(author?: GhMetadata["author"]): string | undefined {
if (!author) return undefined;
if (!author) {
return undefined;
}
const name = author.name?.trim();
const login = author.login?.trim();
if (name && login) return `${name} (@${login})`;
if (login) return `@${login}`;
if (name) return name;
if (name && login) {
return `${name} (@${login})`;
}
if (login) {
return `@${login}`;
}
if (name) {
return name;
}
return undefined;
}
@@ -77,7 +87,9 @@ export default function promptUrlWidgetExtension(pi: ExtensionAPI) {
const urlLine = thm.fg("dim", match.url);
const lines = [titleText];
if (authorLine) lines.push(authorLine);
if (authorLine) {
lines.push(authorLine);
}
lines.push(urlLine);
const container = new Container();
@@ -103,7 +115,9 @@ export default function promptUrlWidgetExtension(pi: ExtensionAPI) {
};
pi.on("before_agent_start", async (event, ctx) => {
if (!ctx.hasUI) return;
if (!ctx.hasUI) {
return;
}
const match = extractPromptMatch(event.prompt);
if (!match) {
return;
@@ -124,8 +138,12 @@ export default function promptUrlWidgetExtension(pi: ExtensionAPI) {
});
const getUserText = (content: string | { type: string; text?: string }[] | undefined): string => {
if (!content) return "";
if (typeof content === "string") return content;
if (!content) {
return "";
}
if (typeof content === "string") {
return content;
}
return (
content
.filter((block): block is { type: "text"; text: string } => block.type === "text")
@@ -135,11 +153,15 @@ export default function promptUrlWidgetExtension(pi: ExtensionAPI) {
};
const rebuildFromSession = (ctx: ExtensionContext) => {
if (!ctx.hasUI) return;
if (!ctx.hasUI) {
return;
}
const entries = ctx.sessionManager.getEntries();
const lastMatch = [...entries].reverse().find((entry) => {
if (entry.type !== "message" || entry.message.role !== "user") return false;
const lastMatch = [...entries].toReversed().find((entry) => {
if (entry.type !== "message" || entry.message.role !== "user") {
return false;
}
const text = getUserText(entry.message.content);
return !!extractPromptMatch(text);
});

View File

@@ -11,7 +11,9 @@ export default function (pi: ExtensionAPI) {
pi.registerCommand("tui", {
description: "Show TUI stats",
handler: async (_args, ctx) => {
if (!ctx.hasUI) return;
if (!ctx.hasUI) {
return;
}
let redraws = 0;
await ctx.ui.custom<void>((tui, _theme, _keybindings, done) => {
redraws = tui.fullRedraws;