@creatornader/agent-bridge 0.2.0

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 (74) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/LICENSE +216 -0
  3. package/README.md +338 -0
  4. package/SKILL.md +24 -0
  5. package/bin/CLAUDE.md +11 -0
  6. package/bin/agent-bridge +7 -0
  7. package/clients/claude-code.json +20 -0
  8. package/clients/claude-desktop.json +20 -0
  9. package/clients/codex.json +20 -0
  10. package/clients/generic-mcp.json +13 -0
  11. package/clients/openclaw.json +13 -0
  12. package/dist/bridge-domain-BcnBeHOn.d.ts +97 -0
  13. package/dist/bridge-service-CfqMcMAn.d.ts +28 -0
  14. package/dist/bridge-store-BuGjxTn4.d.ts +61 -0
  15. package/dist/bridge.d.ts +102 -0
  16. package/dist/bridge.js +83 -0
  17. package/dist/bridge.js.map +1 -0
  18. package/dist/chunk-4KAOBC5X.js +773 -0
  19. package/dist/chunk-4KAOBC5X.js.map +1 -0
  20. package/dist/chunk-6MAZ6YLZ.js +146 -0
  21. package/dist/chunk-6MAZ6YLZ.js.map +1 -0
  22. package/dist/chunk-AXL2I7FH.js +423 -0
  23. package/dist/chunk-AXL2I7FH.js.map +1 -0
  24. package/dist/chunk-BV6W4AJK.js +211 -0
  25. package/dist/chunk-BV6W4AJK.js.map +1 -0
  26. package/dist/chunk-CKSKUBDQ.js +153 -0
  27. package/dist/chunk-CKSKUBDQ.js.map +1 -0
  28. package/dist/chunk-JOUBDRYX.js +272 -0
  29. package/dist/chunk-JOUBDRYX.js.map +1 -0
  30. package/dist/chunk-JTC5YURG.js +49 -0
  31. package/dist/chunk-JTC5YURG.js.map +1 -0
  32. package/dist/chunk-KVR4JBRF.js +80 -0
  33. package/dist/chunk-KVR4JBRF.js.map +1 -0
  34. package/dist/chunk-O26W5QHS.js +409 -0
  35. package/dist/chunk-O26W5QHS.js.map +1 -0
  36. package/dist/chunk-WEULPMUY.js +988 -0
  37. package/dist/chunk-WEULPMUY.js.map +1 -0
  38. package/dist/chunk-YD6YJATN.js +48 -0
  39. package/dist/chunk-YD6YJATN.js.map +1 -0
  40. package/dist/cli.d.ts +3 -0
  41. package/dist/cli.js +670 -0
  42. package/dist/cli.js.map +1 -0
  43. package/dist/client-config.d.ts +30 -0
  44. package/dist/client-config.js +10 -0
  45. package/dist/client-config.js.map +1 -0
  46. package/dist/client-runtime.d.ts +15 -0
  47. package/dist/client-runtime.js +15 -0
  48. package/dist/client-runtime.js.map +1 -0
  49. package/dist/gateway-BULozv3K.d.ts +54 -0
  50. package/dist/gateway-main.d.ts +2 -0
  51. package/dist/gateway-main.js +105 -0
  52. package/dist/gateway-main.js.map +1 -0
  53. package/dist/gateway.d.ts +4 -0
  54. package/dist/gateway.js +10 -0
  55. package/dist/gateway.js.map +1 -0
  56. package/dist/index.d.ts +2 -0
  57. package/dist/index.js +18 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/server.d.ts +34 -0
  60. package/dist/server.js +19 -0
  61. package/dist/server.js.map +1 -0
  62. package/dist/sqlite.d.ts +156 -0
  63. package/dist/sqlite.js +24 -0
  64. package/dist/sqlite.js.map +1 -0
  65. package/llms.txt +39 -0
  66. package/package.json +104 -0
  67. package/sql/migrations/001_schema_state.sql +34 -0
  68. package/sql/migrations/002_workspaces_agents_credentials.sql +77 -0
  69. package/sql/migrations/003_messages_receipts_deliveries.sql +116 -0
  70. package/sql/migrations/004_message_query_indexes.sql +31 -0
  71. package/sql/migrations/005_delivery_events_presence.sql +79 -0
  72. package/sql/migrations/006_legacy_shared_context_import.sql +139 -0
  73. package/sql/migrations/007_runtime_role.sql +59 -0
  74. package/sql/setup.sql +68 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,60 @@
1
+ # Changelog
2
+
3
+ All notable changes to agent-bridge are documented in this file.
4
+
5
+ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.2.0] - 2026-07-14
10
+
11
+ ### Added
12
+
13
+ - Provider-neutral stores for local SQLite, PostgreSQL, the authenticated HTTP gateway, and legacy Supabase.
14
+ - Immutable v2 messages, opaque cursors, receipts, delivery leases, retries, dead letters, transition history, and leased presence.
15
+ - SQLite gateway outbox, inbox cache, restart-safe synchronization, and explicit stale-cache results.
16
+ - Cross-platform Node CLI with init, health, delivery, sync, presence, watch, migration, and client installation commands.
17
+ - Cheap `pending` process gate for unread context or due delivery work.
18
+ - Runtime manifests and native installers for Codex, Claude Code, and Claude Desktop.
19
+ - Runtime-neutral `SKILL.md` guidance and an `llms.txt` package map.
20
+ - PostgreSQL migrations with checksum validation and runtime schema readiness checks.
21
+ - Restricted PostgreSQL runtime grants separated from schema migration credentials.
22
+ - Linux, macOS, and Windows test matrices, live PostgreSQL tests, and clean tarball installation smoke tests.
23
+
24
+ ### Changed
25
+
26
+ - Package identity is `@creatornader/agent-bridge` at version `0.2.0`. Tagged package builds are automatic; npm publication remains gated until scope access is confirmed.
27
+ - Agent identity is process-scoped. Shared config no longer supplies `AGENT_BRIDGE_AGENT`.
28
+ - Exact idempotent replays deduplicate. Reusing a key for changed content returns a conflict.
29
+ - Gateway clients authenticate through separate principal-bound credentials stored in owner-only client backend files.
30
+ - Package-root imports expose the provider-neutral API without starting the MCP server.
31
+ - `watch` runs until interrupted and retries transient gateway or legacy provider failures.
32
+
33
+ ### Security
34
+
35
+ - The v2 PostgreSQL schema is private from Supabase Data API roles.
36
+ - Remote providers require HTTPS except on loopback.
37
+ - Gateway startup validates migration checksums, required objects, credential status, and principal binding.
38
+ - Gateway startup requires a restricted runtime database URL and cannot run schema migrations.
39
+ - Local config and SQLite state use owner-only permissions where the platform supports POSIX modes.
40
+
41
+ ## [0.1.0] - 2026-05-17
42
+
43
+ First tagged release. Marks the point where agent-bridge has shipped its initial feature set, completed the public-flip prep (Apache 2.0 license, generic integration framing in docs), and integrated the public-OSS-prep tooling stack.
44
+
45
+ ### Added
46
+
47
+ - MCP server with three tools: `post_context`, `get_context`, `ack_context`. Direct fetch to Supabase REST API (no `@supabase/supabase-js`) so the MCP server and the bash CLI share the same lightweight approach.
48
+ - Bash CLI at `bin/agent-bridge` for shell-based agent integrations.
49
+ - SQL schema (`sql/setup.sql`) with the `shared_context` table, permissive RLS (anon key is the access control), and the `ack_context_atomic` RPC for race-free acknowledgement via `array_append`.
50
+ - Optional `atrib_receipt_id` column for callers that wrap writes behind an atrib signing layer. The column is format-validated and optional; agent-bridge does not require atrib integration.
51
+ - Integration with the public-OSS-prep stack: textleaks pre-commit hook, oss-twin structural mirror gate, oss-security-scan reusable CI workflow.
52
+
53
+ ### Security
54
+
55
+ - gitleaks + trufflehog + osv-scanner via the reusable workflow at `creatornader/oss-security-scan@v0.1.0`.
56
+ - Narrative-leak detection in CI + on commit via `creatornader/textleaks@v0.2.0` (renamed from leakguard).
57
+
58
+ [0.1.0]: https://github.com/creatornader/agent-bridge/releases/tag/v0.1.0
59
+ [Unreleased]: https://github.com/creatornader/agent-bridge/compare/v0.2.0...HEAD
60
+ [0.2.0]: https://github.com/creatornader/agent-bridge/compare/v0.1.0...v0.2.0
package/LICENSE ADDED
@@ -0,0 +1,216 @@
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.
203
+
204
+ Copyright 2026 Nader Helmy
205
+
206
+ Licensed under the Apache License, Version 2.0 (the "License");
207
+ you may not use this file except in compliance with the License.
208
+ You may obtain a copy of the License at
209
+
210
+ http://www.apache.org/licenses/LICENSE-2.0
211
+
212
+ Unless required by applicable law or agreed to in writing, software
213
+ distributed under the License is distributed on an "AS IS" BASIS,
214
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
215
+ implied. See the License for the specific language governing
216
+ permissions and limitations under the License.
package/README.md ADDED
@@ -0,0 +1,338 @@
1
+ # Agent Bridge
2
+
3
+ Agent Bridge is a shared messaging and work-delivery layer for AI agents that run in different clients, processes, sessions, and machines.
4
+
5
+ It supports three operating modes:
6
+
7
+ | Mode | Store | Use case |
8
+ | --- | --- | --- |
9
+ | Local | SQLite WAL | One machine, no service or account |
10
+ | Gateway | PostgreSQL plus a local SQLite edge store | Cross-machine messaging, offline sends, claims, retries, and presence |
11
+ | Legacy Supabase | Existing `shared_context` table through PostgREST | Compatibility while a v1 deployment migrates |
12
+
13
+ PostgreSQL remains the authority in gateway mode. SQLite holds local-only messages or gateway edge state. Supabase is one way to host PostgreSQL, not a protocol dependency.
14
+
15
+ ## What v2 provides
16
+
17
+ - Immutable messages with UUIDv7 IDs and opaque server cursors.
18
+ - Indexed source, thread, timestamp, workspace, and delivery queries.
19
+ - Read receipts separated from executable delivery state.
20
+ - Atomic claim, lease renewal, acknowledgment, negative acknowledgment, retry, and dead-letter operations.
21
+ - Append-only delivery transition history.
22
+ - Idempotency conflict detection. Exact replay deduplicates; changed content under the same key fails.
23
+ - Scoped credentials that bind a remote workspace and agent principal.
24
+ - SQLite outbox and inbox cache for gateway clients.
25
+ - Leased runtime presence with instance IDs and capabilities.
26
+ - MCP, CLI, Codex, Claude Code, and Claude Desktop integration paths.
27
+ - Existing `post_context`, `get_context`, `ack_context`, `post`, and `get` behavior during migration.
28
+
29
+ The accepted protocol and storage decisions live in [docs/architecture-v2.md](docs/architecture-v2.md).
30
+
31
+ ## Architecture
32
+
33
+ ```text
34
+ Codex Claude Code Claude Desktop scripts
35
+ | | | |
36
+ +--------------+------------------+-----------------+
37
+ MCP or CLI
38
+ |
39
+ process-scoped agent identity
40
+ |
41
+ +----------------+----------------+
42
+ | |
43
+ local SQLite SQLite edge store
44
+ |
45
+ authenticated HTTPS
46
+ |
47
+ Agent Bridge gateway
48
+ |
49
+ PostgreSQL
50
+ ```
51
+
52
+ Realtime notifications or hooks may wake a client, but cursored reads remain authoritative. A missed notification does not lose a message.
53
+
54
+ ## Requirements
55
+
56
+ - Node.js 22.23.1 or newer.
57
+ - SQLite 3.51.3 or newer for local and edge storage. The supported Node version includes it.
58
+ - PostgreSQL 15 or newer for gateway mode.
59
+
60
+ ## Install from source
61
+
62
+ The unscoped npm name belongs to another project. This repository uses `@creatornader/agent-bridge`. The release workflow always builds a tagged package. Publishing remains disabled until the `npm` environment has an approval rule, npm trusts `release.yml` as this package's publisher, and `NPM_PUBLISH_ENABLED` is set to `true`.
63
+
64
+ ```bash
65
+ git clone https://github.com/creatornader/agent-bridge.git
66
+ cd agent-bridge
67
+ npm ci
68
+ npm run build
69
+ npm link
70
+ ```
71
+
72
+ The package exposes three executables:
73
+
74
+ - `agent-bridge`: CLI.
75
+ - `agent-bridge-mcp`: stdio MCP server.
76
+ - `agent-bridge-gateway`: HTTP gateway.
77
+
78
+ `npm pack` builds the package before creating a tarball. CI installs that tarball into an empty project, imports the provider-neutral library API, and runs the packaged CLI. Importing the package root does not start the MCP server.
79
+
80
+ ## Local quick start
81
+
82
+ Initialize backend settings. `init` does not write an agent identity into the shared config.
83
+
84
+ ```bash
85
+ agent-bridge init --provider local
86
+ ```
87
+
88
+ Each client supplies its own identity:
89
+
90
+ ```bash
91
+ AGENT_BRIDGE_AGENT=codex agent-bridge post --category operational "Bridge is ready"
92
+ AGENT_BRIDGE_AGENT=claude-code agent-bridge get --unacked-by claude-code
93
+ ```
94
+
95
+ You can also pass `--source` to a standalone send. If the process already has `AGENT_BRIDGE_AGENT`, an explicit identity must match it.
96
+
97
+ Run a two-principal local proof:
98
+
99
+ ```bash
100
+ agent-bridge demo
101
+ ```
102
+
103
+ ## Install client integrations
104
+
105
+ Agent identity and gateway credentials belong to each client process, not the shared `~/.agent-bridge/config` file.
106
+
107
+ ```bash
108
+ agent-bridge clients install codex --identity codex
109
+ agent-bridge clients install claude-code --identity claude-code
110
+ agent-bridge clients install claude-desktop --identity claude-desktop
111
+ ```
112
+
113
+ For gateway mode, issue a distinct principal-bound token for each client and pass it only during that client's installation:
114
+
115
+ ```bash
116
+ AGENT_BRIDGE_CLIENT_TOKEN=<codex token> \
117
+ agent-bridge clients install codex --identity codex
118
+ AGENT_BRIDGE_CLIENT_TOKEN=<claude-code token> \
119
+ agent-bridge clients install claude-code --identity claude-code
120
+ AGENT_BRIDGE_CLIENT_TOKEN=<claude-desktop token> \
121
+ agent-bridge clients install claude-desktop --identity claude-desktop
122
+ ```
123
+
124
+ `--token` accepts the same value, but the environment form avoids putting a credential in shell history. Each install writes an owner-only backend file under `~/.agent-bridge/clients/`. The host MCP registration receives that file path, the client identity, and a generated instance ID. Tokens are not copied into the shared config, and one client cannot reuse a token bound to another principal.
125
+
126
+ Codex and Claude Code installation uses their native MCP commands. Claude Desktop installation merges the `agent-bridge` server into its JSON config with an atomic write. Restart the client after installation.
127
+
128
+ The runtime contracts are under [`clients/`](clients/). OpenClaw and generic MCP manifests declare the required environment variable and command but leave config mutation to the operator because their host config shapes vary.
129
+
130
+ [`SKILL.md`](SKILL.md) provides concise runtime-neutral operating instructions for agents. [`llms.txt`](llms.txt) gives tools and model crawlers a compact map of the package, modes, commands, and identity rules.
131
+
132
+ ## Gateway setup
133
+
134
+ Apply migrations to a PostgreSQL database:
135
+
136
+ ```bash
137
+ PGUSER=schema_owner PGPASSWORD='<password>' \
138
+ AGENT_BRIDGE_DATABASE_URL=postgresql://host/database \
139
+ agent-bridge migrate
140
+ ```
141
+
142
+ The migration sequence creates or refreshes a database-specific restricted role. Get its name, then create a login that inherits it. Keep the schema-owner URL out of the gateway process:
143
+
144
+ ```sql
145
+ create role agent_bridge_gateway login password '<generated password>';
146
+ do $grant$
147
+ declare
148
+ runtime_role text := 'agent_bridge_runtime_' || substr(md5(current_database()), 1, 16);
149
+ begin
150
+ execute format('grant %I to agent_bridge_gateway', runtime_role);
151
+ end
152
+ $grant$;
153
+ ```
154
+
155
+ The database-derived suffix prevents a gateway login for one database from inheriting access to another Agent Bridge database on the same PostgreSQL cluster. Do not grant the login another database's runtime role.
156
+
157
+ Create a workspace, agent, and credential with the migration or provisioning connection. Store only a SHA-256 token hash:
158
+
159
+ ```sql
160
+ insert into agent_bridge.workspaces (id, name)
161
+ values ('team', 'Team');
162
+
163
+ insert into agent_bridge.agents (workspace_id, principal, runtime_type)
164
+ values ('team', 'codex', 'codex')
165
+ returning id;
166
+
167
+ insert into agent_bridge.credentials (workspace_id, agent_id, token_hash, label)
168
+ values ('team', '<agent uuid>', '<sha256 token hash>', 'codex laptop');
169
+ ```
170
+
171
+ Repeat the agent and credential inserts for Claude Code, Claude Desktop, or any other principal. Each plaintext token should be random, unique, and shown only to the matching client installer.
172
+
173
+ Start the gateway:
174
+
175
+ ```bash
176
+ PGUSER=agent_bridge_gateway PGPASSWORD='<password>' \
177
+ AGENT_BRIDGE_RUNTIME_DATABASE_URL=postgresql://host/database \
178
+ AGENT_BRIDGE_HOST=127.0.0.1 \
179
+ AGENT_BRIDGE_PORT=8787 \
180
+ agent-bridge-gateway
181
+ ```
182
+
183
+ Put the gateway behind TLS for any non-loopback deployment.
184
+
185
+ Configure a client backend without storing its identity:
186
+
187
+ ```text
188
+ AGENT_BRIDGE_PROVIDER=gateway
189
+ AGENT_BRIDGE_URL=https://bridge.example.com
190
+ AGENT_BRIDGE_WORKSPACE=team
191
+ ```
192
+
193
+ These shared settings are enough before `clients install`. The installer takes `AGENT_BRIDGE_CLIENT_TOKEN`, creates a private client backend file containing the matching token, and registers `AGENT_BRIDGE_AGENT`, `AGENT_BRIDGE_INSTANCE`, and that file's path with the host. Gateway initialization checks readiness, token validity, and that the token-bound principal matches that process identity.
194
+
195
+ ## Offline gateway behavior
196
+
197
+ Gateway clients use `~/.agent-bridge/edge.sqlite3` by default.
198
+
199
+ When a send cannot reach the gateway:
200
+
201
+ 1. The validated message is written to the SQLite outbox with a stable idempotency key.
202
+ 2. The CLI or MCP result reports `disposition: "queued"` and `authoritative: false`.
203
+ 3. `agent-bridge sync` retries due messages in queue order and pulls remote history into the inbox cache. A permanently blocked message remains visible in diagnostics but does not stop later messages.
204
+ 4. An ambiguous retry is safe because the gateway enforces idempotency and rejects changed content under the same key.
205
+
206
+ Cached reads report `source: "cache"` and `stale: true`. Claims, lease changes, delivery settlement, presence, and read receipts require the gateway because replaying those operations after a lease or identity change is unsafe.
207
+
208
+ ## CLI
209
+
210
+ ```bash
211
+ agent-bridge init --provider local
212
+ agent-bridge doctor
213
+ agent-bridge status
214
+ agent-bridge pending
215
+ agent-bridge send --type request --target worker "Run the task"
216
+ agent-bridge post --category goal-update --project agent-bridge "Gateway is ready"
217
+ agent-bridge inbox --limit 20
218
+ agent-bridge get --since 24h --unacked-by codex
219
+ agent-bridge history --thread-id release-1
220
+ agent-bridge acknowledge --ids <message-uuid>
221
+ agent-bridge claim --lease-ms 30000
222
+ agent-bridge extend --delivery-id <uuid> --lease-token <uuid>
223
+ agent-bridge ack --delivery-id <uuid> --lease-token <uuid>
224
+ agent-bridge nack --delivery-id <uuid> --lease-token <uuid> --error "retry later"
225
+ agent-bridge join --instance desktop-1 --runtime codex --capability mcp
226
+ agent-bridge presence
227
+ agent-bridge sync
228
+ agent-bridge watch
229
+ ```
230
+
231
+ `agent-bridge pending` is a cheap shell gate for agent startup. It exits 0 when unread messages or due delivery work exists and 1 when neither exists. Its JSON result separates unread context from executable delivery work. Gateway checks fail instead of returning a false negative when the remote authority cannot confirm unread state.
232
+
233
+ `watch` runs until interrupted unless `--polls` sets an explicit bound. Empty polls use capped backoff and jitter. Gateway and legacy network failures retry when the error is transient. Authentication and validation errors stop the watcher.
234
+
235
+ Unknown flags and missing option values fail before a message can be sent. This prevents a misspelled target flag from becoming a broadcast.
236
+
237
+ ## MCP tools
238
+
239
+ All providers expose the v1 compatibility tools:
240
+
241
+ - `post_context`
242
+ - `get_context`
243
+ - `ack_context`
244
+
245
+ Local and gateway providers also expose:
246
+
247
+ - `send`
248
+ - `history`
249
+ - `claim`
250
+ - `extend`
251
+ - `acknowledge`
252
+ - `negative_acknowledge`
253
+ - `heartbeat`
254
+ - `presence`
255
+
256
+ Legacy Supabase does not advertise delivery or presence tools because its schema cannot enforce those operations.
257
+
258
+ ## Identity and security
259
+
260
+ - `~/.agent-bridge/config` contains backend settings only. A stored `AGENT_BRIDGE_AGENT` value is ignored.
261
+ - Local clients bind identity through their process environment or an explicit CLI send argument.
262
+ - Gateway tokens bind workspace and principal. The API ignores caller-supplied source and workspace fields.
263
+ - Gateway clients use separate owner-only backend files and principal-bound tokens.
264
+ - The gateway uses `AGENT_BRIDGE_RUNTIME_DATABASE_URL`. Migration and provisioning commands use the separate schema-owner `AGENT_BRIDGE_DATABASE_URL`.
265
+ - Remote HTTP must use TLS. Plain HTTP is accepted only on loopback.
266
+ - Local config, database, WAL, and shared-memory files use owner-only permissions where the platform supports POSIX modes.
267
+ - The private `agent_bridge` schema is denied to Supabase `anon` and `authenticated` Data API roles.
268
+ - Expired presence rows are pruned during heartbeat and listing. Each agent is capped at 128 active instances, and each workspace is capped at 4,096.
269
+ - Errors expose stable codes without database URLs, tokens, or provider response bodies.
270
+ - Delivery work is at least once, not exactly once. Consumers must make external side effects idempotent.
271
+
272
+ ## Legacy Supabase compatibility
273
+
274
+ Existing deployments can continue using:
275
+
276
+ ```text
277
+ AGENT_BRIDGE_PROVIDER=legacy-supabase
278
+ AGENT_BRIDGE_URL=https://your-project.supabase.co
279
+ AGENT_BRIDGE_KEY=<publishable key>
280
+ ```
281
+
282
+ Legacy mode keeps the v1 `shared_context` and `ack_context` RPC behavior. It adds bounded network calls, HTTPS enforcement, UUID mapping across CLI processes, newest-first reads, and the complete compatibility envelope. It cannot provide secure principal binding, delivery leases, presence, or an offline outbox. Use gateway mode for those features.
283
+
284
+ When gateway migrations run in the same PostgreSQL database as `public.shared_context`, migration 006 imports legacy rows and receipts into the private v2 schema. It preserves valid envelope UUIDs, keeps the existing synthetic UUID mapping for ordinary numeric IDs, assigns deterministic UUIDs to larger IDs, maps projects to workspaces, rejects ID collisions, and verifies the imported count. It does not create executable deliveries for historical targeted rows because an upgrade must not replay old work.
285
+
286
+ The original v1 schema remains in [`sql/setup.sql`](sql/setup.sql). Ordered gateway migrations live in [`sql/migrations/`](sql/migrations/).
287
+
288
+ ## Health and operations
289
+
290
+ `doctor` and `status` return JSON with:
291
+
292
+ - Provider and actual schema version.
293
+ - Bound workspace, agent, and instance.
294
+ - Endpoint or database path.
295
+ - Cursor and queue state.
296
+ - Pending, claimed, retrying, and dead delivery counts.
297
+ - Gateway reachability, outbox depth, blocked outbox rows, cache size, and last sync error.
298
+
299
+ The gateway exposes unauthenticated `/readyz`. `/v2/status` and `/metrics` require a valid credential.
300
+
301
+ Before dropping an Agent Bridge database, remove its gateway login and database-specific runtime role. Run this while connected to that database so `current_database()` still identifies the right role:
302
+
303
+ ```sql
304
+ drop role if exists agent_bridge_gateway;
305
+ do $cleanup$
306
+ declare
307
+ runtime_role text := 'agent_bridge_runtime_' || substr(md5(current_database()), 1, 16);
308
+ begin
309
+ execute format('drop role if exists %I', runtime_role);
310
+ end
311
+ $cleanup$;
312
+ ```
313
+
314
+ The runtime role owns no schema objects. PostgreSQL keeps roles after a database is dropped, so skipping this step leaves an unused cluster role behind.
315
+
316
+ ## Development
317
+
318
+ ```bash
319
+ npm run typecheck
320
+ npm test
321
+ npm run build
322
+ npm pack
323
+ ```
324
+
325
+ Set `AGENT_BRIDGE_TEST_DATABASE_URL` to run the live PostgreSQL contract and migration tests. CI runs Node 22 and 24 on Linux, macOS, and Windows, plus PostgreSQL and clean package-install jobs.
326
+
327
+ ## Documentation
328
+
329
+ - [docs/architecture-v2.md](docs/architecture-v2.md): protocol and storage decisions.
330
+ - [SKILL.md](SKILL.md): runtime-neutral agent operating instructions.
331
+ - [llms.txt](llms.txt): compact machine-readable project map.
332
+ - [docs/postmortems/2026-07-08-wrapper-source-drift.md](docs/postmortems/2026-07-08-wrapper-source-drift.md): wrapper and source-identity incident.
333
+ - [CLAUDE.md](CLAUDE.md): repository rules, architecture constraints, and documentation ownership.
334
+ - [CHANGELOG.md](CHANGELOG.md): released and pending changes.
335
+
336
+ ## License
337
+
338
+ Apache-2.0
package/SKILL.md ADDED
@@ -0,0 +1,24 @@
1
+ ---
2
+ name: agent-bridge
3
+ description: Share context and reliable work between agents across runtimes and machines.
4
+ ---
5
+
6
+ # Agent Bridge
7
+
8
+ Use the Agent Bridge MCP tools for normal traffic. Let the active runtime supply its own identity. Do not pass a literal source unless a standalone CLI process has no configured identity.
9
+
10
+ At session start, call `get_context` with a small limit. Summarize relevant unacknowledged entries, then call `ack_context` with the IDs you handled.
11
+
12
+ Post context as events happen when another agent would need the information later:
13
+
14
+ - `goal-update`: material progress, decisions, or completed research
15
+ - `config-change`: configuration or infrastructure changes
16
+ - `flag`: failures, blockers, or unsafe assumptions
17
+ - `operational`: runtime and repository handoffs
18
+ - `bridge-meta`: limitations or proposed improvements to Agent Bridge
19
+
20
+ Use v2 delivery tools for executable work. A read receipt does not claim work. Claim a delivery before acting, renew long leases, acknowledge success, and negatively acknowledge retryable or dead work with a bounded error.
21
+
22
+ Use `agent-bridge pending` as a cheap process gate before starting an agent. Exit 0 means unread context or due delivery work exists. Exit 1 means neither exists. Treat network errors as unknown state, not as an empty queue.
23
+
24
+ Keep side effects idempotent. Agent Bridge provides at-least-once delivery and idempotent message insertion, not exactly-once execution.
package/bin/CLAUDE.md ADDED
@@ -0,0 +1,11 @@
1
+ <claude-mem-context>
2
+ # Recent Activity
3
+
4
+ <!-- This section is auto-generated by claude-mem. Edit content outside the tags. -->
5
+
6
+ ### Feb 23, 2026
7
+
8
+ | ID | Time | T | Title | Read |
9
+ |----|------|---|-------|------|
10
+ | #5341 | 6:57 AM | ✅ | Agent-bridge database configuration migrated from old to new Supabase account | ~523 |
11
+ </claude-mem-context>
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { runCli } from "../dist/cli.js";
3
+
4
+ runCli().catch((error) => {
5
+ process.stderr.write(`Error: ${error instanceof Error ? error.message : String(error)}\n`);
6
+ process.exitCode = 1;
7
+ });