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
@@ -0,0 +1,33 @@
import { afterEach, describe, expect, it, vi } from "bun:test";
import * as os from "node:os";
import * as path from "node:path";
import { runReadCommand } from "@oh-my-pi/pi-coding-agent/cli/read-cli";
import { Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
import * as scrapers from "@oh-my-pi/pi-coding-agent/web/scrapers/types";
describe("runReadCommand URL handling", () => {
afterEach(() => {
vi.restoreAllMocks();
});
it("delegates URL inputs through the read tool pipeline", async () => {
const cwd = path.join(os.tmpdir(), "read-cli-url-test");
const settings = Settings.isolated({ "fetch.enabled": true });
const pageUrl = "https://example.com/cli-read";
const consoleLogSpy = vi.spyOn(console, "log").mockImplementation(() => {});
vi.spyOn(Settings, "init").mockResolvedValue(settings);
vi.spyOn(scrapers, "loadPage").mockResolvedValue({
ok: true,
status: 200,
contentType: "text/plain",
finalUrl: pageUrl,
content: "CLI URL content",
});
const cwdSpy = vi.spyOn(process, "cwd").mockReturnValue(cwd);
await runReadCommand({ path: pageUrl });
expect(cwdSpy).toHaveBeenCalled();
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining("CLI URL content"));
});
});