feat(coding-agent): added URL selectors with :raw and line range syntax to read command

- Added support for embedded URL selectors with `:raw` and `:L#-L#` line range syntax in read command.
- Implemented `parseReadUrlTarget()` function to parse and validate URL read targets with line range support.
- Updated read CLI to delegate URL inputs through read tool pipeline instead of treating as local file paths.
- Added comprehensive test coverage for URL selector parsing and CLI URL delegation.
- Refactored URL handling in read tool to use structured `ParsedReadUrlTarget` object.
This commit is contained in:
can1357
2026-04-08 19:47:28 +02:00
parent 3cf7d1adc8
commit 9bb1683445
6 changed files with 242 additions and 20 deletions
+29 -4
View File
@@ -1,21 +1,47 @@
/**
* Read CLI command handler.
*
* Handles `omp read` subcommand — emits chunk-mode read output for a file.
* Handles `omp read` subcommand — emits chunk-mode read output for files,
* and delegates URL reads through the read tool pipeline.
*/
import * as path from "node:path";
import chalk from "chalk";
import { Settings } from "../config/settings";
import { formatChunkedRead, resolveAnchorStyle } from "../edit/modes/chunk";
import { getLanguageFromPath } from "../modes/theme/theme";
import type { ToolSession } from "../tools";
import { parseReadUrlTarget } from "../tools/fetch";
import { ReadTool } from "../tools/read";
export interface ReadCommandArgs {
path: string;
sel?: string;
}
export async function runReadCommand(cmd: ReadCommandArgs): Promise<void> {
const filePath = path.resolve(cmd.path);
function createCliReadSession(cwd: string, settings: Settings): ToolSession {
return {
cwd,
hasUI: false,
hasEditTool: true,
getSessionFile: () => null,
getSessionSpawns: () => null,
settings,
};
}
export async function runReadCommand(cmd: ReadCommandArgs): Promise<void> {
const cwd = process.cwd();
const parsedUrlTarget = parseReadUrlTarget(cmd.path, cmd.sel);
if (parsedUrlTarget) {
const settings = await Settings.init({ cwd });
const tool = new ReadTool(createCliReadSession(cwd, settings));
const result = await tool.execute("cli-read", { path: cmd.path, sel: cmd.sel });
const text = result.content.find((content): content is { type: "text"; text: string } => content.type === "text");
console.log(text?.text ?? "");
return;
}
const filePath = path.resolve(cmd.path);
const file = Bun.file(filePath);
if (!(await file.exists())) {
console.error(chalk.red(`Error: File not found: ${cmd.path}`));
@@ -24,7 +50,6 @@ export async function runReadCommand(cmd: ReadCommandArgs): Promise<void> {
const readPath = cmd.sel ? `${filePath}:${cmd.sel}` : filePath;
const language = getLanguageFromPath(filePath);
const cwd = process.cwd();
try {
const result = await formatChunkedRead({