Skip to content

Commit 34c67f1

Browse files
author
Flow Memory Builder
committed
Add dependency-free local API server
1 parent e035a6b commit 34c67f1

11 files changed

Lines changed: 388 additions & 19 deletions

File tree

BUILD_REPORT.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,8 @@ RC1 validation updates:
278278
## Neural Agent Layer v1 build update — 2026-05-23
279279

280280
Added optional neural subsystem, synthetic datasets, tiny dual-stream perception, predictive world model, advisory plan/skill/risk/evaluation scoring, neural memory retrieval, tiny training smoke scripts, V-JEPA 2 / VideoMAE adapter seams, CLI `--neural`, FlowLang neural config, neural examples, neural benchmarks, and documentation. PyTorch remains optional and default tests skip torch-only behavior when absent.
281+
282+
283+
## Dependency-free local HTTP API server update — 2026-05-23
284+
285+
Added `src/flow_memory/api/http_server.py` and `scripts/run_local_api_server.py` to expose the internal API router through a standard-library local HTTP server. The gateway covers JSON parsing, API-key checks, optional scope enforcement, local fixed-window rate limiting, request audit events, and structured API errors. Added `tests/test_api_http_server.py` for direct gateway behavior plus an ephemeral localhost request. This remains a local/public-alpha server boundary, not production internet auth or deployment infrastructure.

FLOW_MEMORY_STATUS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ It is not production-certified. Contracts are unaudited, sandboxing is not harde
4747
| API snapshot validation | Implemented and committed as `docs/API_SNAPSHOT.json` |
4848
| API auth/signed requests | Local API-key and HMAC signed-request seam tested; not production auth |
4949
| API scopes/errors/rate limits/audit middleware | Functional local prototype; not production auth |
50+
| Dependency-free local HTTP API server | Implemented local/public-alpha server with API-key, scopes, rate limits, error contracts, and audit events; not production internet auth |
5051
| Base Sepolia dry run | Implemented no-key/no-funds artifact set and validator |
5152
| ERC-4337 adapter | UserOperation dry-run schema tested locally |
5253
| Contract registry validation | Implemented address, required-contract, and zero-address checks |

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,8 @@ Observed during the public-alpha RC1 preflight build:
136136
## Neural Agent Layer v1
137137

138138
Flow Memory now includes an optional Neural Agent Layer v1. The base install still has no PyTorch requirement. Install `flow-memory[ml]` to run tiny CPU-safe PyTorch prototypes for dual-stream perception, appearance-suppressed dorsal motion, tiny JEPA-style world modeling, advisory plan scoring, skill routing, risk scoring, and neural memory retrieval. V-JEPA 2 and VideoMAE are adapter seams that require explicit local checkpoints; Flow Memory never downloads checkpoints automatically. Neural scores never override policy or approval gates.
139+
140+
141+
## Local HTTP API server
142+
143+
Flow Memory now includes a dependency-free local HTTP API server for public-alpha operator testing. Run it with `python scripts/run_local_api_server.py --host 127.0.0.1 --port 8765`. Add `--api-key dev-local-only --require-scopes` to exercise local API-key and scope gates. This is not production internet authentication; it is a local server boundary for smoke tests, demos, and preflight tools.

docs/API.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Flow Memory API
22

3-
Flow Memory has a dependency-free internal router plus optional server seams.
3+
Flow Memory has a dependency-free internal router, a dependency-free local HTTP server, and optional server seams.
44

55
## Local router
66

@@ -60,16 +60,32 @@ python scripts/export_api_snapshot.py --write docs/API_SNAPSHOT.json
6060

6161
Use `validate_api_snapshot()` in release checks to detect accidental endpoint drift.
6262

63+
## Dependency-free local HTTP server
64+
65+
`src/flow_memory/api/http_server.py` wraps the internal router with JSON parsing, local API-key checks, optional scope enforcement, rate limiting, audit events, and the standard API error contract.
66+
67+
Run it locally:
68+
69+
```bash
70+
python scripts/run_local_api_server.py --host 127.0.0.1 --port 8765
71+
```
72+
73+
With local preflight auth:
74+
75+
```bash
76+
python scripts/run_local_api_server.py --api-key dev-local-only --require-scopes
77+
```
78+
6379
## Auth seams
6480

6581
- `src/flow_memory/api/auth.py` implements local API-key checking seam.
6682
- `src/flow_memory/api/signed_requests.py` implements signed request test seam.
6783
- DID request signatures are a documented placeholder, not production auth.
6884

69-
## Optional server
85+
## Optional FastAPI server
7086

7187
`src/flow_memory/api/server.py` exposes a FastAPI server creation seam when FastAPI is installed. FastAPI is not required by the base test suite.
7288

7389
## Status
7490

75-
The internal router, OpenAPI generation, signed request seam, and API snapshot validation are tested. Production server deployment, rate limiting, auth hardening, and public networking remain future work.
91+
The internal router, dependency-free HTTP server boundary, OpenAPI generation, signed request seam, API auth/scope/rate-limit checks, and API snapshot validation are tested. Production server deployment, replay protection, TLS termination, tenant isolation, and public networking remain future work.

docs/API_SERVER.md

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,65 @@
11
# API Server Seam
22

3-
Status: local router plus optional FastAPI seam; not a hardened public server.
3+
Status: dependency-free local HTTP server plus internal router and optional FastAPI seam; not a hardened public server.
44

55
## Purpose
66

7-
Define the boundary between Flow Memory's in-process API manifest/router and any future network-facing service. The seam keeps endpoint shape, handler dispatch, and generated OpenAPI-like metadata testable without requiring a daemon, reverse proxy, database, or cloud service.
7+
Define the boundary between Flow Memory's in-process API manifest/router and any future network-facing service. The local HTTP server gives operators a concrete public-alpha loop for health checks, scoped local API calls, JSON error contracts, request audit events, and fixed-window rate-limit testing without adding FastAPI or cloud infrastructure to the base install.
8+
9+
## Local HTTP server
10+
11+
Run the dependency-free local server:
12+
13+
```bash
14+
python scripts/run_local_api_server.py --host 127.0.0.1 --port 8765
15+
```
16+
17+
With a local development API key and scope checks:
18+
19+
```bash
20+
python scripts/run_local_api_server.py --api-key dev-local-only --require-scopes
21+
```
22+
23+
Example request:
24+
25+
```bash
26+
python - <<'PY'
27+
import json, urllib.request
28+
req = urllib.request.Request(
29+
'http://127.0.0.1:8765/health',
30+
headers={'x-flow-memory-api-key': 'dev-local-only', 'x-flow-memory-scopes': 'api:read'},
31+
)
32+
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
33+
PY
34+
```
835

936
## Local-safe behavior
1037

11-
- Default execution stays in process through the dependency-light router.
12-
- The endpoint manifest is the source of truth for route groups and handler names.
13-
- Optional FastAPI wiring may expose health and manifest routes when the dependency is installed.
14-
- Local handlers should use deterministic state, explicit inputs, and no hidden network calls.
38+
- Default execution can stay in process through `LocalApiRouter`.
39+
- `HttpApiGateway` wraps the router with JSON parsing, error contracts, optional API-key checks, optional scope enforcement, fixed-window local rate limiting, and audit events.
40+
- The endpoint manifest is still the source of truth for route groups and handler names.
41+
- Optional FastAPI wiring remains a separate application seam when the dependency is installed.
1542
- Value-bearing or externally visible operations must remain behind policy, approval, audit, and adapter boundaries.
1643

1744
## Auth seam
1845

1946
- `src/flow_memory/api/auth.py` supports local API-key checks and an explicit signed-request decision helper.
2047
- Header matching is case-insensitive for `x-flow-memory-api-key`.
48+
- `src/flow_memory/api/http_server.py` enforces local API-key and scope decisions when configured.
2149
- Signed requests use the local development signing seam and verify method, path, and payload binding.
2250
- This is test coverage for the API boundary contract, not production authentication, replay protection, tenant isolation, or key custody.
2351

24-
2552
## Limitations
2653

2754
- Not production-authenticated or internet-facing.
28-
- API-key and signed-request helpers are local seams only; there is no production authorization model, session handling, replay protection, tenant isolation, rate-limit enforcement at the HTTP edge, or production observability.
55+
- API-key and signed-request helpers are local seams only; there is no production authorization model, session handling, replay protection, tenant isolation, distributed rate limiting, TLS termination, WAF, or production observability.
2956
- Optional FastAPI support is an application seam, not a deployment architecture.
3057
- Endpoint presence does not imply that downstream blockchain, MCP/A2A, libp2p, Redis, Qdrant, Neo4j, or OPA integrations are implemented.
3158

3259
## Next implementation steps
3360

34-
1. Promote the manifest into generated OpenAPI with stable request/response schemas.
35-
2. Add authentication, authorization, replay protection, rate limits, and structured audit events at the server boundary.
36-
3. Bind each network route to explicit capability checks before handler execution.
37-
4. Add integration tests for HTTP behavior once the server contract is stable.
61+
1. Add stable request/response schema objects per endpoint.
62+
2. Add request signing/replay windows at the HTTP boundary.
63+
3. Add TLS/reverse-proxy deployment profiles.
64+
4. Add production observability hooks and structured access logs.
3865
5. Document deployment profiles separately for local development, private lab use, and audited production use.

release_evidence/bundle/index.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"bundle_hash": "8ac11903c39c504de8de4b0a2118db1fb6480f4c170041719d29ab9a1a4a3acd",
2+
"bundle_hash": "6d6ab805d8055970c859baf1df118b0ad6bd87c22d716257255ff545273cc8e6",
33
"file_hashes": {
44
"api_snapshot.json": "da9a57cefb763e79404254cf146219eeab67960f0f1f1190dcc171729b8badf3",
55
"base_artifacts.json": "48508bb9e1d31f01a687101dda8c8591fad2d5abb5a4cf70cbdc189f3638f01f",
66
"base_deployment_plan.json": "f53cfe400d5fd425326c3a83b27a8adfb9c7eb3f4baa975ff7fab4b3ad844e0d",
77
"clean_clone_validation.json": "5ec2708b78fc7041fafcbe4a4ed0f83ec5d8dbf914013c3f7b943f6a1664ff03",
88
"dependency_inventory.json": "9819542e274c038b6ad5c1c07bfaff0806e2803f26c9a329f0d59d61360ffe83",
99
"release_gates.json": "218cc98fb0a1b1ff6d4f7b2b037b9b8a93c2f5ef1fdd645809eb080c15062dfc",
10-
"release_manifest.json": "323483e8d34711f7e02f150b33d166cb428cae08a17195b500f0199f8466629a",
10+
"release_manifest.json": "c849c1ac4db5a70cfb1e9d635540174a42d8220fa5f00d308efd86b9c775b991",
1111
"storage_schema.json": "7417bed718a4783b050b61bc84f71b0351547b2a57462780641dd53d7b4885a7"
1212
},
1313
"files": [

release_evidence/bundle/release_manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@
255255
},
256256
"format": "flow-memory-release-manifest-v1",
257257
"git_branch": "main",
258-
"git_commit": "948f70d",
259-
"manifest_hash": "b7e5f6cd42a9f5b98e74f8d2f89accfc92845446f4b0557c137332454f3b69a1",
258+
"git_commit": "e035a6b",
259+
"manifest_hash": "0ec13810bf050587e94ea2e0f4a2421e85aaa844c760c55060e1b0c3ad89222f",
260260
"release_gates": {
261261
"ok": true,
262262
"results": [

scripts/run_local_api_server.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""Run the dependency-free Flow Memory local HTTP API server."""
2+
3+
from __future__ import annotations
4+
5+
import argparse
6+
import sys
7+
from pathlib import Path
8+
9+
ROOT = Path(__file__).resolve().parents[1]
10+
SRC = ROOT / "src"
11+
if str(SRC) not in sys.path:
12+
sys.path.insert(0, str(SRC))
13+
14+
from flow_memory.api.http_server import HttpApiConfig, serve_local_api
15+
16+
17+
def main() -> int:
18+
parser = argparse.ArgumentParser(description="Run Flow Memory local HTTP API server")
19+
parser.add_argument("--host", default="127.0.0.1")
20+
parser.add_argument("--port", type=int, default=8765)
21+
parser.add_argument("--api-key", default="")
22+
parser.add_argument("--require-scopes", action="store_true")
23+
parser.add_argument("--rate-limit", type=int, default=120)
24+
args = parser.parse_args()
25+
config = HttpApiConfig(
26+
host=args.host,
27+
port=args.port,
28+
api_key=args.api_key,
29+
require_scopes=args.require_scopes,
30+
rate_limit=args.rate_limit,
31+
)
32+
print(f"Flow Memory local API listening on http://{config.host}:{config.port}")
33+
serve_local_api(config)
34+
return 0
35+
36+
37+
if __name__ == "__main__":
38+
raise SystemExit(main())

src/flow_memory/api/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
"""Dependency-free local API surface."""
22

33
from flow_memory.api.manifest import API_ENDPOINTS, EndpointSpec, endpoint_manifest
4+
from flow_memory.api.http_server import HttpApiConfig, HttpApiGateway, HttpApiResponse, create_http_server
45
from flow_memory.api.router import LocalApiRouter, create_default_router
56
from flow_memory.api.snapshot import api_snapshot, validate_api_snapshot
67

78
__all__ = [
89
"API_ENDPOINTS",
910
"EndpointSpec",
11+
"HttpApiConfig",
12+
"HttpApiGateway",
13+
"HttpApiResponse",
1014
"LocalApiRouter",
1115
"api_snapshot",
1216
"create_default_router",
17+
"create_http_server",
1318
"endpoint_manifest",
1419
"validate_api_snapshot",
1520
]

0 commit comments

Comments
 (0)