Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/db/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const MIGRATIONS_DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), '
* once: the whole run happens inside one write transaction (BEGIN IMMEDIATE).
*/
export async function migrate(db: Db, log: (msg: string) => void = () => {}): Promise<string[]> {
const files = (await readdir(MIGRATIONS_DIR)).filter((f) => f.endsWith('.sql')).sort();
const files = (await readdir(MIGRATIONS_DIR)).filter((f) => f.endsWith('.sql')).sort((a, b) => Number(a > b) - Number(a < b));
const scripts = await Promise.all(files.map(async (f) => [f, await readFile(path.join(MIGRATIONS_DIR, f), 'utf8')] as const));
return db.transaction(async (tx) => {
await tx.query('CREATE TABLE IF NOT EXISTS schema_migrations (name TEXT PRIMARY KEY, applied_at INTEGER NOT NULL DEFAULT (now_ms()))');
Expand Down
9 changes: 8 additions & 1 deletion src/triage/knowledge-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ const cut = (text: string, max: number) => {
return t.length > max ? `${t.slice(0, max - 1)}…` : t;
};

/** `line` without its trailing spaces and tabs. */
function trimEndSpaces(line: string): string {
let end = line.length;
while (end > 0 && (line[end - 1] === ' ' || line[end - 1] === '\t')) end--;
return line.slice(0, end);
}

/** A document without its badges, images, HTML and comments, cut to size. */
export function cleanDoc(text: string, max: number): string {
return text
Expand All @@ -142,7 +149,7 @@ export function cleanDoc(text: string, max: number): string {
.replace(/\[\s*\]\([^)]*\)/g, '')
.replace(/<img[^>]*>/gi, '')
.replace(/<\/?(p|div|span|a|br|picture|source|img|h\d|center|details|summary|sup|sub|b|i)\b[^>]*>/gi, '')
.split('\n').map((l) => l.replace(/[ \t]+$/, '')).join('\n')
.split('\n').map(trimEndSpaces).join('\n')
.replace(/\n{3,}/g, '\n\n')
.trim()
.slice(0, max);
Expand Down
2 changes: 1 addition & 1 deletion src/web/routes/health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ async function gather(web: Web, ctx: WorkspaceRequestContext) {
const [repos, names] = await Promise.all([indexStatus(deps.db, [...new Set(apps.map((a) => a.repo_id))]), userNames(deps.db, [dev.by])]);
const github = h.running.map((p) => p.stats?.github).filter((g): g is NonNullable<typeof g> => Boolean(g)).sort((a, b) => b.at.localeCompare(a.at))[0] ?? null;
const count = (s: string) => filing.find((f) => f.status === s)?.n ?? 0;
const oldestQueued = filing.filter((f) => f.status === 'pending' || f.status === 'processing').map((f) => f.oldest).filter((n): n is number => n !== null).sort()[0] ?? null;
const oldestQueued = filing.filter((f) => f.status === 'pending' || f.status === 'processing').map((f) => f.oldest).filter((n): n is number => n !== null).sort((a, b) => a - b)[0] ?? null;
return { dev: { ...dev, byName: dev.by ? names.get(dev.by) ?? null : null }, h, samples, disk, dbBytes: dbFile + walFile, files, filing: { queued: count('pending') + count('processing'), unconfirmed: count('uncertain'), failed: count('failed'), failedDay, filedDay, oldestQueued }, triage, triageCounts, repos, cleanup, claude, github };
}

Expand Down
Loading