Enable more biome lints and fix things

This commit is contained in:
Mario Zechner 2025-12-21 22:56:20 +01:00
parent 9c18439c4d
commit d5fd685901
57 changed files with 151 additions and 199 deletions

View file

@ -20,26 +20,6 @@ import { createMomTools, setUploadFunction } from "./tools/index.js";
// Hardcoded model for now - TODO: make configurable (issue #63)
const model = getModel("anthropic", "claude-sonnet-4-5");
/**
* Convert Date.now() to Slack timestamp format (seconds.microseconds)
* Uses a monotonic counter to ensure ordering even within the same millisecond
*/
let lastTsMs = 0;
let tsCounter = 0;
function toSlackTs(): string {
const now = Date.now();
if (now === lastTsMs) {
tsCounter++;
} else {
lastTsMs = now;
tsCounter = 0;
}
const seconds = Math.floor(now / 1000);
const micros = (now % 1000) * 1000 + tsCounter;
return `${seconds}.${micros.toString().padStart(6, "0")}`;
}
export interface PendingMessage {
userName: string;
text: string;
@ -85,7 +65,7 @@ function getMemory(channelDir: string): string {
try {
const content = readFileSync(workspaceMemoryPath, "utf-8").trim();
if (content) {
parts.push("### Global Workspace Memory\n" + content);
parts.push(`### Global Workspace Memory\n${content}`);
}
} catch (error) {
log.logWarning("Failed to read workspace memory", `${workspaceMemoryPath}: ${error}`);
@ -98,7 +78,7 @@ function getMemory(channelDir: string): string {
try {
const content = readFileSync(channelMemoryPath, "utf-8").trim();
if (content) {
parts.push("### Channel-Specific Memory\n" + content);
parts.push(`### Channel-Specific Memory\n${content}`);
}
} catch (error) {
log.logWarning("Failed to read channel memory", `${channelMemoryPath}: ${error}`);
@ -340,7 +320,7 @@ Each tool requires a "label" parameter (shown to user).
function truncate(text: string, maxLen: number): string {
if (text.length <= maxLen) return text;
return text.substring(0, maxLen - 3) + "...";
return `${text.substring(0, maxLen - 3)}...`;
}
function extractToolResultText(result: unknown): string {
@ -530,8 +510,8 @@ function createRunner(sandboxConfig: SandboxConfig, channelId: string, channelDi
let threadMessage = `*${agentEvent.isError ? "✗" : "✓"} ${agentEvent.toolName}*`;
if (label) threadMessage += `: ${label}`;
threadMessage += ` (${duration}s)\n`;
if (argsFormatted) threadMessage += "```\n" + argsFormatted + "\n```\n";
threadMessage += "*Result:*\n```\n" + resultStr + "\n```";
if (argsFormatted) threadMessage += `\`\`\`\n${argsFormatted}\n\`\`\`\n`;
threadMessage += `*Result:*\n\`\`\`\n${resultStr}\n\`\`\``;
queue.enqueueMessage(threadMessage, "thread", "tool result thread", false);
@ -804,7 +784,7 @@ function createRunner(sandboxConfig: SandboxConfig, channelId: string, channelDi
try {
const mainText =
finalText.length > SLACK_MAX_LENGTH
? finalText.substring(0, SLACK_MAX_LENGTH - 50) + "\n\n_(see thread for full response)_"
? `${finalText.substring(0, SLACK_MAX_LENGTH - 50)}\n\n_(see thread for full response)_`
: finalText;
await ctx.replaceMessage(mainText);
} catch (err) {

View file

@ -92,7 +92,7 @@ export class MomSessionManager {
};
this.inMemoryEntries.push(entry);
appendFileSync(this.contextFile, JSON.stringify(entry) + "\n");
appendFileSync(this.contextFile, `${JSON.stringify(entry)}\n`);
}
/**
@ -215,7 +215,7 @@ export class MomSessionManager {
};
this.inMemoryEntries.push(entry);
appendFileSync(this.contextFile, JSON.stringify(entry) + "\n");
appendFileSync(this.contextFile, `${JSON.stringify(entry)}\n`);
}
}
@ -270,9 +270,9 @@ export class MomSessionManager {
this.pendingEntries = [];
// Write to file
appendFileSync(this.contextFile, JSON.stringify(entry) + "\n");
appendFileSync(this.contextFile, `${JSON.stringify(entry)}\n`);
for (const memEntry of this.inMemoryEntries.slice(1)) {
appendFileSync(this.contextFile, JSON.stringify(memEntry) + "\n");
appendFileSync(this.contextFile, `${JSON.stringify(memEntry)}\n`);
}
}
@ -287,7 +287,7 @@ export class MomSessionManager {
this.pendingEntries.push(entry);
} else {
this.inMemoryEntries.push(entry);
appendFileSync(this.contextFile, JSON.stringify(entry) + "\n");
appendFileSync(this.contextFile, `${JSON.stringify(entry)}\n`);
}
}
@ -302,7 +302,7 @@ export class MomSessionManager {
this.pendingEntries.push(entry);
} else {
this.inMemoryEntries.push(entry);
appendFileSync(this.contextFile, JSON.stringify(entry) + "\n");
appendFileSync(this.contextFile, `${JSON.stringify(entry)}\n`);
}
}
@ -318,13 +318,13 @@ export class MomSessionManager {
this.pendingEntries.push(entry);
} else {
this.inMemoryEntries.push(entry);
appendFileSync(this.contextFile, JSON.stringify(entry) + "\n");
appendFileSync(this.contextFile, `${JSON.stringify(entry)}\n`);
}
}
saveCompaction(entry: CompactionEntry): void {
this.inMemoryEntries.push(entry);
appendFileSync(this.contextFile, JSON.stringify(entry) + "\n");
appendFileSync(this.contextFile, `${JSON.stringify(entry)}\n`);
}
/** Load session with compaction support */
@ -587,7 +587,6 @@ export function syncLogToContext(channelDir: string, excludeAfterTs?: string): n
if (logMessages.length === 0) return 0;
// Read existing timestamps from context.jsonl
const existingTs = new Set<string>();
if (existsSync(contextFile)) {
const contextContent = readFileSync(contextFile, "utf-8");
const contextLines = contextContent.trim().split("\n").filter(Boolean);
@ -656,7 +655,7 @@ export function syncLogToContext(channelDir: string, excludeAfterTs?: string): n
mkdirSync(channelDir, { recursive: true });
}
appendFileSync(contextFile, JSON.stringify(entry) + "\n");
appendFileSync(contextFile, `${JSON.stringify(entry)}\n`);
existingMessages.add(content); // Track to avoid duplicates within this sync
syncedCount++;
}

View file

@ -27,7 +27,7 @@ function formatContext(ctx: LogContext): string {
function truncate(text: string, maxLen: number): string {
if (text.length <= maxLen) return text;
return text.substring(0, maxLen) + `\n(truncated at ${maxLen} chars)`;
return `${text.substring(0, maxLen)}\n(truncated at ${maxLen} chars)`;
}
function formatToolArgs(args: Record<string, unknown>): string {
@ -200,9 +200,9 @@ export function logUsageSummary(
): string {
const formatTokens = (count: number): string => {
if (count < 1000) return count.toString();
if (count < 10000) return (count / 1000).toFixed(1) + "k";
if (count < 1000000) return Math.round(count / 1000) + "k";
return (count / 1000000).toFixed(1) + "M";
if (count < 10000) return `${(count / 1000).toFixed(1)}k`;
if (count < 1000000) return `${Math.round(count / 1000)}k`;
return `${(count / 1000000).toFixed(1)}M`;
};
const lines: string[] = [];

View file

@ -144,7 +144,7 @@ function createSlackContext(event: SlackEvent, slack: SlackBot, state: ChannelSt
respond: async (text: string, shouldLog = true) => {
updatePromise = updatePromise.then(async () => {
accumulatedText = accumulatedText ? accumulatedText + "\n" + text : text;
accumulatedText = accumulatedText ? `${accumulatedText}\n${text}` : text;
const displayText = isWorking ? accumulatedText + workingIndicator : accumulatedText;
if (messageTs) {

View file

@ -220,7 +220,7 @@ export class SlackBot {
logToFile(channel: string, entry: object): void {
const dir = join(this.workingDir, channel);
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
appendFileSync(join(dir, "log.jsonl"), JSON.stringify(entry) + "\n");
appendFileSync(join(dir, "log.jsonl"), `${JSON.stringify(entry)}\n`);
}
/**

View file

@ -139,7 +139,7 @@ export class ChannelStore {
message.date = date.toISOString();
}
const line = JSON.stringify(message) + "\n";
const line = `${JSON.stringify(message)}\n`;
await appendFile(logPath, line, "utf-8");
return true;
}