Skip to main content
Glama
README.md
# Relay

Relay gives coding agents one project memory in Meko. For ContextCon Challenge 01, **One Memory, Every Coding Agent**, Claude Code recorded a private partner API contract in a shared datapack. Codex CLI received the same ticket prompt in both arms. With Relay, it retrieved and cited Claude's decision, then passed **3 of 3 partner checks on its first patch**. The baseline passed **1 of 3**. Relay also gives agents a cited task brief, a diff review against retrieved rules, and a trace that can link the design to the merge.

## Live result · 30 Nov 2026

| First patch and handoff | Baseline | Relay |
| --- | --- | --- |
| Partner field and pathname | Fail · `slot` | Pass · `deliverySlot` |
| Stable 404 partner error | Fail · `NO_SLOT_AVAILABLE` | Pass · `NO_DELIVERY_SLOT` |
| Health endpoint compatibility | Pass | Pass |
| **Partner checks passed** | **1/3** | **3/3** |
| Literal rule violations in independent scorer | 0 | 0 |
| Claude decision cited by Codex | None | `97793097-0412-4f5c-a4b3-f42394a14458` |
| Local merge reported in run summary | — | `5748e308` |

One run per arm. Both started from the Parcel API demo and used the same implementer prompt. The partner contract was supplied privately to the designer. [Run record](bench/live-2026-11-30/RESULTS.md) · [Baseline score](bench/live-2026-11-30/score-baseline.json) · [Relay score](bench/live-2026-11-30/score-relay.json) · [Codex citation](bench/live-2026-11-30/codex-relay.log) · [Claude decision trace](bench/live-2026-11-30/explain.txt)

## Judge in 5 minutes

1. **Read the live evidence.** Open the score files above and find the Claude memory ID in the Codex log. See the [video script](docs/VIDEO_SCRIPT.md) for a timed walkthrough and commands to replay the archived patches.
2. **Try the handoff offline.** From `contextcon/relay`, run the two PowerShell blocks below. You need Node 22 or later. The demo uses the local Meko stub and simulates the two agent identities with CLI calls.
3. **Rerun with your own free Meko API key.** Follow the live setup below to run both arms on fresh copies of the demo repo.

### Offline stub · two terminals

In the first terminal, leave the stub running.

```powershell
node relay.mjs stub --sse --port 0
```

In the second terminal, paste the URL printed by the first terminal when prompted.

```powershell
$env:MEKO_MODE = 'stub'
$env:MEKO_STUB_URL = Read-Host 'Paste the stub URL'
$env:RELAY_AGENT_ID = "relay:judge-$([guid]::NewGuid())"
$env:MEKO_DATAPACK_ID = ''
$env:MEKO_DATAPACK_ID = node relay.mjs datapack-create 'Relay judge demo'
node relay.mjs ingest --repo demo-repo
$decision = node relay.mjs record decision --agent claude_code:parcel --task 'RLY-12 delivery slot' --text 'Use deliverySlot in the success response.' --rationale 'The partner parser reads deliverySlot.' --evidence 'A trial response using eta failed.' | ConvertFrom-Json
node relay.mjs brief 'RLY-12 delivery slot response' --agent codex:parcel --budget 400
node relay.mjs outcome $decision.decisionId --outcome 'Ready for implementation' --evidence 'RLY-12 design handoff'
node relay.mjs explain $decision.decisionId
```

Find the memory ID from `$decision.memoryIds` under **Prior decisions** in the Codex brief and in the Claude trace printed by `explain`. Stub data clears when the server stops.

### Reproduce the live run

1. Use Git, Node 22 or later, authenticated Claude Code and Codex CLI, and a free Meko API key with write access. Follow the [candidate setup in the runbook](bench/run_real.md#1-prepare-two-identical-starting-repositories). Keep the scorer and designer prompt outside both candidate trees. Use a fresh pack name and update the Relay copy's `AGENTS.md` to match it.
2. From the Relay source directory, load `MEKO_API_KEY` in the proxy terminal and run the commands below. The archived run's Meko indexer rejected the demo `README.md`. Confirm the style guide and three ADRs report `completed`. Keep this terminal open.

   ```powershell
   $env:MEKO_MODE = 'live'
   $env:MEKO_DATAPACK_ID = ''
   $packName = "Relay Parcel $([guid]::NewGuid())"
   $env:MEKO_DATAPACK_ID = node relay.mjs datapack-create $packName
   node relay.mjs ingest --repo demo-repo
   node relay.mjs proxy
   ```

3. Enable the Relay candidate's project [MCP config](demo-repo/.mcp.json) in Claude Code. Configure the Relay Codex session with the `[mcp_servers.relay]` entry from the [sample Codex config](docs/codex-config.toml). Codex uses the loopback proxy, whose environment contains the key and datapack ID. For baseline Codex, use a separate config with both Relay and Meko disabled.
4. Start Codex in the baseline candidate and save and score its first patch. In the Relay candidate, give Claude the [designer prompt](bench/run_real.md#3-run-design-and-implementation) privately. Have Claude save the decision with `relay_record` as `claude_code:parcel` and capture the returned memory and decision IDs. Start a fresh Codex session in the Relay candidate with the same implementer prompt. The successful archived Relay run used `--approve-for-me` to enable MCP approval under `codex exec`.

   ```powershell
   $prompt = "Implement RLY-12 from docs/TICKET.md. Follow the project's normal workflow. Add and run tests. Tell me when the first complete patch is ready and list what informed the implementation."
   # Baseline candidate with Relay and Meko disabled
   $prompt | codex exec --sandbox workspace-write -
   # Relay candidate with Relay enabled
   $prompt | codex exec --sandbox workspace-write --approve-for-me -
   ```

5. Save and score each first patch before giving feedback. From each candidate, use the runbook's [patch capture and scorer commands](bench/run_real.md#3-run-design-and-implementation). Check that Relay Codex called `relay_brief` and cited the Claude memory ID. After a verified merge, use the runbook's `outcome` and `explain` commands to attach the new commit ID and inspect the trace. [Archived results](bench/live-2026-11-30/RESULTS.md)

## Architecture

```mermaid
flowchart LR
    Claude["Claude Code · design"] -->|relay_record| Proxy["Relay · loopback MCP proxy"]
    Codex["Codex CLI · implementation"] -->|relay_brief / relay_review / relay_record| Proxy
    Operator["Operator · Relay CLI"] -->|ingest / outcome / explain| Service["Relay service"]
    Proxy --> Service
    Service -->|Meko MCP| Pack["One Meko project datapack"]
    Pack --- KB["Knowledge base · style guide and ADRs"]
    Pack --- Memory["Memory · partner decision and handoff"]
    Pack --- Trace["Conversations and decision artifacts"]
    Service -.->|Offline mode| Stub["Local Meko stub"]
```

## Meko calls in the code

| Meko feature and tools | File and function | What Relay does |
| --- | --- | --- |
| Datapack · `datapack_create`, `datapack_list` | [`lib/relay.mjs`](lib/relay.mjs) · `Relay.createDatapack`, `listDatapacks`, `scope` | Creates or lists packs and scopes project calls to the selected ID. |
| Knowledge base · `knowledgebase_upload_document`, `knowledgebase_document_status`, `knowledgebase_search` | [`lib/relay.mjs`](lib/relay.mjs) · `Relay.ingest`, `#pollDocument`<br>[`lib/review.mjs`](lib/review.mjs) · `review` | Uploads style and architecture docs, polls the indexer, and searches documents for cited review rules. |
| Memory · `memory_add`, `memory_search` | [`lib/relay.mjs`](lib/relay.mjs) · `Relay.record`, `brief`<br>[`lib/review.mjs`](lib/review.mjs) · `review` | Saves reusable decisions and handoffs with JSON-encoded metadata. Searches the same pack from different agent conversations. |
| Context · `context_search` | [`lib/relay.mjs`](lib/relay.mjs) · `Relay.brief`<br>[`lib/review.mjs`](lib/review.mjs) · `review` | Collects memory, knowledge, and conversation hits. The brief surfaces `match_quality` and `agent_hint`. A low match returns guidance and skips supplemental retrieval. |
| Conversations · `conversation_create`, `conversation_add_message`, `conversation_get` | [`lib/relay.mjs`](lib/relay.mjs) · `Relay.conversation`, `record`, `outcome`, `explain`<br>[`lib/review.mjs`](lib/review.mjs) · `review` | Opens per-agent traces, appends concise rationale and plan fields with memory IDs, adds review and outcome messages, and reads the decision timeline. |
| Artifacts · `artifact_put`, `artifact_get` | [`lib/relay.mjs`](lib/relay.mjs) · `Relay.putArtifact`, `loadDecision` | Stores a decision manifest and optional evidence file, then verifies the manifest hash on retrieval. |
| Usage · `track_token_usage` | [`lib/relay.mjs`](lib/relay.mjs) · `Relay.brief` | Records the brief size as a characters-divided-by-four token estimate. |
| Promotion · `memory_promote` | [`lib/relay.mjs`](lib/relay.mjs) · `Relay.promote` | Optional explicit promotion via the CLI. The judged handoff used the shared datapack's cross-agent search. |
| Self-learning · `selflearning_status`, `selflearning_query_log`, `selflearning_verify` | [`lib/relay.mjs`](lib/relay.mjs) · `Relay.learning` | Optional CLI workflow to inspect low-match queries and replay one after updating the knowledge base. Exercised in stub tests. |

### CLI and tests

The CLI and proxy share gitignored `.relay/state.json`, keyed by Meko endpoint, datapack and agent ID. The proxy binds to loopback and pins project calls to one datapack. The MCP client discovers and validates tool schemas and handles JSON and SSE responses. [Meko live API notes](docs/MEKO_LIVE_NOTES.md)

Run `node relay.mjs help` for commands. To check a unified diff against retrieved literal rules, use `node relay.mjs review change.diff --task 'RLY-12'`. Review reports the source of each finding and returns exit code 2 if it retrieved zero checkable rules. Behavioral verification uses the separate scorer.

```text
node --test --experimental-test-isolation=none
node bench/run.mjs
```

The second command runs a separate offline simulation across 12 tasks. [Simulation results](bench/results.md) · [Challenge brief](docs/CHALLENGE_01.md) · [Submission copy](SUBMISSION.md) · [MIT license](LICENSE)