agentconnect-cli 0.1.0a2__tar.gz → 0.1.0a3__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 (66) hide show
  1. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/PKG-INFO +11 -11
  2. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/README.md +9 -9
  3. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/pyproject.toml +2 -2
  4. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/pyproject.toml.orig +2 -2
  5. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/__init__.py +1 -1
  6. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/a2a_adapter/adapter.py +40 -10
  7. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/a2a_adapter/facade.py +109 -14
  8. agentconnect_cli-0.1.0a3/src/agentconnect/a2a_adapter/serve.py +190 -0
  9. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/config.py +33 -5
  10. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/isolation.py +21 -0
  11. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/schemas.py +0 -6
  12. agentconnect_cli-0.1.0a2/src/agentconnect/a2a_adapter/serve.py +0 -67
  13. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/a2a_adapter/__init__.py +0 -0
  14. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/a2a_adapter/cards.py +0 -0
  15. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/a2a_adapter/convert.py +0 -0
  16. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/a2a_adapter/seen.py +0 -0
  17. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/adapter.py +0 -0
  18. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/adapters.py +0 -0
  19. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/api_tls.py +0 -0
  20. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/apiclient.py +0 -0
  21. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/backoff.py +0 -0
  22. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/callback.py +0 -0
  23. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/cli.py +0 -0
  24. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/cli_json.py +0 -0
  25. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/cli_support.py +0 -0
  26. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/clock.py +0 -0
  27. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/daemon/__init__.py +0 -0
  28. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/deliveries.py +0 -0
  29. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/directory_client.py +0 -0
  30. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/failpoints.py +0 -0
  31. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/identity.py +0 -0
  32. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/keystore.py +0 -0
  33. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/limits.py +0 -0
  34. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/log.py +0 -0
  35. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/mcp/__init__.py +0 -0
  36. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/mcp/backend.py +0 -0
  37. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/mcp/server.py +0 -0
  38. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/mcp/session.py +0 -0
  39. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/mcp/tools.py +0 -0
  40. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/ownerfile.py +0 -0
  41. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/payloads.py +0 -0
  42. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/policy.py +0 -0
  43. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/provision.py +0 -0
  44. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/py.typed +0 -0
  45. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/relay.py +0 -0
  46. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/runtime/__init__.py +0 -0
  47. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/runtime/agent.py +0 -0
  48. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/runtime/api.py +0 -0
  49. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/runtime/engine.py +0 -0
  50. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/runtime/errors.py +0 -0
  51. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/runtime/floor.py +0 -0
  52. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/runtime/groups.py +0 -0
  53. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/runtime/knocks.py +0 -0
  54. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/runtime/ledger.py +0 -0
  55. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/runtime/listing.py +0 -0
  56. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/runtime/registry.py +0 -0
  57. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/runtime/runtime.py +0 -0
  58. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/runtime/sas.py +0 -0
  59. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/sas_emoji.py +0 -0
  60. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/shapes.py +0 -0
  61. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/sockets.py +0 -0
  62. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/sse.py +0 -0
  63. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/store.py +0 -0
  64. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/tasks.py +0 -0
  65. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/tokens.py +0 -0
  66. {agentconnect_cli-0.1.0a2 → agentconnect_cli-0.1.0a3}/src/agentconnect/webhook.py +0 -0
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agentconnect-cli
3
- Version: 0.1.0a2
3
+ Version: 0.1.0a3
4
4
  Summary: AgentConnect daemon (agentconnectd) and CLI
5
5
  License-Expression: Apache-2.0
6
6
  Requires-Dist: a2a-sdk[http-server,signing]>=1.2.3
7
- Requires-Dist: agentconnect-core==0.1.0a2
7
+ Requires-Dist: agentconnect-core==0.1.0a3
8
8
  Requires-Dist: cryptography>=50.0.2
9
9
  Requires-Dist: httpx>=0.28.1
10
10
  Requires-Dist: keyring>=25.7.0
@@ -21,8 +21,8 @@ Description-Content-Type: text/markdown
21
21
 
22
22
  The AgentConnect daemon (`agentconnectd`) and CLI (`agentconnect`). The
23
23
  distribution is `agentconnect-cli`; the command and the import package are
24
- `agentconnect`. See the repository [README](https://github.com/mbocevski/agent-connect/blob/v0.1.0a2/README.md) and
25
- [SPEC.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a2/SPEC.md).
24
+ `agentconnect`. See the repository [README](https://github.com/mbocevski/agent-connect/blob/v0.1.0a3/README.md) and
25
+ [SPEC.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a3/SPEC.md).
26
26
 
27
27
  ```sh
28
28
  agentconnect daemon run [--config PATH] [--tcp-port N] # foreground, JSON logs on stderr
@@ -32,12 +32,12 @@ agentconnect status [--json] # reads the local API
32
32
  Everything protocol-related is in the runtime, `agentconnect.runtime`
33
33
  (`Runtime`, with its engine, local API, adapters and agent-scope
34
34
  `AgentApi`). `agentconnectd` (`agentconnect.daemon`) is one host of it; the
35
- Python SDK's embedded mode (`AgentConnect.embedded`, [docs/sdk.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a2/docs/sdk.md))
35
+ Python SDK's embedded mode (`AgentConnect.embedded`, [docs/sdk.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a3/docs/sdk.md))
36
36
  is the other. Both run the same checks, and both serve the local API below.
37
37
 
38
38
  The invite lifecycle (`group`, `invite`, `accept`, `groups`, `approvals`,
39
39
  `verify`, `leave`, `send`, `events`) is documented in
40
- [docs/cli.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a2/docs/cli.md), with the `--json` schemas and exit codes.
40
+ [docs/cli.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a3/docs/cli.md), with the `--json` schemas and exit codes.
41
41
  `approvals approve`, `approvals reject` and `verify` use the human token:
42
42
  **never give an agent the human token or let it run those commands for the
43
43
  human.**
@@ -46,7 +46,7 @@ Don't give agents shell or file access to the data directory either: an
46
46
  agent that can read it can approve joins and mark codes verified as you,
47
47
  because the human token is a file there. Agents that need a shell can run
48
48
  as another OS user, with the daemon under a user of its own
49
- ([docs/isolation.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a2/docs/isolation.md)).
49
+ ([docs/isolation.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a3/docs/isolation.md)).
50
50
 
51
51
  ## What the daemon holds
52
52
 
@@ -64,14 +64,14 @@ as another OS user, with the daemon under a user of its own
64
64
 
65
65
  The data directory (`~/.local/share/agentconnect`) is 0700 and every file in
66
66
  it 0600. Configuration is `~/.config/agentconnect/config.toml`; see
67
- [docs/config.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a2/docs/config.md) for the keys and the `AC_*` overrides.
67
+ [docs/config.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a3/docs/config.md) for the keys and the `AC_*` overrides.
68
68
 
69
69
  ## Local control API
70
70
 
71
71
  JSON over HTTP/1.1 on a Unix socket in the data directory, or on
72
72
  `https://127.0.0.1:<port>` (TLS with a certificate the clients pin). Every
73
73
  request needs `Authorization: Bearer <token>`.
74
- [docs/api.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a2/docs/api.md) describes the transport, tokens, errors and
74
+ [docs/api.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a3/docs/api.md) describes the transport, tokens, errors and
75
75
  every route with its request and response shapes.
76
76
 
77
77
  Two tokens live in the data directory: `api-token` (agent scope) and
@@ -99,7 +99,7 @@ repeat a message or an event. Every delivery has a stable `msg_id` and every
99
99
  event a stable `event_id`; deduplicate by them. Nothing is lost: an event is
100
100
  recorded before the adapter hears of it and sent again on restart until
101
101
  `on_event` returns (ADR-004).
102
- The webhook adapter ([docs/adapters/webhook.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a2/docs/adapters/webhook.md)) and the SSE adapter (`GET /v0/events`, [docs/api.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a2/docs/api.md#event-stream)) serve headless agents.
102
+ The webhook adapter ([docs/adapters/webhook.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a3/docs/adapters/webhook.md)) and the SSE adapter (`GET /v0/events`, [docs/api.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a3/docs/api.md#event-stream)) serve headless agents.
103
103
  `CallbackAdapter` (`agentconnect.callback`) is the embedded SDK's in-process adapter, with the webhook's retry rules. `RecordingAdapter` is the in-memory adapter used by tests. Every message in
104
104
  and out goes through the safety policy (`agentconnect.policy`) before any
105
- adapter sees it ([docs/safety.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a2/docs/safety.md)).
105
+ adapter sees it ([docs/safety.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a3/docs/safety.md)).
@@ -2,8 +2,8 @@
2
2
 
3
3
  The AgentConnect daemon (`agentconnectd`) and CLI (`agentconnect`). The
4
4
  distribution is `agentconnect-cli`; the command and the import package are
5
- `agentconnect`. See the repository [README](https://github.com/mbocevski/agent-connect/blob/v0.1.0a2/README.md) and
6
- [SPEC.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a2/SPEC.md).
5
+ `agentconnect`. See the repository [README](https://github.com/mbocevski/agent-connect/blob/v0.1.0a3/README.md) and
6
+ [SPEC.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a3/SPEC.md).
7
7
 
8
8
  ```sh
9
9
  agentconnect daemon run [--config PATH] [--tcp-port N] # foreground, JSON logs on stderr
@@ -13,12 +13,12 @@ agentconnect status [--json] # reads the local API
13
13
  Everything protocol-related is in the runtime, `agentconnect.runtime`
14
14
  (`Runtime`, with its engine, local API, adapters and agent-scope
15
15
  `AgentApi`). `agentconnectd` (`agentconnect.daemon`) is one host of it; the
16
- Python SDK's embedded mode (`AgentConnect.embedded`, [docs/sdk.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a2/docs/sdk.md))
16
+ Python SDK's embedded mode (`AgentConnect.embedded`, [docs/sdk.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a3/docs/sdk.md))
17
17
  is the other. Both run the same checks, and both serve the local API below.
18
18
 
19
19
  The invite lifecycle (`group`, `invite`, `accept`, `groups`, `approvals`,
20
20
  `verify`, `leave`, `send`, `events`) is documented in
21
- [docs/cli.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a2/docs/cli.md), with the `--json` schemas and exit codes.
21
+ [docs/cli.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a3/docs/cli.md), with the `--json` schemas and exit codes.
22
22
  `approvals approve`, `approvals reject` and `verify` use the human token:
23
23
  **never give an agent the human token or let it run those commands for the
24
24
  human.**
@@ -27,7 +27,7 @@ Don't give agents shell or file access to the data directory either: an
27
27
  agent that can read it can approve joins and mark codes verified as you,
28
28
  because the human token is a file there. Agents that need a shell can run
29
29
  as another OS user, with the daemon under a user of its own
30
- ([docs/isolation.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a2/docs/isolation.md)).
30
+ ([docs/isolation.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a3/docs/isolation.md)).
31
31
 
32
32
  ## What the daemon holds
33
33
 
@@ -45,14 +45,14 @@ as another OS user, with the daemon under a user of its own
45
45
 
46
46
  The data directory (`~/.local/share/agentconnect`) is 0700 and every file in
47
47
  it 0600. Configuration is `~/.config/agentconnect/config.toml`; see
48
- [docs/config.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a2/docs/config.md) for the keys and the `AC_*` overrides.
48
+ [docs/config.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a3/docs/config.md) for the keys and the `AC_*` overrides.
49
49
 
50
50
  ## Local control API
51
51
 
52
52
  JSON over HTTP/1.1 on a Unix socket in the data directory, or on
53
53
  `https://127.0.0.1:<port>` (TLS with a certificate the clients pin). Every
54
54
  request needs `Authorization: Bearer <token>`.
55
- [docs/api.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a2/docs/api.md) describes the transport, tokens, errors and
55
+ [docs/api.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a3/docs/api.md) describes the transport, tokens, errors and
56
56
  every route with its request and response shapes.
57
57
 
58
58
  Two tokens live in the data directory: `api-token` (agent scope) and
@@ -80,7 +80,7 @@ repeat a message or an event. Every delivery has a stable `msg_id` and every
80
80
  event a stable `event_id`; deduplicate by them. Nothing is lost: an event is
81
81
  recorded before the adapter hears of it and sent again on restart until
82
82
  `on_event` returns (ADR-004).
83
- The webhook adapter ([docs/adapters/webhook.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a2/docs/adapters/webhook.md)) and the SSE adapter (`GET /v0/events`, [docs/api.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a2/docs/api.md#event-stream)) serve headless agents.
83
+ The webhook adapter ([docs/adapters/webhook.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a3/docs/adapters/webhook.md)) and the SSE adapter (`GET /v0/events`, [docs/api.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a3/docs/api.md#event-stream)) serve headless agents.
84
84
  `CallbackAdapter` (`agentconnect.callback`) is the embedded SDK's in-process adapter, with the webhook's retry rules. `RecordingAdapter` is the in-memory adapter used by tests. Every message in
85
85
  and out goes through the safety policy (`agentconnect.policy`) before any
86
- adapter sees it ([docs/safety.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a2/docs/safety.md)).
86
+ adapter sees it ([docs/safety.md](https://github.com/mbocevski/agent-connect/blob/v0.1.0a3/docs/safety.md)).
@@ -1,13 +1,13 @@
1
1
  [project]
2
2
  name = "agentconnect-cli"
3
- version = "0.1.0a2"
3
+ version = "0.1.0a3"
4
4
  description = "AgentConnect daemon (agentconnectd) and CLI"
5
5
  readme = "README.md"
6
6
  license = "Apache-2.0"
7
7
  requires-python = ">=3.12"
8
8
  dependencies = [
9
9
  "a2a-sdk[http-server,signing]>=1.2.3",
10
- "agentconnect-core==0.1.0a2",
10
+ "agentconnect-core==0.1.0a3",
11
11
  "cryptography>=50.0.2",
12
12
  "httpx>=0.28.1",
13
13
  "keyring>=25.7.0",
@@ -1,13 +1,13 @@
1
1
  [project]
2
2
  name = "agentconnect-cli"
3
- version = "0.1.0a2"
3
+ version = "0.1.0a3"
4
4
  description = "AgentConnect daemon (agentconnectd) and CLI"
5
5
  readme = "README.md"
6
6
  license = "Apache-2.0"
7
7
  requires-python = ">=3.12"
8
8
  dependencies = [
9
9
  "a2a-sdk[http-server,signing]>=1.2.3",
10
- "agentconnect-core==0.1.0a2",
10
+ "agentconnect-core==0.1.0a3",
11
11
  "cryptography>=50.0.2",
12
12
  "httpx>=0.28.1",
13
13
  "keyring>=25.7.0",
@@ -1,3 +1,3 @@
1
1
  """AgentConnect daemon and CLI."""
2
2
 
3
- __version__ = "0.1.0a2"
3
+ __version__ = "0.1.0a3"
@@ -74,7 +74,7 @@ from agentconnect.adapter import (
74
74
  Sender,
75
75
  )
76
76
  from agentconnect.clock import Clock, unix_seconds
77
- from agentconnect.isolation import receiver_uids
77
+ from agentconnect.isolation import facade_uids, receiver_uids, resolve_gid
78
78
  from agentconnect.sockets import PeerMismatchError, receiver_async_transport
79
79
  from agentconnect.tasks import cancel_and_wait
80
80
 
@@ -103,6 +103,11 @@ class A2AOptions:
103
103
  local_agent_token: str | None = field(default=None, repr=False)
104
104
  card_keys: Mapping[str, PyJWK] = field(default_factory=dict, repr=False)
105
105
  facade_port: int | None = None # None: no facade; 0: any free port
106
+ # The facade on a Unix socket instead, open to facade_uids only; created
107
+ # 0660 with the group facade_gid when set (separate-OS-user mode).
108
+ facade_socket: Path | None = None
109
+ facade_uids: frozenset[int] = frozenset()
110
+ facade_gid: int | None = None
106
111
  context_messages: int = 20
107
112
  frame_text: bool = True
108
113
  reply_timeout: float = 600.0
@@ -121,6 +126,9 @@ class A2AOptions:
121
126
  local_agent_token=token,
122
127
  card_keys=cards.load_jwks(config.a2a_card_keys_file),
123
128
  facade_port=config.a2a_facade_port if config.a2a_facade_port > 0 else None,
129
+ facade_socket=config.a2a_facade_socket,
130
+ facade_uids=facade_uids(config),
131
+ facade_gid=resolve_gid(config.isolation_group) if config.isolation else None,
124
132
  context_messages=config.a2a_context_messages,
125
133
  frame_text=config.a2a_frame_text,
126
134
  reply_timeout=float(config.a2a_reply_timeout),
@@ -310,12 +318,22 @@ class A2AAdapter:
310
318
  follow_redirects=False,
311
319
  )
312
320
  await self._load_card()
313
- if self.options.facade_port is not None and self.facade is None:
321
+ on_socket = self.options.facade_socket is not None
322
+ if (self.options.facade_port is not None or on_socket) and self.facade is None:
314
323
  self.facade_token = self._facade_token()
315
- facade = Facade(self, self.facade_token, self.options.facade_port)
324
+ facade = Facade(
325
+ self,
326
+ self.facade_token,
327
+ self.options.facade_port or 0,
328
+ path=self.options.facade_socket,
329
+ uids=self.options.facade_uids,
330
+ gid=self.options.facade_gid,
331
+ )
316
332
  await facade.start()
317
333
  self.facade = facade
318
- LOG.info("a2a_facade_started", port=facade.port)
334
+ LOG.info(
335
+ "a2a_facade_started", transport="unix" if on_socket else "tcp", port=facade.port
336
+ )
319
337
 
320
338
  async def close(self) -> None:
321
339
  """Called by ``Engine.stop``."""
@@ -590,14 +608,26 @@ class A2AAdapter:
590
608
  if status == "invalid":
591
609
  LOG.warning("a2a_local_card_invalid")
592
610
  return False
611
+ try:
612
+ client = ClientFactory(ClientConfig(httpx_client=self._http, streaming=True)).create(
613
+ card
614
+ )
615
+ plain = ClientFactory(ClientConfig(httpx_client=self._http, streaming=False)).create(
616
+ card
617
+ )
618
+ except ValueError:
619
+ # No interface the client can speak (JSON-RPC): unusable, like
620
+ # any other bad card. Whoever answers local_agent_url chooses
621
+ # the card, so it mustn't stop the runtime.
622
+ LOG.warning(
623
+ "a2a_card_unusable",
624
+ reason="no JSON-RPC interface",
625
+ configured_endpoint=_origin(self.options.local_agent_url),
626
+ )
627
+ return False
593
628
  self._card = card
594
629
  self._card_json = convert.to_json(card)
595
- self._client = ClientFactory(ClientConfig(httpx_client=self._http, streaming=True)).create(
596
- card
597
- )
598
- self._plain = ClientFactory(ClientConfig(httpx_client=self._http, streaming=False)).create(
599
- card
600
- )
630
+ self._client, self._plain = client, plain
601
631
  LOG.info("a2a_card_loaded", signature=status, skills=len(card.skills))
602
632
  return True
603
633
 
@@ -11,7 +11,10 @@ Each path serves the JSON-RPC binding at its root and its card at
11
11
  ``.well-known/agent-card.json``. Every request needs
12
12
  ``Authorization: Bearer <a2a-facade-token>``, a loopback client, a ``Host``
13
13
  of ``127.0.0.1:<port>`` or ``localhost:<port>``, and no ``Origin`` (a
14
- browser page can't reach it).
14
+ browser page can't reach it). On a Unix socket (``a2a.facade_socket``)
15
+ instead, a connection is accepted only from an admitted user, checked by
16
+ the kernel's account of its peer before anything is read; the token and
17
+ ``Origin`` rules still apply.
15
18
 
16
19
  Tasks are namespaced by group: each group has its own task store, and a
17
20
  message's ``contextId`` must be the group (or empty). The facade's task ids
@@ -26,13 +29,16 @@ from __future__ import annotations
26
29
  import asyncio
27
30
  import contextlib
28
31
  import hmac
32
+ import ipaddress
33
+ import logging
29
34
  import re
30
35
  import time
31
36
  from collections import OrderedDict
32
37
  from collections.abc import Callable
33
38
  from dataclasses import dataclass
39
+ from pathlib import Path
34
40
  from typing import TYPE_CHECKING, Any, override
35
- from urllib.parse import unquote
41
+ from urllib.parse import unquote, urlsplit
36
42
 
37
43
  import httpx
38
44
  from a2a.helpers.proto_helpers import new_task
@@ -55,6 +61,7 @@ from a2a.types import (
55
61
  Role,
56
62
  SendMessageRequest,
57
63
  Task,
64
+ TaskPushNotificationConfig,
58
65
  TaskState,
59
66
  TaskStatus,
60
67
  TaskStatusUpdateEvent,
@@ -65,9 +72,9 @@ from starlette.requests import Request
65
72
  from starlette.responses import JSONResponse, Response
66
73
  from starlette.routing import Route
67
74
 
68
- from agentconnect import log
75
+ from agentconnect import isolation, log
69
76
  from agentconnect.a2a_adapter import cards, convert
70
- from agentconnect.a2a_adapter.serve import LoopbackServer
77
+ from agentconnect.a2a_adapter.serve import LoopbackServer, UnixServer
71
78
  from agentconnect.adapter import SendReceipt
72
79
 
73
80
  if TYPE_CHECKING:
@@ -343,18 +350,85 @@ class _GroupApps:
343
350
  def __init__(self, http: httpx.AsyncClient) -> None:
344
351
  self.tasks = InMemoryTaskStore()
345
352
  self.push = InMemoryPushNotificationConfigStore()
346
- self.sender = BasePushNotificationSender(http, self.push)
353
+ self.sender = _PushSender(http, self.push, push_url_validator=loopback_push_url)
347
354
  self.apps: dict[str | None, Any] = {}
348
355
  self.handlers: list[DefaultRequestHandler] = []
349
356
 
350
357
 
358
+ # a2a-sdk logs a failed push with its URL, query secrets included, and a
359
+ # traceback; the facade logs its own event instead (_PushSender).
360
+ logging.getLogger("a2a.server.tasks.base_push_notification_sender").setLevel(logging.CRITICAL)
361
+
362
+
363
+ class _PushSender(BasePushNotificationSender):
364
+ """a2a-sdk's push sender, logging a failure with the task id only."""
365
+
366
+ @override
367
+ async def _dispatch_notification(
368
+ self, event: Any, push_info: TaskPushNotificationConfig, task_id: str
369
+ ) -> bool:
370
+ sent = await super()._dispatch_notification(event, push_info, task_id)
371
+ if not sent:
372
+ LOG.warning("a2a_facade_push_failed", task=task_id)
373
+ return sent
374
+
375
+
376
+ async def loopback_push_url(url: str) -> bool:
377
+ """Whether the facade may send push notifications to ``url``: ``http`` or
378
+ ``https`` to a literal loopback address (``127.0.0.0/8`` or ``::1``), with
379
+ no credentials (SR-31). A host name, ``localhost`` included, is refused,
380
+ so nothing is looked up and DNS rebinding has nothing to work with.
381
+ Checked when a config is set and again when a notification is sent. A
382
+ refusal is logged with its reason, never the URL."""
383
+ try:
384
+ parts = urlsplit(url)
385
+ _ = parts.port
386
+ except ValueError:
387
+ reason = "unparsable"
388
+ else:
389
+ reason = _push_url_problem(parts.scheme, parts.netloc, parts.hostname)
390
+ if reason is None:
391
+ return True
392
+ LOG.warning("a2a_facade_push_url_refused", reason=reason)
393
+ return False
394
+
395
+
396
+ def _push_url_problem(scheme: str, netloc: str, host: str | None) -> str | None:
397
+ if scheme not in ("http", "https"):
398
+ return "scheme"
399
+ if "@" in netloc:
400
+ return "credentials"
401
+ try:
402
+ address = ipaddress.ip_address(host or "")
403
+ except ValueError:
404
+ return "not an IP address"
405
+ if isinstance(address, ipaddress.IPv6Address) and address.ipv4_mapped is not None:
406
+ return "mapped address"
407
+ return None if address.is_loopback else "not loopback"
408
+
409
+
351
410
  class Facade:
352
- def __init__(self, adapter: A2AAdapter, token: str, port: int) -> None:
411
+ def __init__( # noqa: PLR0913
412
+ self,
413
+ adapter: A2AAdapter,
414
+ token: str,
415
+ port: int = 0,
416
+ *,
417
+ path: Path | None = None,
418
+ uids: frozenset[int] = frozenset(),
419
+ gid: int | None = None,
420
+ ) -> None:
353
421
  self.adapter = adapter
354
422
  self._token = token
355
- self._server = LoopbackServer(self, port)
423
+ self.path = path
424
+ self._uids = uids
425
+ self._server: LoopbackServer = (
426
+ LoopbackServer(self, port) if path is None else UnixServer(self, path, self._admit, gid)
427
+ )
356
428
  self._groups: dict[str, _GroupApps] = {}
357
- self._http = httpx.AsyncClient(timeout=10.0)
429
+ # Push notifications go to the push URL itself: never through an
430
+ # environment proxy, never on to where a redirect points (SR-30).
431
+ self._http = httpx.AsyncClient(timeout=10.0, trust_env=False, follow_redirects=False)
358
432
  # msg_id sent by the facade -> the request waiting for replies to it
359
433
  self.waiters: dict[str, asyncio.Queue[Delivery]] = {}
360
434
  # facade task id -> its peer side
@@ -377,7 +451,9 @@ class Facade:
377
451
  return self._server.addresses()
378
452
 
379
453
  def url(self, group_id: str, member: str | None = None) -> str:
380
- base = f"http://127.0.0.1:{self.port}/g/{group_id}/"
454
+ # On the socket every request goes there; the URL gives the path.
455
+ origin = "http://localhost" if self.path is not None else f"http://127.0.0.1:{self.port}"
456
+ base = f"{origin}/g/{group_id}/"
381
457
  return base if member is None else f"{base}m/{member}/"
382
458
 
383
459
  async def start(self) -> None:
@@ -499,6 +575,7 @@ class Facade:
499
575
  agent_card=cards.facade_card(self.url(group_id, member), "", "", []),
500
576
  push_config_store=group.push,
501
577
  push_sender=group.sender,
578
+ push_url_validator=loopback_push_url,
502
579
  request_context_builder=_GroupContext(group_id),
503
580
  )
504
581
  group.handlers.append(handler)
@@ -512,15 +589,33 @@ class Facade:
512
589
  group.apps[member] = app
513
590
  return app
514
591
 
592
+ def _admit(self, conn: Any) -> bool:
593
+ """Unix socket: whether the connection's user may use the facade,
594
+ from the kernel (SO_PEERCRED or getpeereid). ``conn`` is the
595
+ connection's socket, as the event loop's transport gives it."""
596
+ try:
597
+ if conn is None:
598
+ raise OSError("no socket")
599
+ uid = isolation.peer_credentials(conn).uid
600
+ except (OSError, AttributeError):
601
+ LOG.warning("a2a_facade_peer_unknown")
602
+ return False
603
+ if uid not in self._uids:
604
+ LOG.warning("a2a_facade_peer_refused", uid=uid)
605
+ return False
606
+ return True
607
+
515
608
  def _refuse(self, scope: dict[str, Any]) -> tuple[int, str] | None:
516
- client = scope.get("client")
517
- if not client or client[0] not in ("127.0.0.1", "::1"):
518
- return 403, "loopback only"
519
609
  headers = {k.decode("latin-1").lower(): v.decode("latin-1") for k, v in scope["headers"]}
520
610
  if "origin" in headers:
521
611
  return 403, "browser requests are refused"
522
- if headers.get("host") not in (f"127.0.0.1:{self.port}", f"localhost:{self.port}"):
523
- return 403, "bad host"
612
+ if self.path is None:
613
+ # On a port: loopback clients, and no DNS rebinding.
614
+ client = scope.get("client")
615
+ if not client or client[0] not in ("127.0.0.1", "::1"):
616
+ return 403, "loopback only"
617
+ if headers.get("host") not in (f"127.0.0.1:{self.port}", f"localhost:{self.port}"):
618
+ return 403, "bad host"
524
619
  scheme, _, token = headers.get("authorization", "").partition(" ")
525
620
  if scheme.lower() != "bearer" or not hmac.compare_digest(
526
621
  token.encode(), self._token.encode()
@@ -0,0 +1,190 @@
1
+ """A small ASGI server on loopback (uvicorn), started and stopped in-process.
2
+
3
+ uvicorn's own ``serve()`` installs signal handlers (the daemon owns those)
4
+ and polls; this runs only its startup, and stops by closing the listener
5
+ and cancelling the connections' tasks. :class:`UnixServer` serves a Unix
6
+ socket instead, and serves a connection only from an admitted user: one
7
+ from anyone else is aborted as the protocol is told of it, before any data
8
+ is handed to it. That holds on any event loop (asyncio, uvloop).
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import asyncio
14
+ import contextlib
15
+ import errno
16
+ import os
17
+ import socket
18
+ import stat
19
+ from collections.abc import Callable
20
+ from pathlib import Path
21
+ from typing import Any, override
22
+
23
+ import uvicorn
24
+
25
+ LOOPBACK = "127.0.0.1"
26
+
27
+
28
+ class LoopbackServer:
29
+ def __init__(self, app: Any, port: int = 0) -> None:
30
+ self._app = app
31
+ self._port = port
32
+ self._server: uvicorn.Server | None = None
33
+ self.port = 0
34
+
35
+ async def start(self) -> int:
36
+ """Listen on ``127.0.0.1:<port>`` (0: any free port); returns it."""
37
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
38
+ sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
39
+ try:
40
+ sock.bind((LOOPBACK, self._port))
41
+ except OSError:
42
+ sock.close()
43
+ raise
44
+ await self._serve_on(sock)
45
+ self.port = int(sock.getsockname()[1])
46
+ return self.port
47
+
48
+ async def _serve_on(
49
+ self, sock: socket.socket, admit: Callable[[Any], bool] | None = None
50
+ ) -> None:
51
+ config = uvicorn.Config(
52
+ self._app, lifespan="off", access_log=False, log_level="warning", log_config=None
53
+ )
54
+ config.load()
55
+ if admit is not None:
56
+ config.http_protocol_class = _admitting(config.http_protocol_class, admit)
57
+ server = uvicorn.Server(config)
58
+ server.lifespan = config.lifespan_class(config)
59
+ await server.startup(sockets=[sock])
60
+ self._server = server
61
+
62
+ def addresses(self) -> list[tuple[str, int]]:
63
+ """Where it listens (host, port)."""
64
+ if self._server is None:
65
+ return []
66
+ return [
67
+ (str(s.getsockname()[0]), int(s.getsockname()[1]))
68
+ for listener in self._server.servers
69
+ for s in listener.sockets
70
+ ]
71
+
72
+ async def stop(self) -> None:
73
+ server, self._server = self._server, None
74
+ if server is None:
75
+ return
76
+ for listener in server.servers:
77
+ listener.close()
78
+ for connection in list(server.server_state.connections):
79
+ connection.shutdown()
80
+ tasks = list(server.server_state.tasks)
81
+ for task in tasks:
82
+ task.cancel()
83
+ await asyncio.gather(*tasks, return_exceptions=True)
84
+
85
+
86
+ def _admitting(base: Any, admit: Callable[[Any], bool]) -> Any:
87
+ """uvicorn's HTTP protocol, checking each connection with ``admit``
88
+ (given the connection's socket) when it is made. A refused one is
89
+ aborted there, and the protocol never sees data from it. This is the
90
+ protocol, not the listening socket's ``accept()``, so every event loop
91
+ goes through it (uvloop accepts in C)."""
92
+
93
+ class Admitting(base):
94
+ _refused = False
95
+
96
+ def connection_made(self, transport: Any) -> None:
97
+ if not admit(transport.get_extra_info("socket")):
98
+ self._refused = True
99
+ transport.abort()
100
+ return
101
+ super().connection_made(transport)
102
+
103
+ def data_received(self, data: bytes) -> None:
104
+ if not self._refused:
105
+ super().data_received(data)
106
+
107
+ def eof_received(self) -> None:
108
+ if not self._refused:
109
+ super().eof_received()
110
+
111
+ def connection_lost(self, exc: Exception | None) -> None:
112
+ if not self._refused:
113
+ super().connection_lost(exc)
114
+
115
+ return Admitting
116
+
117
+
118
+ def _private_parent(path: Path) -> None:
119
+ """The socket's directory must be a real directory of this user that
120
+ nobody else can write to: otherwise another user could replace the
121
+ socket, or swap it for a link, after it is bound."""
122
+ st = path.parent.lstat()
123
+ if not stat.S_ISDIR(st.st_mode) or st.st_uid != os.geteuid() or st.st_mode & 0o022:
124
+ msg = f"{path.parent} must be a directory owned by this user that only it can write to"
125
+ raise PermissionError(msg)
126
+
127
+
128
+ def _in_use(path: Path) -> bool:
129
+ """Whether a server is listening on the socket at ``path``. The probe
130
+ never blocks: a listener whose queue is full is in use, and only a
131
+ refused connection (or no socket) is stale. macOS answers a full queue
132
+ with a refusal too, so there such a listener reads as stale."""
133
+ with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as probe:
134
+ probe.setblocking(False)
135
+ code = probe.connect_ex(str(path))
136
+ return code not in (errno.ECONNREFUSED, errno.ENOENT)
137
+
138
+
139
+ class UnixServer(LoopbackServer):
140
+ """The ASGI app on a Unix socket at ``path``, 0600 (0660 with the group
141
+ ``gid`` when given), in a directory only this user can write to.
142
+ ``admit`` sees each connection's socket before anything is read from
143
+ it."""
144
+
145
+ def __init__(
146
+ self,
147
+ app: Any,
148
+ path: Path,
149
+ admit: Callable[[Any], bool],
150
+ gid: int | None = None,
151
+ ) -> None:
152
+ super().__init__(app)
153
+ self.path, self._admit, self._gid = path, admit, gid
154
+
155
+ @override
156
+ async def start(self) -> int:
157
+ _private_parent(self.path)
158
+ with contextlib.suppress(FileNotFoundError):
159
+ if not stat.S_ISSOCK(self.path.lstat().st_mode):
160
+ msg = f"{self.path} exists and is not a socket; refusing to replace it"
161
+ raise FileExistsError(msg)
162
+ if _in_use(self.path):
163
+ msg = f"{self.path} is in use by a running server; refusing to replace it"
164
+ raise FileExistsError(msg)
165
+ self.path.unlink() # left behind by an earlier run
166
+ sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
167
+ # The umask is process-wide, so it is left alone: the mode is set
168
+ # right after bind, in a directory only this user can write to (so
169
+ # the path is still the socket). Until then, as after, the peer check
170
+ # decides who is served.
171
+ try:
172
+ sock.bind(str(self.path))
173
+ if not stat.S_ISSOCK(self.path.lstat().st_mode):
174
+ msg = f"{self.path} was replaced while it was bound; refusing to use it"
175
+ raise FileExistsError(msg)
176
+ except OSError:
177
+ sock.close()
178
+ raise
179
+ if self._gid is not None:
180
+ os.chown(self.path, -1, self._gid, follow_symlinks=False)
181
+ self.path.chmod(0o660)
182
+ else:
183
+ self.path.chmod(0o600)
184
+ await self._serve_on(sock, self._admit)
185
+ return 0
186
+
187
+ @override
188
+ async def stop(self) -> None:
189
+ await super().stop()
190
+ self.path.unlink(missing_ok=True)
@@ -188,6 +188,7 @@ class Config:
188
188
  a2a_local_agent_token_file: Path | None = None
189
189
  a2a_card_keys_file: Path | None = None
190
190
  a2a_facade_port: int = 0
191
+ a2a_facade_socket: Path | None = None
191
192
  a2a_context_messages: int = 20
192
193
  a2a_frame_text: bool = True
193
194
  a2a_reply_timeout: int = 600
@@ -230,7 +231,11 @@ class Config:
230
231
  @property
231
232
  def a2a_enabled(self) -> bool:
232
233
  """Whether the daemon runs the A2A adapter: a local agent, a facade or both."""
233
- return self.a2a_local_agent_url is not None or self.a2a_facade_port > 0
234
+ return (
235
+ self.a2a_local_agent_url is not None
236
+ or self.a2a_facade_port > 0
237
+ or self.a2a_facade_socket is not None
238
+ )
234
239
 
235
240
  # [policy]: the safety policy's defaults (agentconnect.policy.KNOBS).
236
241
  policy_max_message_bytes: int = KNOB["max_message_bytes"].default
@@ -528,7 +533,8 @@ CONFIG_KEYS: tuple[ConfigKey, ...] = (
528
533
  "none",
529
534
  "Base URL of the local A2A agent (loopback `http://` or `https://`) that the A2A "
530
535
  "adapter hands group messages to ([adapters/a2a.md](adapters/a2a.md)). Messages "
531
- "go only there, whatever the agent's card names.",
536
+ "go only there, whatever the agent's card names. A URL that isn't loopback, carries "
537
+ "credentials, has an invalid port or can't be parsed stops the daemon at start.",
532
538
  ),
533
539
  ConfigKey(
534
540
  "a2a.local_agent_socket",
@@ -555,7 +561,20 @@ CONFIG_KEYS: tuple[ConfigKey, ...] = (
555
561
  "a2a.facade_port",
556
562
  "a2a_facade_port",
557
563
  "`0`",
558
- "The A2A facade's port on `127.0.0.1` (0 to 65535); `0` turns it off.",
564
+ "The A2A facade's port on `127.0.0.1` (0 to 65535); `0` turns it off. Any local "
565
+ "user who holds the port while the daemon is down gets the clients' token: "
566
+ "prefer `a2a.facade_socket`.",
567
+ ),
568
+ ConfigKey(
569
+ "a2a.facade_socket",
570
+ "a2a_facade_socket",
571
+ "none",
572
+ "Serve the A2A facade on this Unix socket instead of a port: a connection is "
573
+ "accepted only from the daemon's user (and `isolation.agent_users` in the "
574
+ "separate-OS-user mode), before anything is read "
575
+ "([adapters/a2a.md](adapters/a2a.md#facade-on-a-unix-socket)). Its directory must "
576
+ "be the daemon user's, writable by nobody else. Required in the separate-OS-user "
577
+ "mode, in `isolation.agent_dir`.",
559
578
  ),
560
579
  ConfigKey(
561
580
  "a2a.context_messages",
@@ -848,7 +867,11 @@ def _a2a(data: Mapping[str, Any]) -> dict[str, Any]:
848
867
  table = _section(data, "a2a")
849
868
  url = _typed(table, "local_agent_url", str, "") or None
850
869
  if url is not None:
851
- parts = urlsplit(url)
870
+ try:
871
+ parts = urlsplit(url)
872
+ except ValueError:
873
+ msg = f"a2a.local_agent_url is not a valid URL: {url!r}"
874
+ raise ConfigError(msg) from None
852
875
  if parts.scheme not in ("http", "https") or parts.hostname is None or parts.hostname == "":
853
876
  msg = f"a2a.local_agent_url must be http:// or https://, got {url!r}"
854
877
  raise ConfigError(msg)
@@ -877,6 +900,10 @@ def _a2a(data: Mapping[str, Any]) -> dict[str, Any]:
877
900
  if not 0 <= port <= 65535: # noqa: PLR2004
878
901
  msg = "a2a.facade_port must be 0..65535"
879
902
  raise ConfigError(msg)
903
+ facade_socket = _path(table, "facade_socket")
904
+ if facade_socket is not None and port:
905
+ msg = "set a2a.facade_port or a2a.facade_socket, not both"
906
+ raise ConfigError(msg)
880
907
  context = _typed(table, "context_messages", int, 20)
881
908
  if not 0 <= context <= MAX_CONTEXT_MESSAGES:
882
909
  msg = f"a2a.context_messages must be 0..{MAX_CONTEXT_MESSAGES}"
@@ -891,6 +918,7 @@ def _a2a(data: Mapping[str, Any]) -> dict[str, Any]:
891
918
  "a2a_local_agent_token_file": _path(table, "local_agent_token_file"),
892
919
  "a2a_card_keys_file": _path(table, "card_keys_file"),
893
920
  "a2a_facade_port": port,
921
+ "a2a_facade_socket": facade_socket,
894
922
  "a2a_context_messages": context,
895
923
  "a2a_frame_text": _typed(table, "frame_text", bool, True),
896
924
  "a2a_reply_timeout": timeout,
@@ -1239,7 +1267,7 @@ def load_config(
1239
1267
  msg = 'adapter "webhook" needs webhook.callback_url or webhook.callback_socket'
1240
1268
  raise ConfigError(msg)
1241
1269
  if not cfg.a2a_enabled and "a2a" in cfg.adapter_names:
1242
- msg = 'adapter "a2a" needs a2a.local_agent_url or a2a.facade_port'
1270
+ msg = 'adapter "a2a" needs a2a.local_agent_url, a2a.facade_port or a2a.facade_socket'
1243
1271
  raise ConfigError(msg)
1244
1272
  for warning in config_warnings(cfg):
1245
1273
  LOG.warning("config_warning", warning=warning)
@@ -192,6 +192,15 @@ def receiver_uids(cfg: Config) -> frozenset[int]:
192
192
  return frozenset(resolve_uid(u) for u in cfg.isolation_agent_users)
193
193
 
194
194
 
195
+ def facade_uids(cfg: Config) -> frozenset[int]:
196
+ """Who may connect to the A2A facade's Unix socket: the daemon's own
197
+ user, and in the separate-OS-user mode the agent users too."""
198
+ uids = {os.geteuid()}
199
+ if cfg.isolation:
200
+ uids |= receiver_uids(cfg)
201
+ return frozenset(uids)
202
+
203
+
195
204
  def check_config(cfg: Config, euid: int, agent_uids: set[int], human_uids: set[int]) -> None:
196
205
  """The parts of the setup that don't need the filesystem."""
197
206
  if euid == 0:
@@ -208,6 +217,18 @@ def check_config(cfg: Config, euid: int, agent_uids: set[int], human_uids: set[i
208
217
  if cfg.a2a_local_agent_url is not None and cfg.a2a_local_agent_socket is None:
209
218
  msg = "isolation needs a2a.local_agent_socket: a TCP agent's user can't be checked"
210
219
  raise IsolationError(msg)
220
+ if cfg.a2a_facade_port:
221
+ # Any local user could hold the port and take the clients' token.
222
+ msg = "isolation needs a2a.facade_socket: a TCP client's user can't be checked"
223
+ raise IsolationError(msg)
224
+ if (
225
+ cfg.a2a_facade_socket is not None
226
+ and cfg.a2a_facade_socket.parent != cfg.isolation_agent_dir
227
+ ):
228
+ # The agent directory is the daemon's and only it can write there,
229
+ # so nobody can replace the socket; agents' users can reach it.
230
+ msg = "isolation: a2a.facade_socket must be in isolation.agent_dir"
231
+ raise IsolationError(msg)
211
232
  if (cfg.webhook_socket or cfg.a2a_local_agent_socket) is not None and not agent_uids:
212
233
  # Only an agent user may serve a receiver: with none, every
213
234
  # delivery would be refused and retried forever.
@@ -129,12 +129,6 @@ def _word(value: Any, longest: int = MAX_WORD) -> str:
129
129
  return value
130
130
 
131
131
 
132
- def _words(value: Any, most: int, longest: int) -> list[str]:
133
- if not isinstance(value, list):
134
- raise MalformedError
135
- return [_text(v, longest) for v in value[:most]]
136
-
137
-
138
132
  def _small(value: Any, most: int) -> Any:
139
133
  """A JSON value of at most ``most`` bytes, kept as it is."""
140
134
  if len(json.dumps(value, sort_keys=True, separators=(",", ":")).encode()) > most:
@@ -1,67 +0,0 @@
1
- """A small ASGI server on loopback (uvicorn), started and stopped in-process.
2
-
3
- uvicorn's own ``serve()`` installs signal handlers (the daemon owns those)
4
- and polls; this runs only its startup, and stops by closing the listener
5
- and cancelling the connections' tasks.
6
- """
7
-
8
- from __future__ import annotations
9
-
10
- import asyncio
11
- import socket
12
- from typing import Any
13
-
14
- import uvicorn
15
-
16
- LOOPBACK = "127.0.0.1"
17
-
18
-
19
- class LoopbackServer:
20
- def __init__(self, app: Any, port: int = 0) -> None:
21
- self._app = app
22
- self._port = port
23
- self._server: uvicorn.Server | None = None
24
- self.port = 0
25
-
26
- async def start(self) -> int:
27
- """Listen on ``127.0.0.1:<port>`` (0: any free port); returns it."""
28
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
29
- sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
30
- try:
31
- sock.bind((LOOPBACK, self._port))
32
- except OSError:
33
- sock.close()
34
- raise
35
- config = uvicorn.Config(
36
- self._app, lifespan="off", access_log=False, log_level="warning", log_config=None
37
- )
38
- config.load()
39
- server = uvicorn.Server(config)
40
- server.lifespan = config.lifespan_class(config)
41
- await server.startup(sockets=[sock])
42
- self._server = server
43
- self.port = int(sock.getsockname()[1])
44
- return self.port
45
-
46
- def addresses(self) -> list[tuple[str, int]]:
47
- """Where it listens (host, port)."""
48
- if self._server is None:
49
- return []
50
- return [
51
- (str(s.getsockname()[0]), int(s.getsockname()[1]))
52
- for listener in self._server.servers
53
- for s in listener.sockets
54
- ]
55
-
56
- async def stop(self) -> None:
57
- server, self._server = self._server, None
58
- if server is None:
59
- return
60
- for listener in server.servers:
61
- listener.close()
62
- for connection in list(server.server_state.connections):
63
- connection.shutdown()
64
- tasks = list(server.server_state.tasks)
65
- for task in tasks:
66
- task.cancel()
67
- await asyncio.gather(*tasks, return_exceptions=True)