kaos-web 0.1.0a1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. kaos_web-0.1.0a1/.gitignore +36 -0
  2. kaos_web-0.1.0a1/CHANGELOG.md +273 -0
  3. kaos_web-0.1.0a1/LICENSE +201 -0
  4. kaos_web-0.1.0a1/NOTICE +8 -0
  5. kaos_web-0.1.0a1/PKG-INFO +284 -0
  6. kaos_web-0.1.0a1/README.md +242 -0
  7. kaos_web-0.1.0a1/kaos_web/__init__.py +23 -0
  8. kaos_web-0.1.0a1/kaos_web/__main__.py +5 -0
  9. kaos_web-0.1.0a1/kaos_web/_version.py +1 -0
  10. kaos_web-0.1.0a1/kaos_web/browser_tools.py +1897 -0
  11. kaos_web-0.1.0a1/kaos_web/cli.py +288 -0
  12. kaos_web-0.1.0a1/kaos_web/clients/__init__.py +15 -0
  13. kaos_web-0.1.0a1/kaos_web/clients/browser.py +1122 -0
  14. kaos_web-0.1.0a1/kaos_web/clients/config.py +108 -0
  15. kaos_web-0.1.0a1/kaos_web/clients/http.py +412 -0
  16. kaos_web-0.1.0a1/kaos_web/clients/page_prep.py +269 -0
  17. kaos_web-0.1.0a1/kaos_web/clients/protocol.py +19 -0
  18. kaos_web-0.1.0a1/kaos_web/clients/user_agents.py +74 -0
  19. kaos_web-0.1.0a1/kaos_web/crawl_tools.py +572 -0
  20. kaos_web-0.1.0a1/kaos_web/data/user_agents.json +107 -0
  21. kaos_web-0.1.0a1/kaos_web/discover/__init__.py +54 -0
  22. kaos_web-0.1.0a1/kaos_web/discover/batch.py +95 -0
  23. kaos_web-0.1.0a1/kaos_web/discover/crawl.py +256 -0
  24. kaos_web-0.1.0a1/kaos_web/discover/discovery.py +296 -0
  25. kaos_web-0.1.0a1/kaos_web/discover/sitemap.py +351 -0
  26. kaos_web-0.1.0a1/kaos_web/domain/__init__.py +122 -0
  27. kaos_web-0.1.0a1/kaos_web/domain/dns.py +653 -0
  28. kaos_web-0.1.0a1/kaos_web/domain/fingerprint.py +331 -0
  29. kaos_web-0.1.0a1/kaos_web/domain/http.py +225 -0
  30. kaos_web-0.1.0a1/kaos_web/domain/models.py +380 -0
  31. kaos_web-0.1.0a1/kaos_web/domain/org.py +367 -0
  32. kaos_web-0.1.0a1/kaos_web/domain/profile.py +93 -0
  33. kaos_web-0.1.0a1/kaos_web/domain/security.py +265 -0
  34. kaos_web-0.1.0a1/kaos_web/domain/service.py +95 -0
  35. kaos_web-0.1.0a1/kaos_web/domain/tcp.py +378 -0
  36. kaos_web-0.1.0a1/kaos_web/domain/tls.py +170 -0
  37. kaos_web-0.1.0a1/kaos_web/domain/udp.py +724 -0
  38. kaos_web-0.1.0a1/kaos_web/domain/whois.py +373 -0
  39. kaos_web-0.1.0a1/kaos_web/domain_tools.py +1180 -0
  40. kaos_web-0.1.0a1/kaos_web/errors.py +145 -0
  41. kaos_web-0.1.0a1/kaos_web/extract/__init__.py +28 -0
  42. kaos_web-0.1.0a1/kaos_web/extract/html_to_ast.py +227 -0
  43. kaos_web-0.1.0a1/kaos_web/extract/images.py +255 -0
  44. kaos_web-0.1.0a1/kaos_web/extract/links.py +266 -0
  45. kaos_web-0.1.0a1/kaos_web/extract/metadata.py +155 -0
  46. kaos_web-0.1.0a1/kaos_web/extract/readability.py +349 -0
  47. kaos_web-0.1.0a1/kaos_web/extract/readability_l3.py +667 -0
  48. kaos_web-0.1.0a1/kaos_web/middleware/__init__.py +21 -0
  49. kaos_web-0.1.0a1/kaos_web/middleware/base.py +57 -0
  50. kaos_web-0.1.0a1/kaos_web/middleware/cache.py +377 -0
  51. kaos_web-0.1.0a1/kaos_web/middleware/rate_limit.py +103 -0
  52. kaos_web-0.1.0a1/kaos_web/middleware/retry.py +109 -0
  53. kaos_web-0.1.0a1/kaos_web/middleware/robots.py +132 -0
  54. kaos_web-0.1.0a1/kaos_web/models/__init__.py +11 -0
  55. kaos_web-0.1.0a1/kaos_web/models/metadata.py +44 -0
  56. kaos_web-0.1.0a1/kaos_web/models/request.py +37 -0
  57. kaos_web-0.1.0a1/kaos_web/models/response.py +47 -0
  58. kaos_web-0.1.0a1/kaos_web/py.typed +0 -0
  59. kaos_web-0.1.0a1/kaos_web/search/__init__.py +23 -0
  60. kaos_web-0.1.0a1/kaos_web/search/backends.py +413 -0
  61. kaos_web-0.1.0a1/kaos_web/security.py +138 -0
  62. kaos_web-0.1.0a1/kaos_web/serve.py +125 -0
  63. kaos_web-0.1.0a1/kaos_web/settings.py +303 -0
  64. kaos_web-0.1.0a1/kaos_web/tools.py +1079 -0
  65. kaos_web-0.1.0a1/pyproject.toml +155 -0
  66. kaos_web-0.1.0a1/tests/__init__.py +0 -0
  67. kaos_web-0.1.0a1/tests/benchmarks/test_benchmarks.py +170 -0
  68. kaos_web-0.1.0a1/tests/fixtures/article.html +112 -0
  69. kaos_web-0.1.0a1/tests/fixtures/books_toscrape.html +361 -0
  70. kaos_web-0.1.0a1/tests/fixtures/cornell_law.html +879 -0
  71. kaos_web-0.1.0a1/tests/fixtures/httpbin.html +14 -0
  72. kaos_web-0.1.0a1/tests/fixtures/readability/category_listing.html +66 -0
  73. kaos_web-0.1.0a1/tests/fixtures/readability/corpus.json +132 -0
  74. kaos_web-0.1.0a1/tests/fixtures/readability/directory_listing.html +75 -0
  75. kaos_web-0.1.0a1/tests/fixtures/readability/docket_report.html +95 -0
  76. kaos_web-0.1.0a1/tests/fixtures/readability/multi_section_landing.html +63 -0
  77. kaos_web-0.1.0a1/tests/fixtures/readability/search_results_page.html +80 -0
  78. kaos_web-0.1.0a1/tests/fixtures/readability/team_directory_cards.html +71 -0
  79. kaos_web-0.1.0a1/tests/integration/__init__.py +0 -0
  80. kaos_web-0.1.0a1/tests/integration/test_273v_e2e.py +402 -0
  81. kaos_web-0.1.0a1/tests/integration/test_browser_interaction.py +604 -0
  82. kaos_web-0.1.0a1/tests/integration/test_crawl.py +303 -0
  83. kaos_web-0.1.0a1/tests/integration/test_domain_live.py +403 -0
  84. kaos_web-0.1.0a1/tests/integration/test_entity_live.py +74 -0
  85. kaos_web-0.1.0a1/tests/integration/test_mcp_web_pipeline.py +193 -0
  86. kaos_web-0.1.0a1/tests/integration/test_mcp_web_session.py +193 -0
  87. kaos_web-0.1.0a1/tests/integration/test_middleware_e2e.py +228 -0
  88. kaos_web-0.1.0a1/tests/integration/test_real_http.py +244 -0
  89. kaos_web-0.1.0a1/tests/integration/test_real_sites.py +242 -0
  90. kaos_web-0.1.0a1/tests/integration/test_search_live.py +164 -0
  91. kaos_web-0.1.0a1/tests/unit/__init__.py +0 -0
  92. kaos_web-0.1.0a1/tests/unit/conftest.py +43 -0
  93. kaos_web-0.1.0a1/tests/unit/domain/__init__.py +0 -0
  94. kaos_web-0.1.0a1/tests/unit/domain/test_dns.py +555 -0
  95. kaos_web-0.1.0a1/tests/unit/domain/test_fingerprint.py +387 -0
  96. kaos_web-0.1.0a1/tests/unit/domain/test_http.py +233 -0
  97. kaos_web-0.1.0a1/tests/unit/domain/test_models.py +357 -0
  98. kaos_web-0.1.0a1/tests/unit/domain/test_org.py +576 -0
  99. kaos_web-0.1.0a1/tests/unit/domain/test_profile.py +86 -0
  100. kaos_web-0.1.0a1/tests/unit/domain/test_security.py +281 -0
  101. kaos_web-0.1.0a1/tests/unit/domain/test_service.py +125 -0
  102. kaos_web-0.1.0a1/tests/unit/domain/test_tcp.py +168 -0
  103. kaos_web-0.1.0a1/tests/unit/domain/test_tcp_banner.py +255 -0
  104. kaos_web-0.1.0a1/tests/unit/domain/test_tls.py +255 -0
  105. kaos_web-0.1.0a1/tests/unit/domain/test_udp.py +568 -0
  106. kaos_web-0.1.0a1/tests/unit/domain/test_whois.py +438 -0
  107. kaos_web-0.1.0a1/tests/unit/test_batch.py +124 -0
  108. kaos_web-0.1.0a1/tests/unit/test_browser_client.py +186 -0
  109. kaos_web-0.1.0a1/tests/unit/test_browser_interaction.py +963 -0
  110. kaos_web-0.1.0a1/tests/unit/test_browser_session_isolation.py +530 -0
  111. kaos_web-0.1.0a1/tests/unit/test_browser_tools_wrappers.py +1033 -0
  112. kaos_web-0.1.0a1/tests/unit/test_cache.py +374 -0
  113. kaos_web-0.1.0a1/tests/unit/test_cli_commands.py +306 -0
  114. kaos_web-0.1.0a1/tests/unit/test_clients_page_prep.py +413 -0
  115. kaos_web-0.1.0a1/tests/unit/test_crawl.py +204 -0
  116. kaos_web-0.1.0a1/tests/unit/test_crawl_tools.py +644 -0
  117. kaos_web-0.1.0a1/tests/unit/test_discovery.py +293 -0
  118. kaos_web-0.1.0a1/tests/unit/test_domain_tools.py +837 -0
  119. kaos_web-0.1.0a1/tests/unit/test_edge_cases.py +426 -0
  120. kaos_web-0.1.0a1/tests/unit/test_fuzz.py +207 -0
  121. kaos_web-0.1.0a1/tests/unit/test_html_to_ast.py +495 -0
  122. kaos_web-0.1.0a1/tests/unit/test_http_client.py +335 -0
  123. kaos_web-0.1.0a1/tests/unit/test_metadata.py +108 -0
  124. kaos_web-0.1.0a1/tests/unit/test_middleware.py +359 -0
  125. kaos_web-0.1.0a1/tests/unit/test_readability.py +67 -0
  126. kaos_web-0.1.0a1/tests/unit/test_readability_experiments.py +66 -0
  127. kaos_web-0.1.0a1/tests/unit/test_readability_l3.py +265 -0
  128. kaos_web-0.1.0a1/tests/unit/test_response_capture.py +1311 -0
  129. kaos_web-0.1.0a1/tests/unit/test_search_backends.py +269 -0
  130. kaos_web-0.1.0a1/tests/unit/test_security.py +213 -0
  131. kaos_web-0.1.0a1/tests/unit/test_serve.py +175 -0
  132. kaos_web-0.1.0a1/tests/unit/test_settings.py +306 -0
  133. kaos_web-0.1.0a1/tests/unit/test_sitemap.py +410 -0
  134. kaos_web-0.1.0a1/tests/unit/test_tools.py +932 -0
@@ -0,0 +1,36 @@
1
+ # Build / dist
2
+ build/
3
+ dist/
4
+ *.egg-info/
5
+
6
+ # Caches
7
+ .benchmarks/
8
+ .coverage
9
+ .coverage.*
10
+ .kaos-vfs/
11
+ .kaos-vfs-*/
12
+ .mypy_cache/
13
+ .pytest_cache/
14
+ .ruff_cache/
15
+ .ty_cache/
16
+ .venv/
17
+ __pycache__/
18
+ coverage.xml
19
+ htmlcov/
20
+ *.pyc
21
+
22
+ # OS / editor scratch
23
+ .DS_Store
24
+ Thumbs.db
25
+ .idea/
26
+ .vscode/
27
+
28
+ # Secrets — never commit
29
+ .env
30
+ .env.*
31
+ !.env.example
32
+ *.pem
33
+ *.key
34
+ *.p12
35
+ *.pfx
36
+ .kaos-credentials.json
@@ -0,0 +1,273 @@
1
+ # Changelog
2
+
3
+ All notable changes to `kaos-web` are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ### Security
11
+
12
+ - **SSRF gate at every outbound URL/host site** (WEB5-001). Wires
13
+ ``kaos_core.security.validate_outbound_url`` (and the host-only
14
+ ``is_loopback`` / ``is_private_ip`` / ``is_metadata_service``
15
+ primitives) into every kaos-web fetch site so a misconfigured
16
+ caller — especially the HTTP-mode MCP server fronting multiple
17
+ agents — cannot reach link-local cloud-metadata services
18
+ (``169.254.169.254``), loopback, RFC1918 private networks, or
19
+ block-listed schemes (``file://``, ``javascript:``, ``data:``,
20
+ ``vbscript:``). New ``kaos_web.security`` module exposes
21
+ ``validate_url(url)`` and ``validate_host(host)`` thin wrappers
22
+ that translate ``UnsafeURLError`` into a new
23
+ ``UrlPolicyError(WebError)`` whose message includes the specific
24
+ policy field that fired plus the env var the operator can flip to
25
+ relax it. **Strict by default**: blocks private/loopback/metadata
26
+ and limits schemes to ``http``/``https``. Operators relax via
27
+ ``KAOS_SECURITY_BLOCK_PRIVATE_NETWORKS=0`` /
28
+ ``KAOS_SECURITY_BLOCK_LOOPBACK=0`` /
29
+ ``KAOS_SECURITY_BLOCK_METADATA_SERVICES=0`` /
30
+ ``KAOS_SECURITY_ALLOWED_HOSTS=["host","10.0.0.0/24",".example.com"]``.
31
+ Sites wired (4 URL gates + 12 host gates):
32
+ - URL: ``HttpClient._raw_fetch``, ``BrowserClient.fetch`` /
33
+ ``screenshot`` / ``evaluate``, ``analyze_headers``,
34
+ ``ExtractOrgTool.execute``.
35
+ - Host: ``probe_port`` / ``probe_ports`` / ``probe_banner`` /
36
+ ``probe_banners``, ``inspect_tls``, ``probe_dns`` / ``probe_ntp``
37
+ / ``probe_snmp`` / ``probe_syslog``, ``whois_lookup``, ``lookup``
38
+ / ``lookup_many`` / ``enumerate_dns`` / ``attempt_zone_transfer``
39
+ / ``reverse_ptr``.
40
+ Known gap: ``follow_redirects=True`` on httpx only validates the
41
+ original URL — the redirect target is not re-validated. Closing
42
+ this requires a connect-time hook on the HTTP client (kaos-core
43
+ follow-up). Hostname-only inputs (most DNS / WHOIS use cases)
44
+ pass through; the gate fires on IP literals where the policy
45
+ classification is unambiguous.
46
+
47
+ - **Browser contexts are now session-scoped** (WEB5-002). Every entry
48
+ in ``BrowserClient._contexts`` / ``_pages`` / ``_request_logs`` /
49
+ ``_response_bodies`` / ``_logging_config`` is keyed by the tuple
50
+ ``(KaosContext.session_id, context_id)``. Previously, the shared
51
+ process-global client keyed by raw ``context_id`` strings — any
52
+ caller who knew or guessed a context_id could click/fill/screenshot
53
+ another caller's pages, read their cookies, or download captured
54
+ fetch/XHR bodies. With the MCP HTTP server fronting multiple
55
+ agents, that is a cross-tenant browser session takeover. Cross-
56
+ session lookups now miss uniformly with the same "No active page" /
57
+ "No context '<id>'" error a missing context returns — never
58
+ disclosing existence in another session. ``close_context`` from a
59
+ different session is a silent no-op. ``BrowserClient.active_contexts``
60
+ changed from a property to a ``method(session_id) -> list[str]``
61
+ that returns only the calling session's context IDs. Library
62
+ callers that omit ``session_id`` fall back to a module-level
63
+ ``ANONYMOUS_SESSION_ID`` sentinel so the original single-user stdio
64
+ surface keeps working without churn.
65
+
66
+ - **`SaveAuthStateTool` no longer accepts a caller-supplied filesystem
67
+ path** (WEB5-004). The previous implementation passed an MCP-input
68
+ ``path`` straight to Playwright's ``context.storage_state(path=...)``
69
+ — path-traversal / arbitrary-write to anywhere the server process
70
+ could write, plus a credentials-leak persistence path. Rewritten to:
71
+ capture the storage state in-memory via new
72
+ ``BrowserClient.get_storage_state(context_id)``, write to a
73
+ session-scoped VFS path, and persist as a kaos-core artifact via
74
+ ``KaosContext.runtime.artifacts.create_from_path`` (auto-bound to
75
+ the caller's ``session_id``). Returns an ``ArtifactManifest`` the
76
+ agent retrieves via standard artifact MCP tools. **Breaking change
77
+ for the MCP tool input schema**: the ``path`` parameter is removed
78
+ and replaced with an optional ``name`` parameter (artifact name).
79
+ Library users with their own filesystem authority can still call
80
+ ``BrowserClient.save_storage_state(path)`` directly.
81
+
82
+ - **Observed third-party traffic redacts sensitive headers by default**
83
+ (WEB5-003). When ``kaos-web-browser-log-requests`` captures network
84
+ traffic, the recorded request and response headers now mask values
85
+ for ``Authorization``, ``Proxy-Authorization``, ``Cookie``,
86
+ ``Set-Cookie``, ``X-API-Key``, ``X-Auth-Token``, ``X-CSRF-Token``,
87
+ plus any header whose name matches the catch-all
88
+ ``(?i).*(?:secret|token|api[_-]?key|password|auth).*``. Mask format
89
+ ``<redacted: N bytes>`` preserves length information without leaking
90
+ the value. New ``KAOS_WEB_REDACT_OBSERVED_TRAFFIC`` env var
91
+ (default ``true``); set ``false`` for explicit security-research
92
+ workflows. The agent's OWN session cookies (returned by
93
+ ``kaos-web-browser-cookies`` / ``GetCookiesTool``) are NOT
94
+ redacted — they're the agent's own state.
95
+
96
+ - **Response-body size cap enforced at every fetch site** (WEB5-007).
97
+ New `KaosWebSettings.max_body_bytes` (env: `KAOS_WEB_MAX_BODY_BYTES`,
98
+ default 50 MB) bounds memory usage on hostile or misconfigured
99
+ endpoints. Enforced at three sites:
100
+ - `HttpClient._raw_fetch` switched to `client.stream() +
101
+ aiter_bytes()` with a pre-check on the declared `Content-Length`
102
+ header and a running tally over the streamed bytes. Aborts with
103
+ `BodyTooLargeError` before materialization.
104
+ - `BrowserClient.fetch` post-checks `len(page.content())` (Playwright
105
+ has no streaming variant) — protects downstream parsers and
106
+ artifact storage from operating on absurd strings.
107
+ - `kaos_web.discover.sitemap._decompress_gzip` switched to
108
+ `gzip.GzipFile.read(max_bytes + 1)` (gzip-bomb protection — a
109
+ small gzipped payload can decompress to gigabytes; bounded read
110
+ is the only memory-safe pattern).
111
+ New `BodyTooLargeError(WebError)` carries `size_bytes`,
112
+ `max_bytes`, and an agent-friendly recovery hint pointing at the
113
+ env var.
114
+
115
+ - **URL filter regexes now use the Rust regex engine when available**
116
+ (WEB5-008). `kaos_web.discover.discovery._compile_patterns` previously
117
+ built `re.compile(...)` patterns from caller-supplied include /
118
+ exclude regex strings and applied `pattern.search(...)` to every
119
+ discovered URL path. Stdlib `re` is a backtracking engine —
120
+ pathological patterns like `(a+)+b` against `"a" * N` run in
121
+ exponential time and block the asyncio event loop (ReDoS).
122
+ Compiled patterns now route through a `_SafePattern` shim that
123
+ prefers `kaos_nlp_core.matching.RegexMatcher` (Rust regex, linear
124
+ time, no backtracking) when the `[nlp]` optional extra is installed,
125
+ with stdlib `re` as a fallback (one-shot warning logged so operators
126
+ see the path). Install `kaos-web[nlp]` to get the protection by
127
+ default.
128
+
129
+ - **CacheMiddleware bypasses any request bearing auth-shaped headers**
130
+ (WEB5-009). Cache key is `method:url` only — without this gate, an
131
+ authenticated request would either return another caller's cached
132
+ anonymous response (read-leak) or poison the cache for subsequent
133
+ anonymous callers (write-leak). The bypass is conservative: if the
134
+ request includes any of `Authorization`, `Proxy-Authorization`,
135
+ `Cookie`, `X-API-Key`, `X-Auth-Token`, `X-CSRF-Token`
136
+ (case-insensitive), the cache is skipped entirely (no LOOKUP, no
137
+ STORE) and the request always hits upstream. Anonymous requests
138
+ still benefit from the cache normally.
139
+
140
+ - **TLS verification on domain-intelligence probes now defaults to ON**
141
+ (WEB5-006). The two probes that explicitly disable verification
142
+ (`kaos-web-http-headers`, `kaos-web-extract-org`) previously
143
+ defaulted to `KAOS_WEB_DOMAIN_VERIFY_TLS=false` (audit-02 WEB2-001
144
+ shipped the setting with that default; WEB5-006 flips it to `true`).
145
+ Secure-by-default: the typical use case is observing healthy public
146
+ sites where CA validation is correct. Set
147
+ `KAOS_WEB_DOMAIN_VERIFY_TLS=false` to inspect hosts whose cert is
148
+ itself the subject of inspection (self-signed, expired, mismatched
149
+ SAN, staging environments). **Migration**: anyone scraping such
150
+ hosts will see new TLS errors; explicitly opt out via the env var.
151
+ Content-extraction tools (`HttpClient` / `BrowserClient`) keep TLS
152
+ verification on independently of this flag.
153
+
154
+ - **Browser interaction tools now declare `destructiveHint=True`**
155
+ (WEB5-005). Click / fill / type / press / select / evaluate run
156
+ inside an authenticated browser session and CAN trigger real actions
157
+ (form submit, settings change, JS-driven side effects). The prior
158
+ shared `_BROWSER_WRITE_ANNOTATIONS` annotation said
159
+ `destructiveHint=False` for all of them, which weakened any MCP
160
+ client that gates auto-approval on the annotation. Split into
161
+ `_BROWSER_INTERACT_ANNOTATIONS` (destructive=True for the 6
162
+ interaction tools) and the existing `_BROWSER_WRITE_ANNOTATIONS`
163
+ (destructive=False for local-state tools that do not trigger remote
164
+ actions: set-cookie, save-auth-state, enable-request-logging,
165
+ close-context, navigate). No behavior change — annotation
166
+ correctness only.
167
+
168
+ ### Changed
169
+
170
+ - **Refactored package layout** for better cohesion (per
171
+ `docs/python/design/modules.md`):
172
+ - New `kaos_web.discover` subpackage groups the BFS-discovery
173
+ subsystem: `batch`, `crawl`, `discovery`, `sitemap` (formerly four
174
+ top-level modules with mutual imports). Re-exports the canonical
175
+ public API at the package level (e.g. `from kaos_web.discover
176
+ import batch_fetch, crawl_site, discover_urls, parse_sitemap`).
177
+ - `kaos_web.browser_page_prep` → `kaos_web.clients.page_prep`. Only
178
+ consumer was `clients/browser.py`; the helper is logically a
179
+ browser-client primitive.
180
+ - The four `*_tools.py` files (`tools.py`, `browser_tools.py`,
181
+ `crawl_tools.py`, `domain_tools.py`) **stay top-level** per the
182
+ explicit KAOS convention documented in
183
+ `docs/python/design/modules.md` ("split tool files by domain when
184
+ they would otherwise exceed ~1500 lines"). No tools/ subpackage.
185
+
186
+ Pre-0.1.0a1 — no published version pins these import paths, so no
187
+ back-compat shims are shipped. If you imported from these paths in
188
+ pre-release builds, update to the new locations.
189
+
190
+ ## [0.1.0a1] — 2026-05-08
191
+
192
+ First public alpha release.
193
+
194
+ ### Added
195
+
196
+ - Web content extraction for the KAOS (Kelvin Agentic Operating System)
197
+ platform. Fetches HTML from URLs over HTTP or a headless browser and
198
+ produces `kaos-content` `ContentDocument` AST with provenance on every
199
+ block.
200
+ - **Dual-client architecture**: `HttpClient` (httpx, async, HTTP/2,
201
+ connection pooling, auth, SSL, proxy, structured error mapping) and
202
+ `BrowserClient` (Playwright, lazy launch, named-context page tracking,
203
+ cookie-banner dismissal for 8 known consent-management platforms).
204
+ - **HTML-to-AST extraction** (`html_to_document`): lxml element tree to
205
+ Block/Inline `ContentDocument` with `SourceRef` + `Provenance` on
206
+ every node. Supports headings, paragraphs, lists, blockquotes, code
207
+ blocks, tables, figures, definition lists, thematic breaks, and the
208
+ full inline grammar (text, strong, emphasis, code, link, image,
209
+ strikethrough, sub/superscript, line break).
210
+ - **Level-3 learned readability** (`extract.readability_l3`): pre-trained
211
+ logistic regression over 35 DOM-node features. Default extractor with
212
+ a `content_scope` parameter (0.0–1.0) controlling
213
+ precision/recall tradeoff. Heuristic readability and semantic
214
+ container detection (`<main>` → `<article>` → `[role=main]` → `<body>`)
215
+ remain as fallbacks when the L3 extraction returns `< 50` words.
216
+ - **Composable middleware chain** (`middleware/`): `RetryMiddleware`
217
+ (exponential backoff with jitter, honors `Retry-After`),
218
+ `RateLimitMiddleware` (per-domain token bucket), `RobotsMiddleware`
219
+ (stdlib `robotparser`, cached per domain), `CacheMiddleware`
220
+ (in-memory LRU, RFC 7231 compliant). Wired into `HttpClient.fetch()`
221
+ via `MiddlewareChain`; configurable per-client.
222
+ - **Search backends** (`search/`): SerpAPI, DuckDuckGo, Exa, Brave —
223
+ unified async interface with auto-detection from configured API keys.
224
+ - **Domain intelligence** (`domain/`): TCP probing + banner grab,
225
+ TLS cert inspection, HTTP header analysis with CDN detection and
226
+ security scoring, DNS lookup/enumeration/zone-transfer/security
227
+ posture, stdlib WHOIS client (55-TLD server map with referral
228
+ following), UDP protocol-aware probes (DNS / NTP / SNMPv1 / syslog),
229
+ pure banner→ServiceIdentity fingerprinting, and Schema.org
230
+ organization-entity extraction.
231
+ - **Multi-page workflows**: `discovery` (sitemaps + page links with
232
+ pattern filtering), `batch` (concurrent URL fetching with
233
+ `asyncio.Semaphore`), `crawl` (BFS site crawl with depth/page limits
234
+ and sitemap-first discovery).
235
+ - **45 MCP tools across 4 servers**:
236
+ - `register_web_tools()` — 7 extraction tools (fetch-page, get-text,
237
+ get-markdown, get-metadata, search-page, get-links, get-images).
238
+ - `register_browser_tools()` — 19 browser interaction tools
239
+ (navigate, click, fill, type, press, select, screenshot, evaluate,
240
+ snapshot, content, cookies, set-cookie, save-auth, log-requests,
241
+ requests, get-request, captured-responses, list-contexts,
242
+ close-context).
243
+ - `register_crawl_tools()` — 3 multi-page tools (discover-urls,
244
+ batch-fetch, crawl-site).
245
+ - `register_domain_tools()` — 14 domain-intelligence tools
246
+ (tcp-probe, tcp-banner, tls-inspect, http-headers, service-detect,
247
+ fingerprint-service, dns-lookup, dns-enumerate, dns-zone-transfer,
248
+ dns-security, whois-lookup, domain-profile, extract-org,
249
+ udp-probe). Enabled with `kaos-web-serve --domain`.
250
+ - **Typed module settings** (`KaosWebSettings`): `KAOS_WEB_*` env prefix
251
+ with legacy fallbacks (`SERPAPI_API_KEY`, `EXA_API_KEY`,
252
+ `BRAVE_API_KEY`, `KAOS_BROWSER_*`, `KAOS_SEARCH_*`). API keys use
253
+ `pydantic.SecretStr`. Knobs cover browser (type/headless/channel),
254
+ search (backend selection + per-backend timeouts + DDG user-agent),
255
+ discovery, sitemap, crawl, and middleware behavior.
256
+ - **CLI** (`kaos-web`): `extract`, `metadata`, `serve` subcommands with
257
+ `--json` envelope output for piping/agents.
258
+ - **Standalone MCP server** (`kaos-web-serve`): stdio (default) or
259
+ streamable HTTP (`--http --port`); `--browser`, `--crawl`, `--domain`
260
+ flags compose the registered tool surface; `--debug` enables verbose
261
+ logging.
262
+ - **Optional extras**: `[browser]` adds Playwright for JS-heavy pages;
263
+ `[dns]` adds dnspython for the domain-intelligence DNS tools; `[mcp]`
264
+ adds `kaos-mcp` for serving tools as a FastMCP bridge; `[nlp]` adds
265
+ `kaos-nlp-core` for BM25 search inside extracted documents.
266
+
267
+ ### License
268
+
269
+ This release is the first to ship under the Apache License 2.0. Earlier
270
+ internal versions were proprietary.
271
+
272
+ [Unreleased]: https://github.com/273v/kaos-web/compare/v0.1.0a1...HEAD
273
+ [0.1.0a1]: https://github.com/273v/kaos-web/releases/tag/v0.1.0a1
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 273 Ventures LLC
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,8 @@
1
+ kaos-web
2
+ Copyright 2026 273 Ventures LLC.
3
+
4
+ This product includes software developed at 273 Ventures LLC
5
+ (https://273ventures.com).
6
+
7
+ Licensed under the Apache License, Version 2.0. See the LICENSE file
8
+ distributed with this software for the full text of the license.