chore: Enable more lint rules, disable some that trigger a lot. Will clean up later.

This commit is contained in:
cpojer
2026-01-31 16:03:28 +09:00
parent 481f696a87
commit 15792b153f
292 changed files with 643 additions and 699 deletions

View File

@@ -115,7 +115,7 @@ function formatZonedTimestamp(date: Date, timeZone?: string): string | undefined
const hh = pick("hour");
const min = pick("minute");
const tz = [...parts]
.reverse()
.toReversed()
.find((part) => part.type === "timeZoneName")
?.value?.trim();
if (!yyyy || !mm || !dd || !hh || !min) return undefined;

View File

@@ -38,7 +38,7 @@ function formatListTop(
entries: Array<{ name: string; value: number }>,
cap: number,
): { lines: string[]; omitted: number } {
const sorted = [...entries].sort((a, b) => b.value - a.value);
const sorted = [...entries].toSorted((a, b) => b.value - a.value);
const top = sorted.slice(0, cap);
const omitted = Math.max(0, sorted.length - top.length);
const lines = top.map((e) => `- ${e.name}: ${formatCharsAndTokens(e.value)}`);
@@ -263,7 +263,7 @@ export async function buildContextReply(params: HandleCommandsParams): Promise<R
);
const toolPropsLines = report.tools.entries
.filter((t) => t.propertiesCount != null)
.sort((a, b) => (b.propertiesCount ?? 0) - (a.propertiesCount ?? 0))
.toSorted((a, b) => (b.propertiesCount ?? 0) - (a.propertiesCount ?? 0))
.slice(0, 30)
.map((t) => `- ${t.name}: ${t.propertiesCount} params`);

View File

@@ -154,7 +154,7 @@ export async function resolveModelsCommandReply(params: {
add(resolvedDefault.provider, resolvedDefault.model);
addModelConfigEntries();
const providers = [...byProvider.keys()].sort();
const providers = [...byProvider.keys()].toSorted();
if (!provider) {
const lines: string[] = [
@@ -181,7 +181,7 @@ export async function resolveModelsCommandReply(params: {
return { text: lines.join("\n") };
}
const models = [...(byProvider.get(provider) ?? new Set<string>())].sort();
const models = [...(byProvider.get(provider) ?? new Set<string>())].toSorted();
const total = models.length;
if (total === 0) {

View File

@@ -289,7 +289,7 @@ export const handleStopCommand: CommandHandler = async (params, allowTextCommand
params.sessionStore[abortTarget.key] = abortTarget.entry;
if (params.storePath) {
await updateSessionStore(params.storePath, (store) => {
store[abortTarget.key] = abortTarget.entry as SessionEntry;
store[abortTarget.key] = abortTarget.entry;
});
}
} else if (params.command.abortKey) {
@@ -336,7 +336,7 @@ export const handleAbortTrigger: CommandHandler = async (params, allowTextComman
params.sessionStore[abortTarget.key] = abortTarget.entry;
if (params.storePath) {
await updateSessionStore(params.storePath, (store) => {
store[abortTarget.key] = abortTarget.entry as SessionEntry;
store[abortTarget.key] = abortTarget.entry;
});
}
} else if (params.command.abortKey) {

View File

@@ -316,10 +316,10 @@ export const handleSubagentsCommand: CommandHandler = async (params, allowTextCo
reply: { text: `⚠️ ${resolved.error ?? "Unknown subagent."}` },
};
}
const history = (await callGateway({
const history = await callGateway({
method: "chat.history",
params: { sessionKey: resolved.entry.childSessionKey, limit },
})) as { messages?: unknown[] };
});
const rawMessages = Array.isArray(history?.messages) ? history.messages : [];
const filtered = includeTools ? rawMessages : stripToolMessages(rawMessages);
const lines = formatLogLines(filtered as ChatMessage[]);
@@ -349,7 +349,7 @@ export const handleSubagentsCommand: CommandHandler = async (params, allowTextCo
const idempotencyKey = crypto.randomUUID();
let runId: string = idempotencyKey;
try {
const response = (await callGateway({
const response = await callGateway({
method: "agent",
params: {
message,
@@ -360,7 +360,7 @@ export const handleSubagentsCommand: CommandHandler = async (params, allowTextCo
lane: AGENT_LANE_SUBAGENT,
},
timeoutMs: 10_000,
})) as { runId?: string };
});
if (response?.runId) runId = response.runId;
} catch (err) {
const messageText =
@@ -369,11 +369,11 @@ export const handleSubagentsCommand: CommandHandler = async (params, allowTextCo
}
const waitMs = 30_000;
const wait = (await callGateway({
const wait = await callGateway({
method: "agent.wait",
params: { runId, timeoutMs: waitMs },
timeoutMs: waitMs + 2000,
})) as { status?: string; error?: string };
});
if (wait?.status === "timeout") {
return {
shouldContinue: false,
@@ -389,10 +389,10 @@ export const handleSubagentsCommand: CommandHandler = async (params, allowTextCo
};
}
const history = (await callGateway({
const history = await callGateway({
method: "chat.history",
params: { sessionKey: resolved.entry.childSessionKey, limit: 50 },
})) as { messages?: unknown[] };
});
const filtered = stripToolMessages(Array.isArray(history?.messages) ? history.messages : []);
const last = filtered.length > 0 ? filtered[filtered.length - 1] : undefined;
const replyText = last ? extractAssistantText(last) : undefined;

View File

@@ -54,8 +54,7 @@ function resolveExecDefaults(params: {
(agentExec?.ask as ExecAsk | undefined) ??
(globalExec?.ask as ExecAsk | undefined) ??
"on-miss",
node:
(params.sessionEntry?.execNode as string | undefined) ?? agentExec?.node ?? globalExec?.node,
node: params.sessionEntry?.execNode ?? agentExec?.node ?? globalExec?.node,
};
}

View File

@@ -196,8 +196,8 @@ export async function applyInlineDirectiveOverrides(params: {
model,
contextTokens,
resolvedThinkLevel: resolvedDefaultThinkLevel,
resolvedVerboseLevel: (currentVerboseLevel ?? "off") as VerboseLevel,
resolvedReasoningLevel: (currentReasoningLevel ?? "off") as ReasoningLevel,
resolvedVerboseLevel: currentVerboseLevel ?? "off",
resolvedReasoningLevel: currentReasoningLevel ?? "off",
resolvedElevatedLevel,
resolveDefaultThinkingLevel: async () => resolvedDefaultThinkLevel,
isGroup,

View File

@@ -339,20 +339,20 @@ export async function resolveReplyDirectives(params: {
});
const defaultActivation = defaultGroupActivation(requireMention);
const resolvedThinkLevel =
(directives.thinkLevel as ThinkLevel | undefined) ??
directives.thinkLevel ??
(sessionEntry?.thinkingLevel as ThinkLevel | undefined) ??
(agentCfg?.thinkingDefault as ThinkLevel | undefined);
const resolvedVerboseLevel =
(directives.verboseLevel as VerboseLevel | undefined) ??
directives.verboseLevel ??
(sessionEntry?.verboseLevel as VerboseLevel | undefined) ??
(agentCfg?.verboseDefault as VerboseLevel | undefined);
const resolvedReasoningLevel: ReasoningLevel =
(directives.reasoningLevel as ReasoningLevel | undefined) ??
directives.reasoningLevel ??
(sessionEntry?.reasoningLevel as ReasoningLevel | undefined) ??
"off";
const resolvedElevatedLevel = elevatedAllowed
? ((directives.elevatedLevel as ElevatedLevel | undefined) ??
? (directives.elevatedLevel ??
(sessionEntry?.elevatedLevel as ElevatedLevel | undefined) ??
(agentCfg?.elevatedDefault as ElevatedLevel | undefined) ??
"on")

View File

@@ -50,7 +50,7 @@ export function resolveGroupRequireMention(params: {
}
export function defaultGroupActivation(requireMention: boolean): "always" | "mention" {
return requireMention === false ? "always" : "mention";
return !requireMention ? "always" : "mention";
}
export function buildGroupIntro(params: {

View File

@@ -436,7 +436,7 @@ export function resolveModelDirectiveSelection(params: {
});
return Object.assign({ candidate }, details);
})
.sort((a, b) => {
.toSorted((a, b) => {
if (b.score !== a.score) return b.score - a.score;
if (a.isDefault !== b.isDefault) return a.isDefault ? -1 : 1;
if (a.variantMatchCount !== b.variantMatchCount)

View File

@@ -87,7 +87,7 @@ export async function prependSystemEvents(params: {
const min = pick("minute");
const sec = pick("second");
const tz = [...parts]
.reverse()
.toReversed()
.find((part) => part.type === "timeZoneName")
?.value?.trim();
if (!yyyy || !mm || !dd || !hh || !min || !sec) return undefined;

View File

@@ -235,10 +235,9 @@ export async function initSessionState(params: {
const baseEntry = !isNewSession && freshEntry ? entry : undefined;
// Track the originating channel/to for announce routing (subagent announce-back).
const lastChannelRaw = (ctx.OriginatingChannel as string | undefined) || baseEntry?.lastChannel;
const lastToRaw = (ctx.OriginatingTo as string | undefined) || ctx.To || baseEntry?.lastTo;
const lastAccountIdRaw = (ctx.AccountId as string | undefined) || baseEntry?.lastAccountId;
const lastThreadIdRaw =
(ctx.MessageThreadId as string | number | undefined) || baseEntry?.lastThreadId;
const lastToRaw = ctx.OriginatingTo || ctx.To || baseEntry?.lastTo;
const lastAccountIdRaw = ctx.AccountId || baseEntry?.lastAccountId;
const lastThreadIdRaw = ctx.MessageThreadId || baseEntry?.lastThreadId;
const deliveryFields = normalizeSessionDeliveryFields({
deliveryContext: {
channel: lastChannelRaw,

View File

@@ -42,7 +42,7 @@ export function formatRunStatus(entry: SubagentRunRecord) {
}
export function sortSubagentRuns(runs: SubagentRunRecord[]) {
return [...runs].sort((a, b) => {
return [...runs].toSorted((a, b) => {
const aTime = a.startedAt ?? a.createdAt ?? 0;
const bTime = b.startedAt ?? b.createdAt ?? 0;
return bTime - aTime;