intentframe-edge 0.1.0__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.
@@ -0,0 +1,120 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ build/
8
+ develop-eggs/
9
+ dist/
10
+ downloads/
11
+ eggs/
12
+ .eggs/
13
+ lib/
14
+ lib64/
15
+ parts/
16
+ sdist/
17
+ var/
18
+ wheels/
19
+ share/python-wheels/
20
+ *.egg-info/
21
+ .installed.cfg
22
+ *.egg
23
+ MANIFEST
24
+
25
+ # Virtual environments
26
+ venv/
27
+ env/
28
+ ENV/
29
+ env.bak/
30
+ venv.bak/
31
+ .venv/
32
+ .venv-runtime/
33
+
34
+ # Kits two-venv harness artifacts
35
+ .intentframe/kits/
36
+ .intentframe/kits-build/
37
+ .intentframe/kits-two-venv/
38
+ .intentframe/runtime-constraints.txt
39
+
40
+ # IDEs
41
+ .vscode/
42
+ .idea/
43
+ *.swp
44
+ *.swo
45
+ *~
46
+
47
+ # Jupyter Notebook
48
+ .ipynb_checkpoints
49
+
50
+ # mypy
51
+ .mypy_cache/
52
+ .dmypy.json
53
+ dmypy.json
54
+
55
+ # Pyre type checker
56
+ .pyre/
57
+
58
+ # pytype static type analyzer
59
+ .pytype/
60
+
61
+ # Cython debug symbols
62
+ cython_debug/
63
+
64
+ # Testing
65
+ .pytest_cache/
66
+ .coverage
67
+ .coverage.*
68
+ htmlcov/
69
+ .tox/
70
+ .nox/
71
+ coverage.xml
72
+ *.cover
73
+ .hypothesis/
74
+
75
+ # Environment variables / local secrets
76
+ .env
77
+ .env.local
78
+ .env.*.local
79
+ .aienv
80
+
81
+ # Logs
82
+ *.log
83
+ logs/
84
+
85
+ # Database
86
+ *.db
87
+ *.sqlite
88
+ *.sqlite3
89
+
90
+ # OS
91
+ .DS_Store
92
+ Thumbs.db
93
+
94
+ # Project specific
95
+ *.bak
96
+ *.tmp
97
+ temp/
98
+ tmp/
99
+
100
+ .external_lib_helpers/
101
+
102
+ # Email sync test credentials (contains real passwords)
103
+ external_data_ingestion/tests/test_config.yaml
104
+ external_data_ingestion/tests/test_e2e_config.yaml
105
+
106
+ # Swift platform server (local release builds; regenerate via intentframe_setup.sh / bundle.sh)
107
+ macos-appkit-server/.build/
108
+
109
+ .cursor_chats/
110
+ .cursor/
111
+
112
+ .ruff_cache/
113
+
114
+ # Attack test sandbox (populated at runtime by test harness)
115
+ demo/demo_data/attack_invoices_sandbox/
116
+
117
+ .claude/
118
+ .claude_chats/
119
+
120
+ .cursorignore
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,37 @@
1
+ Metadata-Version: 2.4
2
+ Name: intentframe-edge
3
+ Version: 0.1.0
4
+ Summary: IntentFrame edge ingress — HTTP/TLS front door for runtime Unix domain socket services
5
+ Project-URL: Homepage, https://github.com/intentframe/intentframe
6
+ Project-URL: Repository, https://github.com/intentframe/intentframe
7
+ Project-URL: Issues, https://github.com/intentframe/intentframe/issues
8
+ Author: IntentFrame Contributors
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: agents,ai,edge,intentframe,security
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Security
16
+ Requires-Python: >=3.14
17
+ Requires-Dist: fastapi
18
+ Requires-Dist: intentframe-proxy==0.1.0
19
+ Requires-Dist: pydantic>=2.12.5
20
+ Requires-Dist: pyyaml>=6.0.3
21
+ Requires-Dist: uvicorn[standard]
22
+ Description-Content-Type: text/markdown
23
+
24
+ # intentframe-edge
25
+
26
+ Network-facing HTTP/TLS ingress for an IntentFrame runtime.
27
+
28
+ The edge is a thin, stateless reverse proxy. It terminates TCP/TLS/auth at the
29
+ deployment boundary and forwards approved routes to supervisor-managed services
30
+ over Unix domain sockets. Its default backend set exposes the substrate routes
31
+ only; the first-party native kit supplies an optional profile that also exposes
32
+ `/workspaces` through the resource registry.
33
+
34
+ ```bash
35
+ python -m intentframe_edge --host 0.0.0.0 --port 8443
36
+ intentframe-edge --config "${KIT}/edge_profile.yaml"
37
+ ```
@@ -0,0 +1,14 @@
1
+ # intentframe-edge
2
+
3
+ Network-facing HTTP/TLS ingress for an IntentFrame runtime.
4
+
5
+ The edge is a thin, stateless reverse proxy. It terminates TCP/TLS/auth at the
6
+ deployment boundary and forwards approved routes to supervisor-managed services
7
+ over Unix domain sockets. Its default backend set exposes the substrate routes
8
+ only; the first-party native kit supplies an optional profile that also exposes
9
+ `/workspaces` through the resource registry.
10
+
11
+ ```bash
12
+ python -m intentframe_edge --host 0.0.0.0 --port 8443
13
+ intentframe-edge --config "${KIT}/edge_profile.yaml"
14
+ ```
@@ -0,0 +1,30 @@
1
+ """IntentFrame Edge — network-facing HTTP/TLS front door for a runtime.
2
+
3
+ The edge is a thin, stateless reverse proxy that terminates the network
4
+ (TCP / TLS / optional bearer auth) and forwards requests to the
5
+ supervisor-managed services over their Unix domain sockets. The default
6
+ backend set is minimal:
7
+
8
+ /policies* → policy-registry.sock
9
+ /handshake, /process, /audit* → intentframe.sock
10
+
11
+ The optional ``/workspaces* → resource-registry.sock`` route is added by the
12
+ first-party kit profile (kit `edge_profile.yaml` in the installed package), selected
13
+ via ``INTENTFRAME_EDGE_CONFIG`` / ``--config``. This mirrors the supervisor's
14
+ registry-less default + opt-in kit profile.
15
+
16
+ It deliberately does NOT expose the executor or the credential vault —
17
+ those stay UDS-only inside the environment. The edge holds no state and
18
+ is not a "writer", so it does not affect the single-writer invariant; run
19
+ it as a sidecar next to the runtime, sharing the run-dir volume.
20
+
21
+ Run it with::
22
+
23
+ python -m intentframe_edge
24
+ # or, once installed:
25
+ intentframe-edge
26
+ """
27
+
28
+ from intentframe_edge.config import EdgeConfig, load_edge_config
29
+
30
+ __all__ = ["EdgeConfig", "load_edge_config"]
@@ -0,0 +1,68 @@
1
+ """Launch the IntentFrame edge with uvicorn (TCP, optional TLS/mTLS).
2
+
3
+ Configuration is env-driven (see ``intentframe_edge.config``); CLI flags
4
+ override host/port and select the backend profile for convenience::
5
+
6
+ python -m intentframe_edge --host 0.0.0.0 --port 8443
7
+ python -m intentframe_edge --config "${KIT}/edge_profile.yaml"
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import argparse
13
+ import os
14
+ import ssl
15
+
16
+ import uvicorn
17
+
18
+ from intentframe_edge.config import load_edge_config
19
+
20
+
21
+ def main() -> None:
22
+ parser = argparse.ArgumentParser(
23
+ prog="intentframe-edge",
24
+ description="IntentFrame network edge — HTTP/TLS front door that "
25
+ "forwards to the runtime's UDS services.",
26
+ )
27
+ parser.add_argument("--host", default=None)
28
+ parser.add_argument("--port", type=int, default=None)
29
+ parser.add_argument(
30
+ "--config",
31
+ default=None,
32
+ help=(
33
+ "Path to an edge backend profile YAML. Defaults to the in-code "
34
+ "minimal backends (policy-registry + intentframe-server). First-party "
35
+ "products / test harnesses pass the kit edge profile (${KIT}/edge_profile.yaml) "
36
+ "to expose /workspaces. Equivalent to INTENTFRAME_EDGE_CONFIG."
37
+ ),
38
+ )
39
+ args = parser.parse_args()
40
+
41
+ # Set the env var before the app module is imported by uvicorn so the
42
+ # ``app:app`` factory (which calls load_edge_config at import time) sees it.
43
+ if args.config:
44
+ os.environ["INTENTFRAME_EDGE_CONFIG"] = args.config
45
+
46
+ config = load_edge_config()
47
+ host = args.host or config.host
48
+ port = args.port or config.port
49
+
50
+ ssl_kwargs: dict = {}
51
+ if config.tls_enabled:
52
+ ssl_kwargs["ssl_certfile"] = config.tls_cert
53
+ ssl_kwargs["ssl_keyfile"] = config.tls_key
54
+ if config.mtls_enabled:
55
+ ssl_kwargs["ssl_ca_certs"] = config.tls_ca
56
+ ssl_kwargs["ssl_cert_reqs"] = ssl.CERT_REQUIRED
57
+
58
+ uvicorn.run(
59
+ "intentframe_edge.app:app",
60
+ host=host,
61
+ port=port,
62
+ log_level="info",
63
+ **ssl_kwargs,
64
+ )
65
+
66
+
67
+ if __name__ == "__main__":
68
+ main()
@@ -0,0 +1,117 @@
1
+ """IntentFrame Edge FastAPI app — path-routes HTTP to backend UDS sockets.
2
+
3
+ Routes are built from the configured backend profile (see
4
+ ``intentframe_edge.config``). Default (minimal) backends:
5
+
6
+ GET /health → edge + backend health summary
7
+ * /policies* → policy-registry.sock
8
+ * /handshake /process /audit* → intentframe.sock
9
+
10
+ The kit profile additionally exposes:
11
+
12
+ * /workspaces* → resource-registry.sock
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ import hmac
18
+ import logging
19
+ from contextlib import asynccontextmanager
20
+
21
+ from fastapi import FastAPI, HTTPException, Request, Response
22
+ from fastapi.responses import JSONResponse
23
+
24
+ from intentframe_edge.config import EdgeConfig, load_edge_config
25
+ from intentframe_proxy import UDSProxy
26
+
27
+ logger = logging.getLogger("intentframe.edge")
28
+
29
+ # Core /process can run for minutes; registries are quick.
30
+ _CORE_TIMEOUT = 120.0
31
+ _DEFAULT_TIMEOUT = 30.0
32
+
33
+
34
+ def create_app(config: EdgeConfig | None = None) -> FastAPI:
35
+ config = config or load_edge_config()
36
+
37
+ proxies: dict[str, UDSProxy] = {}
38
+ # (prefix, proxy) pairs, matched longest-prefix-first.
39
+ routes: list[tuple[str, UDSProxy]] = []
40
+ for backend in config.backends:
41
+ timeout = _CORE_TIMEOUT if backend.name == "intentframe-server" else _DEFAULT_TIMEOUT
42
+ proxy = UDSProxy(
43
+ config.socket_path(backend),
44
+ f"http://{backend.upstream_host}",
45
+ timeout=timeout,
46
+ )
47
+ proxies[backend.name] = proxy
48
+ for prefix in backend.prefixes:
49
+ routes.append((prefix, proxy))
50
+ routes.sort(key=lambda item: len(item[0]), reverse=True)
51
+
52
+ @asynccontextmanager
53
+ async def lifespan(_app: FastAPI):
54
+ logger.info(
55
+ "intentframe-edge starting (run_dir=%s, backends=%s, tls=%s, mtls=%s, auth=%s)",
56
+ config.run_dir,
57
+ list(proxies),
58
+ config.tls_enabled,
59
+ config.mtls_enabled,
60
+ bool(config.auth_token),
61
+ )
62
+ yield
63
+ for proxy in proxies.values():
64
+ await proxy.close()
65
+
66
+ # Docs/OpenAPI are disabled: this is a network-facing ingress, not a
67
+ # browsable API. Disabling them also avoids the duplicate-operation-id
68
+ # warning the single catch-all route would otherwise emit.
69
+ app = FastAPI(
70
+ title="IntentFrame Edge",
71
+ lifespan=lifespan,
72
+ docs_url=None,
73
+ redoc_url=None,
74
+ openapi_url=None,
75
+ )
76
+
77
+ def _check_auth(request: Request) -> None:
78
+ if not config.auth_token:
79
+ return
80
+ provided = request.headers.get("authorization", "")
81
+ expected = f"Bearer {config.auth_token}"
82
+ if not hmac.compare_digest(provided, expected):
83
+ raise HTTPException(status_code=401, detail="Unauthorized")
84
+
85
+ def _match(path: str) -> UDSProxy | None:
86
+ for prefix, proxy in routes:
87
+ if path == prefix or path.startswith(prefix + "/"):
88
+ return proxy
89
+ return None
90
+
91
+ @app.get("/health")
92
+ async def health() -> JSONResponse:
93
+ backends = {name: await p.health() for name, p in proxies.items()}
94
+ ok = all(backends.values())
95
+ # 503 when any backend is down so container/k8s health probes
96
+ # (which only inspect the status code) can detect a degraded edge.
97
+ return JSONResponse(
98
+ status_code=200 if ok else 503,
99
+ content={"status": "ok" if ok else "degraded", "backends": backends},
100
+ )
101
+
102
+ @app.api_route(
103
+ "/{full_path:path}",
104
+ methods=["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD"],
105
+ )
106
+ async def proxy_route(full_path: str, request: Request) -> Response:
107
+ _check_auth(request)
108
+ path = request.url.path
109
+ proxy = _match(path)
110
+ if proxy is None:
111
+ raise HTTPException(status_code=404, detail=f"No edge route for {path}")
112
+ return await proxy.forward(request, path)
113
+
114
+ return app
115
+
116
+
117
+ app = create_app()
@@ -0,0 +1,164 @@
1
+ """Edge configuration — backends, run dir, listen address, TLS, auth.
2
+
3
+ Everything is env-overridable so the edge can be configured entirely
4
+ from a container environment (docker-compose, k8s) with no code change.
5
+
6
+ The backend list is admin-owned data, not edge logic. It is read from a YAML
7
+ profile (``INTENTFRAME_EDGE_CONFIG`` / ``--config``) when provided, falling back
8
+ to the in-code minimal default. The minimal default deliberately exposes only
9
+ the substrate services that every deployment runs (``policy-registry`` and
10
+ ``intentframe-server``); the ``resource-registry`` ``/workspaces`` route is
11
+ optional and lives in the first-party kit profile
12
+ (kit `edge_profile.yaml` in the installed package), mirroring the supervisor's
13
+ registry-less default + opt-in kit profile split.
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ import logging
19
+ import os
20
+ from pathlib import Path
21
+
22
+ import yaml
23
+ from pydantic import BaseModel, Field
24
+
25
+ logger = logging.getLogger("intentframe.edge")
26
+
27
+
28
+ def _default_run_dir() -> Path:
29
+ return Path(
30
+ os.environ.get(
31
+ "INTENTFRAME_RUN_DIR",
32
+ os.path.expanduser("~/.intentframe/run"),
33
+ )
34
+ )
35
+
36
+
37
+ class Backend(BaseModel):
38
+ """A single upstream service reached over its UDS.
39
+
40
+ ``prefixes`` are the HTTP path prefixes routed to this backend. The
41
+ edge matches the longest prefix first, so backends never collide.
42
+ """
43
+
44
+ name: str
45
+ socket_name: str
46
+ # Label used as the httpx base_url host (cosmetic; UDS ignores host).
47
+ upstream_host: str
48
+ prefixes: tuple[str, ...]
49
+
50
+
51
+ # Minimal default: only the substrate services every deployment runs.
52
+ # ``resource-registry`` (/workspaces) is optional and added by the first-party
53
+ # kit profile (edge_profile.yaml in the installed native-kit package). Executor and
54
+ # credential-vault are intentionally never exposed — they stay UDS-only inside
55
+ # the environment.
56
+ DEFAULT_BACKENDS: list[Backend] = [
57
+ Backend(
58
+ name="policy-registry",
59
+ socket_name="policy-registry.sock",
60
+ upstream_host="policy-registry",
61
+ prefixes=("/policies",),
62
+ ),
63
+ Backend(
64
+ name="intentframe-server",
65
+ socket_name="intentframe.sock",
66
+ upstream_host="intentframe",
67
+ prefixes=("/handshake", "/process", "/audit"),
68
+ ),
69
+ ]
70
+
71
+
72
+ class EdgeConfig(BaseModel):
73
+ """Top-level edge configuration."""
74
+
75
+ run_dir: Path = Field(default_factory=_default_run_dir)
76
+ host: str = "0.0.0.0"
77
+ port: int = 8443
78
+
79
+ # Optional shared bearer token. When set, every proxied request must
80
+ # carry ``Authorization: Bearer <token>``. (mTLS is handled at the
81
+ # TLS layer below; this is a coarse app-level gate on top of it.)
82
+ auth_token: str | None = None
83
+
84
+ # Optional TLS. When cert+key are set the edge serves HTTPS; adding
85
+ # ca enables mutual TLS (client-cert required).
86
+ tls_cert: str | None = None
87
+ tls_key: str | None = None
88
+ tls_ca: str | None = None
89
+
90
+ backends: list[Backend] = Field(default_factory=lambda: list(DEFAULT_BACKENDS))
91
+
92
+ def socket_path(self, backend: Backend) -> Path:
93
+ return self.run_dir / backend.socket_name
94
+
95
+ @property
96
+ def tls_enabled(self) -> bool:
97
+ return bool(self.tls_cert and self.tls_key)
98
+
99
+ @property
100
+ def mtls_enabled(self) -> bool:
101
+ return self.tls_enabled and bool(self.tls_ca)
102
+
103
+
104
+ def _load_config_file(path: Path) -> EdgeConfig:
105
+ """Validate an edge profile YAML into an :class:`EdgeConfig`.
106
+
107
+ The YAML typically carries only a ``backends:`` list (the routable upstream
108
+ set); network fields (host/port/TLS/auth) keep their defaults and are
109
+ overlaid from env afterwards, so one profile works across deployments.
110
+ """
111
+ with open(path) as fh:
112
+ data = yaml.safe_load(fh)
113
+ if not isinstance(data, dict):
114
+ raise ValueError(f"Edge config must be a YAML mapping: {path}")
115
+ return EdgeConfig.model_validate(data)
116
+
117
+
118
+ def load_edge_config() -> EdgeConfig:
119
+ """Build config from a profile file (if any) overlaid with env.
120
+
121
+ The backend graph comes from ``INTENTFRAME_EDGE_CONFIG`` (a YAML profile)
122
+ when set, else the in-code minimal default. ``INTENTFRAME_EDGE_*`` env vars
123
+ always override the network-facing fields on top.
124
+ """
125
+ config_path = os.environ.get("INTENTFRAME_EDGE_CONFIG")
126
+ if config_path:
127
+ path = Path(config_path)
128
+ if not path.exists():
129
+ raise FileNotFoundError(f"Edge config not found: {path}")
130
+ config = _load_config_file(path)
131
+ else:
132
+ config = EdgeConfig()
133
+
134
+ if run_dir := os.environ.get("INTENTFRAME_RUN_DIR"):
135
+ config.run_dir = Path(run_dir)
136
+ if host := os.environ.get("INTENTFRAME_EDGE_HOST"):
137
+ config.host = host
138
+ if port := os.environ.get("INTENTFRAME_EDGE_PORT"):
139
+ config.port = int(port)
140
+
141
+ config.auth_token = os.environ.get("INTENTFRAME_EDGE_TOKEN") or None
142
+ config.tls_cert = os.environ.get("INTENTFRAME_EDGE_TLS_CERT") or None
143
+ config.tls_key = os.environ.get("INTENTFRAME_EDGE_TLS_KEY") or None
144
+ config.tls_ca = os.environ.get("INTENTFRAME_EDGE_TLS_CA") or None
145
+
146
+ _warn_on_insecure_config(config)
147
+ return config
148
+
149
+
150
+ def _warn_on_insecure_config(config: EdgeConfig) -> None:
151
+ """Surface easy-to-miss misconfigurations as loud warnings."""
152
+ # Partial TLS: exactly one of cert/key set silently disables TLS.
153
+ if bool(config.tls_cert) != bool(config.tls_key):
154
+ logger.warning(
155
+ "Partial TLS config: both INTENTFRAME_EDGE_TLS_CERT and "
156
+ "INTENTFRAME_EDGE_TLS_KEY are required — TLS will stay DISABLED "
157
+ "(serving plain HTTP)."
158
+ )
159
+ # Bearer token over plaintext travels in the clear.
160
+ if config.auth_token and not config.tls_enabled:
161
+ logger.warning(
162
+ "INTENTFRAME_EDGE_TOKEN is set but TLS is disabled — the bearer "
163
+ "token will be sent in cleartext. Enable TLS for any real network."
164
+ )
@@ -0,0 +1,38 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "intentframe-edge"
7
+ version = "0.1.0"
8
+ description = "IntentFrame edge ingress — HTTP/TLS front door for runtime Unix domain socket services"
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.14"
13
+ authors = [{ name = "IntentFrame Contributors" }]
14
+ keywords = ["ai", "agents", "security", "intentframe", "edge"]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Intended Audience :: Developers",
18
+ "Programming Language :: Python :: 3",
19
+ "Topic :: Security",
20
+ ]
21
+ dependencies = [
22
+ "intentframe-proxy==0.1.0",
23
+ "fastapi",
24
+ "pydantic>=2.12.5",
25
+ "pyyaml>=6.0.3",
26
+ "uvicorn[standard]",
27
+ ]
28
+
29
+ [project.urls]
30
+ Homepage = "https://github.com/intentframe/intentframe"
31
+ Repository = "https://github.com/intentframe/intentframe"
32
+ Issues = "https://github.com/intentframe/intentframe/issues"
33
+
34
+ [project.scripts]
35
+ intentframe-edge = "intentframe_edge.__main__:main"
36
+
37
+ [tool.hatch.build.targets.wheel]
38
+ packages = ["intentframe_edge"]