Files
oh-my-pi/packages/coding-agent/src/web/scrapers/tldr.ts
T
can1357 cb5bbbf382 refactor(coding-agent): flattened directory structure, eliminated core/ folder
- Eliminated core/ directory (252 files, 23 subdirs → distributed)
- Reduced max nesting from 9 levels to 5 levels
- Promoted tool subdirs to top level: exa/, lsp/, patch/, task/, web/
- Merged web-scrapers/ + web-search/ into web/{scrapers,search}/
- Flattened modes/interactive/ to modes/
- Split execution/ into: ipy/ (python), exec/ (bash), ssh/
- Renamed ipy/python-*.ts to ipy/*.ts (executor, kernel, etc.)
- Flattened cursor/exec-bridge.ts to cursor.ts
- Created logical groupings: config/, session/, extensibility/, export/
- Updated all imports across 500+ files
2026-01-23 12:24:47 +01:00

52 lines
1.4 KiB
TypeScript

import type { RenderResult, SpecialHandler } from "./types";
import { finalizeOutput, loadPage } from "./types";
const TLDR_BASE = "https://raw.githubusercontent.com/tldr-pages/tldr/main/pages";
const PLATFORMS = ["common", "linux", "osx"] as const;
/**
* Handle tldr page URLs
* - https://tldr.sh/{command}
* - https://tldr.ostera.io/{command}
*/
export const handleTldr: SpecialHandler = async (
url: string,
timeout: number,
signal?: AbortSignal,
): Promise<RenderResult | null> => {
try {
const parsed = new URL(url);
if (parsed.hostname !== "tldr.sh" && parsed.hostname !== "tldr.ostera.io") return null;
// Extract command from path (e.g., /tar -> tar)
const command = parsed.pathname.replace(/^\//, "").replace(/\.md$/, "");
if (!command || command.includes("/")) return null;
const fetchedAt = new Date().toISOString();
// Try platforms in order: common, linux, osx
for (const platform of PLATFORMS) {
const rawUrl = `${TLDR_BASE}/${platform}/${command}.md`;
const result = await loadPage(rawUrl, { timeout, signal });
if (result.ok && result.content.trim()) {
const output = finalizeOutput(result.content);
return {
url,
finalUrl: rawUrl,
contentType: "text/markdown",
method: "tldr",
content: output.content,
fetchedAt,
truncated: output.truncated,
notes: [`Fetched from tldr-pages (${platform})`],
};
}
}
return null;
} catch {}
return null;
};