Files
oh-my-pi/packages/coding-agent/src/cli/read-cli.ts
T
can1357 fdc3fe1196 refactor(coding-agent): removed configurable read timeout and standardized URL fetch timeout
- Removed the read CLI argument and tool schema field so read requests no longer accept custom timeouts.
- Updated URL read handling to stop forwarding timeout values and execute URL reads without a timeout parameter.
- Standardized URL read fetching to a fixed 30-second timeout and dropped timeout metadata from URL call rendering.
2026-05-07 05:39:22 +02:00

58 lines
1.7 KiB
TypeScript

/**
* Read CLI command handler.
*
* Handles `omp read` — invokes the `read` agent tool against a path/URL and
* prints the resulting content blocks exactly as the model would receive them
* (including truncation/limit notices appended by the meta-notice wrapper).
*/
import { getProjectDir } from "@oh-my-pi/pi-utils";
import chalk from "chalk";
import { Settings } from "../config/settings";
import type { ToolSession } from "../tools";
import { wrapToolWithMetaNotice } from "../tools/output-meta";
import { ReadTool } from "../tools/read";
import { renderError } from "../tools/tool-errors";
export interface ReadCommandArgs {
path: string;
}
export async function runReadCommand(cmd: ReadCommandArgs): Promise<void> {
if (!cmd.path) {
process.stderr.write(chalk.red("error: path is required\n"));
process.exit(1);
}
const cwd = getProjectDir();
const settings = await Settings.init({ cwd });
const session: ToolSession = {
cwd,
hasUI: false,
settings,
getSessionFile: () => null,
getSessionSpawns: () => "*",
};
const tool = wrapToolWithMetaNotice(new ReadTool(session));
try {
const result = await tool.execute("omp-read", { path: cmd.path });
for (const block of result.content) {
if (block.type === "text") {
process.stdout.write(block.text);
if (!block.text.endsWith("\n")) process.stdout.write("\n");
} else if (block.type === "image") {
const decodedBytes = Buffer.from(block.data, "base64").byteLength;
process.stdout.write(
chalk.dim(`[image content: ${block.mimeType}, ${decodedBytes} bytes base64-decoded]\n`),
);
}
}
} catch (err) {
process.stderr.write(`${chalk.red(renderError(err))}\n`);
process.exit(1);
}
}