Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a70c5fd124 | ||
|
|
5c62d287cf | ||
|
|
9ae378c2e3 | ||
|
|
7381738f0b | ||
|
|
8c6b0c0e07 | ||
|
|
ec9626503c |
58
SPEC.md
58
SPEC.md
@@ -855,7 +855,63 @@ The broker:
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 13. Encryption
|
## 13. Claude Code Integration — How Push Delivery Works
|
||||||
|
|
||||||
|
Understanding how Claude Code processes channel notifications is critical for claudemesh reliability.
|
||||||
|
|
||||||
|
### The notification pipeline
|
||||||
|
|
||||||
|
```
|
||||||
|
MCP server (claudemesh-cli)
|
||||||
|
└─ server.notification("notifications/claude/channel", { content, meta })
|
||||||
|
└─ writes JSON-RPC to stdout
|
||||||
|
└─ Claude Code reads from MCP process stdout
|
||||||
|
└─ setNotificationHandler fires
|
||||||
|
└─ enqueue({ mode: "prompt", value: wrappedContent, origin: { kind: "channel" } })
|
||||||
|
└─ React useSyncExternalStore triggers re-render
|
||||||
|
└─ useQueueProcessor effect fires
|
||||||
|
└─ processQueueIfReady() → executeInput()
|
||||||
|
└─ Claude sees ← claudemesh: ...
|
||||||
|
```
|
||||||
|
|
||||||
|
### Key requirements (from Claude Code source)
|
||||||
|
|
||||||
|
1. **Feature gate**: `feature('KAIROS') || feature('KAIROS_CHANNELS')` must be true. `KAIROS_CHANNELS` is external (GrowthBook). `--dangerously-load-development-channels` sets `entry.dev = true` which bypasses the allowlist check but still requires the feature gate.
|
||||||
|
|
||||||
|
2. **OAuth auth required**: Channel notifications require `claude.ai` authentication (OAuth tokens). API key users are blocked. This means `claude login --for-claude-ai` must have been run.
|
||||||
|
|
||||||
|
3. **Server name must match**: The MCP server's declared name (`new Server({ name: "claudemesh" })`) must match the channel entry from `--dangerously-load-development-channels server:claudemesh`.
|
||||||
|
|
||||||
|
4. **Meta keys**: Must match `/^[a-zA-Z_][a-zA-Z0-9_]*$/`. No hyphens. All values must be strings.
|
||||||
|
|
||||||
|
5. **Capability declaration**: Server must declare `experimental: { "claude/channel": {} }` in capabilities.
|
||||||
|
|
||||||
|
6. **Queue processing is event-driven**: `enqueue()` triggers a React store update → `useEffect` fires → processes immediately. No polling needed on the Claude Code side. The 1s poll timer in claudemesh is for draining the WS push buffer into notifications — Claude Code handles the rest instantly.
|
||||||
|
|
||||||
|
### Priority gating on the broker
|
||||||
|
|
||||||
|
The broker holds `"next"` and `"low"` priority messages when the peer's status is `"working"`. Only `"now"` messages deliver immediately regardless of status. This is by design — but can cause perceived "push not working" when the hook reports `working` status.
|
||||||
|
|
||||||
|
```
|
||||||
|
Status: idle → delivers: now, next, low
|
||||||
|
Status: working → delivers: now only
|
||||||
|
Status: dnd → delivers: now only
|
||||||
|
```
|
||||||
|
|
||||||
|
If a peer appears to not receive messages, check their status in `list_peers`. A peer stuck in `"working"` (e.g., stale hook) will only receive `"now"` priority messages.
|
||||||
|
|
||||||
|
### Common issues
|
||||||
|
|
||||||
|
| Symptom | Likely cause |
|
||||||
|
|---------|-------------|
|
||||||
|
| Messages never arrive | Session started before CLI update — restart with `claudemesh launch` |
|
||||||
|
| Messages arrive with 5+ minute delay | Peer status stuck on `"working"` — `next` messages held until idle |
|
||||||
|
| `← claudemesh:` never appears in idle session | Feature gate `KAIROS_CHANNELS` not enabled, or not OAuth-authenticated |
|
||||||
|
| Messages arrive only on `check_messages` | Channel handler not registered — check `--dangerously-load-development-channels` flag |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 14. Encryption
|
||||||
|
|
||||||
### Direct messages
|
### Direct messages
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "claudemesh-cli",
|
"name": "claudemesh-cli",
|
||||||
"version": "0.5.1",
|
"version": "0.5.5",
|
||||||
"description": "Claude Code MCP client for claudemesh — peer mesh messaging between Claude sessions.",
|
"description": "Claude Code MCP client for claudemesh — peer mesh messaging between Claude sessions.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"claude-code",
|
"claude-code",
|
||||||
|
|||||||
@@ -707,6 +707,58 @@ Your message mode is "${messageMode}".
|
|||||||
return text(lines.join("\n"));
|
return text(lines.join("\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case "ping_mesh": {
|
||||||
|
const { priorities: pingPriorities } = (args ?? {}) as { priorities?: string[] };
|
||||||
|
const toTest = (pingPriorities ?? ["now", "next"]) as Priority[];
|
||||||
|
const client = allClients()[0];
|
||||||
|
if (!client) return text("ping_mesh: not connected", true);
|
||||||
|
const results: string[] = [];
|
||||||
|
|
||||||
|
for (const prio of toTest) {
|
||||||
|
const sendTime = Date.now();
|
||||||
|
const pingId = `ping-${sendTime}-${prio}`;
|
||||||
|
// Send to self (broadcast) — should bounce back through the broker
|
||||||
|
const sendResult = await client.send("*", `__ping__${pingId}`, prio);
|
||||||
|
const ackTime = Date.now();
|
||||||
|
|
||||||
|
if (!sendResult.ok) {
|
||||||
|
results.push(`[${prio}] SEND FAILED: ${sendResult.error}`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait up to 10s for the ping to arrive in pushBuffer
|
||||||
|
let received = false;
|
||||||
|
let receiveTime = 0;
|
||||||
|
for (let i = 0; i < 100; i++) {
|
||||||
|
await new Promise(r => setTimeout(r, 100));
|
||||||
|
const buffer = client.pushHistory;
|
||||||
|
const match = buffer.find(m =>
|
||||||
|
m.plaintext?.includes(pingId) || false
|
||||||
|
);
|
||||||
|
if (match) {
|
||||||
|
received = true;
|
||||||
|
receiveTime = Date.now();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (received) {
|
||||||
|
results.push(
|
||||||
|
`[${prio}] OK — send→ack: ${ackTime - sendTime}ms, send→receive: ${receiveTime - sendTime}ms`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Check peer status
|
||||||
|
const peers = await client.listPeers();
|
||||||
|
const selfStatus = peers.find(p => p.displayName === myName)?.status ?? "unknown";
|
||||||
|
results.push(
|
||||||
|
`[${prio}] NOT RECEIVED in 10s (your status: ${selfStatus}${selfStatus === "working" ? " — broker holds next/low" : ""})`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return text(`Ping results:\n${results.join("\n")}`);
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return text(`Unknown tool: ${name}`, true);
|
return text(`Unknown tool: ${name}`, true);
|
||||||
}
|
}
|
||||||
@@ -722,19 +774,20 @@ Your message mode is "${messageMode}".
|
|||||||
// any mesh's broker connection becomes a <channel source="claudemesh">
|
// any mesh's broker connection becomes a <channel source="claudemesh">
|
||||||
// system reminder injected into Claude Code's context.
|
// system reminder injected into Claude Code's context.
|
||||||
for (const client of allClients()) {
|
for (const client of allClients()) {
|
||||||
|
// Event-driven push: WS onPush fires immediately when a message arrives.
|
||||||
|
// Claude Code's setNotificationHandler → enqueue → React useEffect pipeline
|
||||||
|
// processes notifications instantly (no polling needed on Claude's side).
|
||||||
|
// The old poll-based approach was an overcorrection — Claude Code source
|
||||||
|
// confirms event-driven notification processing.
|
||||||
client.onPush(async (msg) => {
|
client.onPush(async (msg) => {
|
||||||
// In "off" mode, silently skip notification — messages are still
|
|
||||||
// buffered in pushBuffer and accessible via check_messages.
|
|
||||||
if (messageMode === "off") return;
|
if (messageMode === "off") return;
|
||||||
|
|
||||||
const fromPubkey = msg.senderPubkey || "";
|
const fromPubkey = msg.senderPubkey || "";
|
||||||
// Resolve sender's display name from the cached peer list.
|
|
||||||
const fromName = fromPubkey
|
const fromName = fromPubkey
|
||||||
? await resolvePeerName(client, fromPubkey)
|
? await resolvePeerName(client, fromPubkey)
|
||||||
: "unknown";
|
: "unknown";
|
||||||
|
|
||||||
if (messageMode === "inbox") {
|
if (messageMode === "inbox") {
|
||||||
// Count-only notification, no content
|
|
||||||
try {
|
try {
|
||||||
await server.notification({
|
await server.notification({
|
||||||
method: "notifications/claude/channel",
|
method: "notifications/claude/channel",
|
||||||
@@ -747,7 +800,7 @@ Your message mode is "${messageMode}".
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// push mode — full content notification
|
// push mode — full content
|
||||||
const content = msg.plaintext ?? decryptFailedWarning(fromPubkey);
|
const content = msg.plaintext ?? decryptFailedWarning(fromPubkey);
|
||||||
try {
|
try {
|
||||||
await server.notification({
|
await server.notification({
|
||||||
@@ -766,8 +819,9 @@ Your message mode is "${messageMode}".
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch {
|
process.stderr.write(`[claudemesh] pushed: from=${fromName} content=${content.slice(0, 60)}\n`);
|
||||||
/* channel push is best-effort; check_messages is the fallback */
|
} catch (pushErr) {
|
||||||
|
process.stderr.write(`[claudemesh] push FAILED: ${pushErr}\n`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -555,4 +555,21 @@ export const TOOLS: Tool[] = [
|
|||||||
"Get a complete overview of the mesh: peers, groups, state, memory, files, tasks, streams, tables. Call on session start for full situational awareness.",
|
"Get a complete overview of the mesh: peers, groups, state, memory, files, tasks, streams, tables. Call on session start for full situational awareness.",
|
||||||
inputSchema: { type: "object", properties: {} },
|
inputSchema: { type: "object", properties: {} },
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// --- Diagnostics ---
|
||||||
|
{
|
||||||
|
name: "ping_mesh",
|
||||||
|
description:
|
||||||
|
"Send test messages through the full pipeline and measure round-trip timing per priority. Diagnoses push delivery issues.",
|
||||||
|
inputSchema: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
priorities: {
|
||||||
|
type: "array",
|
||||||
|
items: { type: "string", enum: ["now", "next", "low"] },
|
||||||
|
description: "Priorities to test (default: [\"now\", \"next\"])",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ ENV NEXT_PUBLIC_URL=$NEXT_PUBLIC_URL
|
|||||||
ENV NEXT_PUBLIC_PRODUCT_NAME=$NEXT_PUBLIC_PRODUCT_NAME
|
ENV NEXT_PUBLIC_PRODUCT_NAME=$NEXT_PUBLIC_PRODUCT_NAME
|
||||||
ENV NEXT_PUBLIC_DEFAULT_LOCALE=$NEXT_PUBLIC_DEFAULT_LOCALE
|
ENV NEXT_PUBLIC_DEFAULT_LOCALE=$NEXT_PUBLIC_DEFAULT_LOCALE
|
||||||
|
|
||||||
|
# TURBOPACK=0 forces webpack for production build — Payload CMS's
|
||||||
|
# richtext-lexical CSS imports fail under Turbopack.
|
||||||
|
ENV TURBOPACK=0
|
||||||
RUN npx turbo run build --filter=web...
|
RUN npx turbo run build --filter=web...
|
||||||
|
|
||||||
# Stage 2: runtime — standalone output only
|
# Stage 2: runtime — standalone output only
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import { RootPage, generatePageMetadata } from "@payloadcms/next/views";
|
|||||||
import { importMap } from "../importMap";
|
import { importMap } from "../importMap";
|
||||||
import config from "@payload-config";
|
import config from "@payload-config";
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
type Args = { params: Promise<{ segments: string[] }> };
|
type Args = { params: Promise<{ segments: string[] }> };
|
||||||
|
|
||||||
export const generateMetadata = ({ params }: Args) =>
|
export const generateMetadata = ({ params }: Args) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user