Skip to main content

Natural language to URI resolution and cross-platform local URI execution

Project description

nlp2uri

AI Cost Tracking

PyPI Version Python License AI Cost Human Time Model

  • 🤖 LLM usage: $1.0267 (3 commits)
  • 👤 Human dev: ~$200 (2.0h @ $100/h, 30min dedup)

Generated on 2026-06-06 using openrouter/qwen/qwen3-coder-next


Python library and CLI — kompilator NL → URI → akcje OS dla operacji desktopowych.

Wejście (naturalny język):

  • „otwórz VS Code w folderze ~/projekty/nlp2uri”
  • „zrób screenshot aktywnego okna przeglądarki”
  • „otwórz plik invoice-2025.pdf”

Wyjście:

  1. Abstrakcyjny URI (RFC 3986, niezależny od OS)
  2. Plan akcji OSAction[] — konkretne komendy per platforma
  3. (Opcjonalnie) wykonanie lub payload MCP (text/uri-list)

Architektura

flowchart LR
    NL[Natural language] --> PARSE[parse_nl]
    PARSE --> INTENT[UriIntent + slots]
    INTENT --> BUILD[schemes/build]
    BUILD --> SPEC[UriSpec abstract URI]
    SPEC --> COMPILE[compile_uri_to_actions]
    COMPILE --> ACTIONS[OSAction plan]
    ACTIONS --> EXEC[execute_uri / MCP]

Warstwy

Warstwa Moduł Opis
NLP → intencja parse_nl Heurystyki EN + PL → UriIntent
Intencja → URI schemes/* Abstrakcyjne schemy OS-neutral
URI → OS compile compile_uri_to_actions()
Wykonanie runtime subprocess / dry-run
MCP mcp text/uri-list, tool payloads

Abstrakcyjne schemy URI

Scheme Przykład Znaczenie
app:// app://vscode/open?path=/home/tom/... Otwórz aplikację / IDE
app://file/open app://file/open?path=/tmp/x.pdf Otwórz plik
desktop-screenshot:// desktop-screenshot://window?title=Chrome&mode=active Screenshot okna/ekranu
desktop-window:// desktop-window://focus?name=slack Fokus okna
natywne vscode://, cursor://, file://, ms-settings: Passthrough do handlera OS

Metadata native_uri zawiera deep-link IDE (vscode://file/...) gdy istnieje.

Konfiguracja (nlp2uri.yaml)

Domyślne ustawienia w pliku nlp2uri.yaml (auto-tworzony przy pierwszym uruchomieniu):

platform: auto          # auto | linux | darwin | windows
host_platform: linux  # ostatnio wykryty host (informacyjnie)
locale: null
dry_run: false
capture_dir: /tmp/nlp2uri-captures

Kolejność wyboru platformy: --platformNLP2URI_PLATFORMnlp2uri.yaml → auto-detect OS.

nlp2uri config show --json    # efektywna konfiguracja
nlp2uri config init           # zapisz domyślny nlp2uri.yaml

Ścieżki szukania configu: NLP2URI_CONFIG./nlp2uri.yaml~/.config/nlp2uri/nlp2uri.yaml.

Quick start

pip install -e ".[dev]"

# Platforma wykrywana automatycznie (bez --platform)
nlp2uri plan "otwórz vscode w folderze ~/github/semcod/nlp2uri" --json
nlp2uri resolve "zrób screenshot aktywnego okna przeglądarki" --json
nlp2uri execute "open firefox" --dry-run

Python API (service facade)

from nlp2uri import NLP2URIService
from nlp2uri.models import HostPlatform

svc = NLP2URIService.default()  # ładuje nlp2uri.yaml + auto-detect

plan = svc.from_prompt("otwórz vscode w folderze /tmp/foo")
print(plan.uri)                    # app://vscode/open?path=/tmp/foo
print(plan.actions[0].argv())      # ['xdg-open', 'vscode://file/tmp/foo']

payload = svc.handle_prompt("open firefox", dry_run=True)  # prompt → URI → run

Adaptery i integratory (reużywalne powierzchnie)

Warstwa Użycie Moduł
Service NLP2URIService.from_prompt() / handle_uri() nlp2uri.service
CLI nlp2uri plan|resolve|compile|execute nlp2uri.adapters.cli
Shell eval "$(nlp2uri shell export '…')" nlp2uri.adapters.shell
REST nlp2uri-serve --port 8766 nlp2uri.integrators.rest_server
MCP nlp2uri-mcp (stdio JSON-RPC) nlp2uri.integrators.mcp_server

REST (POST /v1/plan)

curl -s -X POST http://127.0.0.1:8766/v1/plan \
  -H 'Content-Type: application/json' \
  -d '{"prompt":"open firefox"}'

MCP (Cursor / Windsurf)

{ "mcpServers": { "nlp2uri": { "command": "nlp2uri-mcp" } } }

Tools: nlp2uri_plan, nlp2uri_resolve, nlp2uri_compile, nlp2uri_execute, nlp2uri_handle.

Shell

eval "$(nlp2uri shell export 'open firefox')"
echo "$NLP2URI_URI"    # app://firefox/open
$nlp2uri-run           # alias do skompilowanej komendy

Własny adapter

from nlp2uri.adapters.base import AdapterRequest
from nlp2uri.adapters.rest import RestAdapter

response = RestAdapter().dispatch("plan", {"prompt": "capture screen", "platform": "linux"})
print(response.data["uri"])

Standardy

Standard Rola
RFC 3986 Składnia URI (scheme, path, query)
RFC 8089 file://
RFC 9110 http(s)://
Freedesktop Desktop Entry .desktop, x-scheme-handler/<scheme>
XDG Desktop Portal Screenshot Wayland
Windows URI activation ms-settings:, rejestracja schemów
macOS URL Schemes CFBundleURLSchemes w Info.plist
MCP text/uri-list Lista URI dla hosta / MCP Apps

Przydatne biblioteki

Biblioteka Kiedy
urllib.parse, webbrowser, subprocess Już używane (stdlib)
psutil PID → okno
pyxdg Parsowanie .desktop
dbus-python + PyGObject XDG Portal screenshot
pywin32 Win32 SetForegroundWindow
pyobjc / Quartz macOS window ID
spaCy / transformers Zamiast heurystyk regex
nlp2dsl / nlp2cmd-intent IntentIR z LLM (jak nlpshim)

Testy i Docker

python -m pytest
docker compose build && docker compose run --rm nlp2uri-test
./examples/run-e2e.sh

Przykłady per kategoria: examples/README.md.

W Dockerze:

  • unit: NLP → URI → OSAction
  • integracja: rejestracja testapp:// przez .desktop + xdg-open (NLP2URI_INTEGRATION=1)

Plan rozwoju

docs/roadmap.md · docs/mcp-tools.md · CI: .github/workflows/ci.yml

Relacja z ekosystemem Semcod

  • nlpshim — NLP → DSL / workflow
  • nlp2uri — NLP → URI → akcje desktopowe (MCP, screenshot, focus, open app)
  • koruportal_capture.py jako wzorzec dla Wayland screenshot

License

Licensed under Apache-2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nlp2uri-0.4.1.tar.gz (47.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nlp2uri-0.4.1-py3-none-any.whl (52.4 kB view details)

Uploaded Python 3

File details

Details for the file nlp2uri-0.4.1.tar.gz.

File metadata

  • Download URL: nlp2uri-0.4.1.tar.gz
  • Upload date:
  • Size: 47.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for nlp2uri-0.4.1.tar.gz
Algorithm Hash digest
SHA256 f6a617daddd901b066b08b1dc8559118416d5ade860c3cbc1c09935f5d1935f2
MD5 3f02b47a7556f5f25949f3169ee37d55
BLAKE2b-256 d01f253f402b1f269a64f8b4503b03824be6a47a441527b4d833f340e813d110

See more details on using hashes here.

File details

Details for the file nlp2uri-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: nlp2uri-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 52.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for nlp2uri-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 30804c80538d2d6e66b73920cf5b3fe3efe0a5587770d2810216ad84f36b1aa7
MD5 9ccdfba7ec5d2c12c1c28dec3f71ae5f
BLAKE2b-256 61535408ae0318aa4f68555ad3a88c5a8add9a93937d0d85e089e85c3d59be7c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page