Agent-Bridge är en minimal MCP-brygga byggd med Node.js + TypeScript. Den tillhandahåller ett enkelt HTTP-gränssnitt för att skicka meddelanden mellan agenter, hantera uppdragskontrakt, serialisera resurslås och strömma statusuppdateringar via Server-Sent Events.
- Meddelandehantering – Publicera, hämta och kvittera meddelanden mellan agenter.
- Task Contracts – Skapa uppdragskontrakt med status, historik, metadata och koppling till meddelanden.
- Resurslås – Enkel TTL-baserad låsning av filer/resurser med förnyelse och upplåsning.
- Event Stream – SSE-endpoint (
/events) som strömmar kontrakts-, meddelande- och låshändelser till lyssnande agenter. - Klienthjälpare –
agent-bridge-client.jserbjuder axios-wrapper, kontrakts-API, låshantering och eventprenumeration.
npm install
npm run devServern startar på port 3000 (override med PORT).
npm run build
npm startnpm test
# eller kontinuerligt
npm run test:watchnpm run test:contractsSkriptet scripts/contract-smoke-test.js startar agent-bryggan på en tillfällig port, låter Cursor- och Codex-agenterna driva ett kodgenereringsscenario och kontrollerar att filer skrivs till site/, att kontraktets metadata innehåller persistedPaths och att loggarna visar sparade artefakter. Efter körning återställs data/contracts.json så att miljön förblir oförändrad.
POST /publish_messageGET /fetch_messages/:recipientPOST /ack_message
POST /contractsGET /contracts/:idPATCH /contracts/:id/status
POST /lock_resourcePOST /renew_lockDELETE /unlock_resource/:resource
GET /events(Server-Sent Events)
POST /publish_message
{
"recipient": "codex-agent",
"sender": "cursor-agent",
"content": "{...}",
"contract": {
"title": "Analyse TypeScript config",
"initiator": "cursor-agent",
"owner": "codex-agent",
"priority": "high",
"tags": ["analysis", "typescript"],
"files": ["tsconfig.json"]
}
}Svaren innehåller messageId, contractId och serialiserat kontrakt.
PATCH /contracts/:id/status
{
"actor": "codex-agent",
"status": "in_progress",
"owner": "codex-agent",
"note": "Work started"
}Svarshuvuden:
Content-Type: text/event-stream
Cache-Control: no-cache
Connection: keep-alive
Varje event ser ut så här:
event: contract.updated
id: l7a3gxx49vul2t6m51
data: {
"id": "l7a3gxx49vul2t6m51",
"type": "contract.updated",
"timestamp": "2025-09-25T12:45:09.123Z",
"data": {
"contract": { ... serialiserad contract ... },
"actor": "codex-agent",
"note": "Work started"
}
}
Historikbufferten sparar de 100 senaste händelserna – nya klienter får historiken direkt efter anslutning. Följande händelsetyper skickas i dagsläget:
| Typ | Innehåll |
|---|---|
contract.created |
Serialiserat kontrakt (contract) |
contract.updated |
Serialiserat kontrakt + actor, note |
contract.message_linked |
contractId, messageId |
message.published |
messageId, recipient, sender, contractId |
message.acknowledged |
messageId, recipient |
lock.created |
resource, holder, ttl, expiresAt |
lock.renewed |
resource, holder, ttl, expiresAt |
lock.released |
resource, holder |
lock.expired |
resource, holder |
{
"id": "c5z7k2u4...",
"title": "Analyse TypeScript config",
"initiator": "cursor-agent",
"owner": "codex-agent",
"status": "in_progress",
"priority": "high",
"tags": ["analysis", "typescript"],
"files": ["tsconfig.json"],
"createdAt": "2025-09-25T12:30:01.000Z",
"updatedAt": "2025-09-25T12:45:09.000Z",
"metadata": {
"intent": "code_analysis",
"correlationId": "cursor-..."
},
"history": [
{
"id": "h1...",
"timestamp": "2025-09-25T12:30:01.000Z",
"actor": "cursor-agent",
"status": "proposed",
"note": "Contract created"
},
{
"id": "h2...",
"timestamp": "2025-09-25T12:45:09.000Z",
"actor": "codex-agent",
"status": "in_progress",
"note": "Work started"
}
]
}src/
contracts.ts # Kontraktsmodeller och in-memory store
index.ts # Express-app med endpoints och eventströmmar
index.test.ts # Supertest/Jest-testfall
agent-bridge-client.js # Axios/SSE-klient för agenter
autonomous-cursor-agent.js # Cursor-agent med kontrakt & eventlyssning
autonomous-codex-agent.js # Codex-agent med låshantering
start-autonomous-agents.js # Bootskript för båda agenterna
MIT
Agent-Bridge implements a Node.js-based orchestrator that coordinates agent interactions using adapter modules instead of child processes. This provides better integration and control over the agent workflow.
The orchestrator now drives a deterministic handoff protocol so Codex (implementer/verifier) and Cursor (analyst) can collaborate with structured state rather than free-form text:
- Shared envelope schema (
scripts/collaboration-protocol.mjs) – Defines normalized agent responses withplan,actions,diffs,artifacts,checks, and ahandofftarget (analyst | implementer | verifier | complete). - Normalized adapters –
src/adapters/cursor-agent-adapter.mjsandsrc/adapters/codex-agent-adapter.mjsemit envelopes instead of ad-hoc prose, keeping plans and commands deterministic for Cursor ↔ Codex loops. - Stateful orchestrator –
scripts/orchestrator.mjsfeeds each agent with the previous envelope, interprets thehandofffield to select the next role, and logs the structured envelope in conversation history for repeatability. - Deterministic verification – The verifier step explicitly requests
npm testandnpm run buildvia the whitelist-aware runner, making the collaboration loop testable end-to-end. - Executable checks – Verification envelopes trigger whitelisted commands automatically (e.g.,
npm run lint,npm test), updating envelope status and redirecting the handoff if checks fail. - Session flight recorder – Every orchestration run is persisted as a JSON transcript under
data/orchestration-history/, capturing envelopes, executed checks, outcomes, and the final handoff so a session can be replayed, audited, or resumed with full context.
The result is a repeatable loop: Cursor analyzes and shapes the task → Codex implements with concrete diffs/actions → Codex verifier runs commands and completes the task when checks pass.
The orchestrator uses adapter modules for programmatic agent integration:
src/adapters/cursor-agent-adapter.mjs- Wraps Cursor agent functionalitysrc/adapters/codex-agent-adapter.mjs- Wraps Codex agent functionalityscripts/orchestrator.mjs- Main orchestration logic with handoff markers
-
Cursor-analytiker (Analyst) - Analyzes tasks and requirements
- Handoff marker:
HANDOFF_TO_CODEX→ transitions to Implementer
- Handoff marker:
-
Codex-implementerare (Implementer) - Creates implementations
- Handoff marker:
RUN_TESTS→ transitions to Verifier
- Handoff marker:
-
Verifierare (Verifier) - Tests and validates implementations
- Completion marker:
implementation verified successfully→ completes task
- Completion marker:
The orchestrator includes a security whitelist for command execution (run_cmd):
Allowed commands:
npm test(with optional flags likenpm test -s)npm run buildnpm run lintnode <script.js>(local script files only)git statusgit diff
Blocked commands: All others are blocked with a clear warning message.
Extending the whitelist: TODO - Configuration-driven expansion planned.
# Run orchestrator with a task
npm run orchestrate -- --task "Hello world"
# Run orchestrator smoke test
npm run test:orchestrator$ npm run orchestrate -- --task "Create a calculator"
=== Node Orchestrator Starting ===
Task: "Create a calculator"
--- Turn 1 (analyst) ---
Cursor-analytiker: Analysis complete...
Next step: HANDOFF_TO_CODEX for implementation
--- Turn 2 (implementer) ---
Codex-implementerare: Implementation complete...
Next step: RUN_TESTS for verification
--- Turn 3 (verifier) ---
Verifierare: Verification complete...
Status: Implementation verified successfully
=== Task completed successfully ===Every orchestration run saves a JSON transcript to data/orchestration-history/<sessionId>.json containing:
- meta – Task description, session timestamps, final envelope, and success flag.
- history – Turn-by-turn envelopes, check executions, and responses (including the bootstrap state in turn
0).
These artifacts are ignored by git and can be reused for replay, audits, or seeding the next collaboration loop with deterministic context.
The orchestrator automatically manages the agent handoffs and ensures tasks complete within 8 turns for efficient processing.
Ett enkelt verktyg följer med för att läsa den beständiga kontraktsloggen i data/contracts.json.
# lista alla kontrakt npm run contracts:list
# visa ett enskilt kontrakt
npm run contracts:view -- <contractId>
# visa historik för ett kontrakt
npm run contracts:history -- <contractId>Kontrakt lagras automatiskt på disk och laddas vid serverstart, vilket gör att omstarter inte rensar historik.
När Codex upptäcker kritiska säkerhetsproblem eller tydliga rekommendationer skapar den automatiskt nya kontrakt åt Cursor. Dessa kontrakt syns direkt via CLI:t och i /events-strömmen.
Door /dashboard exposes a lightweight real-time view of contracts, locks, messages, and raw events streamed from /events. The static assets live in dashboard/ and can be served by running the development server and visiting the path in the browser.