Skip to content

Conversation

@konard
Copy link
Collaborator

@konard konard commented Dec 9, 2025

Summary

This PR implements CLI support for web-capture, allowing it to work both as a local command for AI agents and as an HTTP API server. The implementation uses the lino-arguments pattern for unified configuration management.

Key Features

  • Server Mode: web-capture --serve starts the HTTP API server
  • Capture Mode: web-capture <url> captures a URL to file or stdout
  • Multiple Formats: Support for HTML, Markdown, and PNG screenshot output
  • Browser Engine Selection: Choose between Puppeteer and Playwright engines
  • Unified Configuration: Uses lino-arguments for CLI args, env vars, and .lenv files
  • Comprehensive CLI Options: --format, --output, --engine, --port, --configuration

Implementation Details

New Files

  • bin/web-capture.js - CLI entry point using lino-arguments pattern
  • .lenv - Default configuration file with PORT and BROWSER_ENGINE settings
  • tests/unit/cli.test.js - Unit tests for CLI functionality

Modified Files

  • package.json - Added bin field for CLI, added lino-arguments dependency, bumped version to 1.1.0
  • README.md - Added CLI usage documentation, configuration section, and examples

Configuration System

Uses lino-arguments with the following priority chain (highest to lowest):

  1. CLI arguments: --port 8080
  2. Environment variables: PORT=8080
  3. Custom .lenv file: --configuration path/to/custom.lenv
  4. Default .lenv file: .lenv in project root
  5. Built-in defaults

.lenv File Format

# Server configuration
PORT: 3000

# Browser engine (puppeteer or playwright)
BROWSER_ENGINE: puppeteer

CLI Usage

Server Mode

# Start API server on default port 3000
web-capture --serve

# Start on custom port
web-capture --serve --port 8080

# Use custom configuration file
web-capture --serve --configuration /path/to/custom.lenv

Capture Mode

# Capture URL as HTML to stdout
web-capture https://example.com

# Capture as Markdown to file
web-capture https://example.com --format markdown --output page.md

# Take screenshot using Playwright engine
web-capture https://example.com --format png --engine playwright -o screenshot.png

# Use environment variable for configuration
PORT=8080 web-capture --serve

All Options

-c, --configuration  Path to .lenv configuration file
-s, --serve          Start as HTTP API server
-p, --port           Port for server mode (default: 3000)
-f, --format         Output format: html, markdown/md, image/png
-o, --output         Output file path
-e, --engine         Browser engine: puppeteer, playwright
-h, --help           Show help
-v, --version        Show version

Testing

All CLI tests pass (15 tests):

  • Help message display with --help and -h flags
  • Version display with --version and -v flags
  • URL validation and error handling
  • Format, engine, and output option documentation
  • Server mode option documentation
  • Configuration system integration

Unit tests verify the CLI argument parsing and help output work correctly with the lino-arguments/yargs integration.

Fixes

Fixes #19


🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #19
@konard konard self-assigned this Dec 9, 2025
- Add bin/web-capture.js CLI entry point supporting two modes:
  - Server mode: `web-capture --serve` starts HTTP API server
  - Capture mode: `web-capture <url>` captures URL to file/stdout
- CLI options: --format (html/markdown/png), --output, --engine, --port
- Add unit tests for CLI argument parsing and help/version commands
- Update README with CLI usage documentation and examples
- Bump version to 1.1.0

Fixes #19

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Add support for CLI that works in both like local command for AI agent to use and is able to be a server feat: add CLI support for local command and server mode Dec 9, 2025
@konard konard marked this pull request as ready for review December 9, 2025 05:02
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard
Copy link
Collaborator Author

konard commented Dec 9, 2025

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $2.637984 USD
  • Calculated by Anthropic: $1.561243 USD
  • Difference: $-1.076741 (-40.82%)
    📎 Log file uploaded as GitHub Gist (371KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Collaborator Author

konard commented Dec 9, 2025

🔄 Auto-restart 1/3

Detected uncommitted changes from previous run. Starting new session to review and commit them.

Uncommitted files:

M yarn.lock
?? package-lock.json

Auto-restart will stop after changes are committed or after 2 more iterations. Please wait until working session will end and give your feedback.

@konard
Copy link
Collaborator Author

konard commented Dec 9, 2025

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $1.759815 USD
  • Calculated by Anthropic: $0.780148 USD
  • Difference: $-0.979668 (-55.67%)
    📎 Log file uploaded as GitHub Gist (635KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Collaborator Author

konard commented Dec 9, 2025

Please use https://github.com/link-foundation/lino-arguments pattern for arguments and configuration

@konard konard marked this pull request as draft December 9, 2025 05:28
@konard
Copy link
Collaborator Author

konard commented Dec 9, 2025

🤖 AI Work Session Started

Starting automated work session at 2025-12-09T05:28:34.064Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback.

- Install lino-arguments package for unified configuration management
- Create .lenv file with default configuration (PORT, BROWSER_ENGINE)
- Refactor bin/web-capture.js to use makeConfig from lino-arguments
- Replace custom argument parsing with yargs-based configuration
- Update CLI tests to work with new yargs output format
- Add configuration documentation to README with priority chain

Configuration priority (highest to lowest):
1. CLI arguments (--port 8080)
2. Environment variables (PORT=8080)
3. Custom .lenv file (--configuration path/to/custom.lenv)
4. Default .lenv file
5. Built-in defaults

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard marked this pull request as ready for review December 9, 2025 05:33
@konard
Copy link
Collaborator Author

konard commented Dec 9, 2025

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $1.247949 USD
  • Calculated by Anthropic: $0.706584 USD
  • Difference: $-0.541365 (-43.38%)
    📎 Log file uploaded as GitHub Gist (380KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Collaborator Author

konard commented Dec 11, 2025

Also make sure our Dockerfile and other files use new web-capture --serve.

@konard konard marked this pull request as draft December 11, 2025 00:18
@konard
Copy link
Collaborator Author

konard commented Dec 11, 2025

🤖 AI Work Session Started

Starting automated work session at 2025-12-11T00:18:38.313Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback.

Updated all references from direct node execution to use the new
web-capture CLI command for consistency and better user experience.

Changes:
- Dockerfile: Changed ENTRYPOINT from "node src/index.js" to "node bin/web-capture.js --serve"
- package.json: Updated dev script to use CLI command with nodemon
- tests/e2e/process.test.js: Updated to spawn CLI command instead of direct node execution
- ARCHITECTURE.md: Updated documentation to reflect new CLI usage in Dockerfile example

This ensures the Dockerfile and all related files use the new unified
CLI interface as requested in PR feedback.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard marked this pull request as ready for review December 11, 2025 00:23
@konard
Copy link
Collaborator Author

konard commented Dec 11, 2025

✅ Updated to use new CLI command

I've updated all files to use the new web-capture --serve command as requested:

Changes Made

  1. Dockerfile (line 45)

    • Changed: ENTRYPOINT ["node", "src/index.js"]
    • To: ENTRYPOINT ["node", "bin/web-capture.js", "--serve"]
  2. package.json (line 11)

    • Changed: "dev": "nodemon src/index.js"
    • To: "dev": "nodemon bin/web-capture.js -- --serve"
  3. tests/e2e/process.test.js (line 14)

    • Changed: spawn('node', [path.resolve('src/index.js')])
    • To: spawn('node', [path.resolve('bin/web-capture.js'), '--serve'])
  4. ARCHITECTURE.md (line 518)

    • Updated documentation example to reflect new CLI usage

Testing

  • ✅ CLI help works correctly: node bin/web-capture.js --help
  • ✅ Server starts successfully: node bin/web-capture.js --serve
  • ✅ Unit tests passing (15 CLI tests, 11 conversion tests, 3 URL tests, 15 mock tests)
  • ⚠️ E2E tests skipped (require Playwright browsers installation and Docker)

All files now consistently use the new unified CLI interface. The PR is ready for review.

@konard
Copy link
Collaborator Author

konard commented Dec 11, 2025

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $1.701392 USD
  • Calculated by Anthropic: $1.018824 USD
  • Difference: $-0.682568 (-40.12%)
    📎 Log file uploaded as GitHub Gist (418KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for CLI that works in both like local command for AI agent to use and is able to be a server

2 participants