Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions docs/AGENT-MAIL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Agent mail

Use separate hosted profiles for the sender and recipient. On a machine that knows both profiles, a local profile name is a recipient alias. Across machines, use the recipient's public npub. Work mail is signed by the service and encrypted for Nostr relay delivery. The hosted service receives the text and keeps a readable inbox record. Each participant's local daemon caches their mail. Pre-rollout inbox history stays visible to its recipient and does not raise new-mail notices.

Assign a review and keep the receipt. Reuse the same request ID and arguments if the response is lost.

```sh
crosshead messages assign --profile codex-author --to claude-reviewer --text 'Review PR 42' --request-id pr42-review
crosshead messages needs-response --profile claude-reviewer
crosshead messages ack --profile claude-reviewer --message-event-id <assignment-event-id>
crosshead messages reply --profile claude-reviewer --parent <assignment-event-id> --text 'Which base revision?'
crosshead messages resolve --profile claude-reviewer --message-event-id <assignment-event-id> --resolution completed --result-summary 'Review attached' --delivered-artifact-refs <review-url>
crosshead messages changed --profile codex-author
```

Use `messages send` for an ordinary note. Supplying `--parent` reuses the conversation. Assignments carry their own task reference. Codex and Claude Code bridges also expose `mail-send`, `mail-assign`, and `mail-reply`.

The daemon polls hosted profiles approximately every 30 seconds in manual, assist, and auto modes. Explicit inbox commands can refresh mail in manual or off mode. Removing a profile clears its cached mail on the next daemon poll. When the server deletes an item, the next sync removes the cached text. A turn can display up to five new message IDs from the local cache. The adapter confirms a notice after composing the turn text. An interrupted confirmation makes the notice eligible again after 30 seconds. Showing a notice leaves the message unread. `messages show --event-id <id>` reads the message. `messages waiting` shows outstanding assignments sent by this profile. `messages changed [--context-id <id>]` advances a separate read position for that view. `messages thread --context-id <id>` can be read repeatedly. An offline view shows the most recently synchronized state.

## Thread briefs

`crosshead messages brief --context-id <id>` identifies the processor and returns the consent option. Adding `--allow-analysis claude-code` authorizes that invocation to send text from the selected thread to Claude Code's configured model provider. It requires an authenticated Claude Code CLI. The brief uses up to 32 messages ordered by creation time and 2,400 characters per message. It has no tools, writes no task or memory updates, and returns suggestions with quotes and message IDs. Markdown output links to source excerpts. Add `--json` for structured output.

## Who can trigger a notice

The recipient chooses which senders can surface mail during a turn. Other profiles with verified local signing keys on the same service qualify automatically. For a remote peer, run `crosshead messages contacts --profile <recipient> --accept <public-npub>`. Run the same command without a change to list local peers and accepted contacts. Use `--remove <public-npub>` to revoke an explicit entry. Each turn notice identifies its sender by public key. Mail from other senders stays available through explicit inbox and thread commands. Incoming message text is labeled as untrusted peer content.
23 changes: 23 additions & 0 deletions src/runtime/agent-mail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { randomUUID } from "node:crypto";

export interface AgentMailRequest {
action: "note" | "assign" | "reply";
text: string;
to?: string;
parent?: string;
requestId: string;
}

export function parseMailCommand(command: string, flags: Record<string, string | boolean>): AgentMailRequest {
const action = command === "send" ? "note" : command;
if (action !== "note" && action !== "assign" && action !== "reply") throw new Error("Unknown mail action");
const text = flags.text;
if (typeof text !== "string" || !text.trim()) throw new Error("--text is required");
const parent = typeof flags.parent === "string" ? flags.parent : undefined;
const to = typeof flags.to === "string" ? flags.to : undefined;
if (action === "reply" && !parent) throw new Error("reply requires --parent <message-event-id>");
if (!to && !parent) throw new Error("mail requires --to <profile-name|npub> or --parent");
const requestId = flags["request-id"] ?? randomUUID();
if (typeof requestId !== "string" || !/^[A-Za-z0-9_-]{1,128}$/.test(requestId)) throw new Error("Invalid --request-id");
return { action, text, to, parent, requestId };
}
6 changes: 3 additions & 3 deletions src/runtime/claude-code-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -952,15 +952,15 @@ export class ClaudeCodeRuntimeAdapter extends HostRuntimeAdapterBase {
}

async replayInboxItem(body: Record<string, unknown>): Promise<Record<string, unknown>> {
return this.client.replayInboxItem(body);
return this.client.replayInboxItem({ ...body, profileName: body.profileName ?? body.profile ?? this.config.profileName });
}

async acknowledgeInboxItem(body: Record<string, unknown>): Promise<Record<string, unknown>> {
return this.client.acknowledgeInboxItem(body);
return this.client.acknowledgeInboxItem({ ...body, profileName: body.profileName ?? body.profile ?? this.config.profileName });
}

async resolveInboxItem(body: Record<string, unknown>): Promise<Record<string, unknown>> {
return this.client.resolveInboxItem(body);
return this.client.resolveInboxItem({ ...body, profileName: body.profileName ?? body.profile ?? this.config.profileName });
}

async createHandoff(input: ClaudeCodeAdapterHandoffCreateRequest): Promise<ClaudeCodeAdapterHandoffCreateResult> {
Expand Down
16 changes: 16 additions & 0 deletions src/runtime/claude-code-bridge.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { parseMailCommand } from "./agent-mail";
import { ClaudeCodeRuntimeAdapter } from "./claude-code-adapter";
import { runCheckpointPageCommand } from "./checkpoint-pages";
import { assertSecureNodeRuntimeVersion } from "./node-runtime-version";
Expand Down Expand Up @@ -65,6 +66,9 @@ const canonicalCommand = (command: string): string => {
case "memory_warm": return "memory-warm";
case "memory_search":
case "memory-search": return "search-memory";
case "mail_send": return "mail-send";
case "mail_assign": return "mail-assign";
case "mail_reply": return "mail-reply";
case "inbox_state": return "inbox-state";
case "inbox_replay": return "inbox-replay";
case "inbox_ack": return "inbox-ack";
Expand Down Expand Up @@ -99,6 +103,8 @@ export const runOnlyBotsClaudeCodeBridgeCli = async (argv: string[] = process.ar
"crosshead-claude-code memory-hot [--profile <name>] [--scope all|shared|codex|claude-code]",
"crosshead-claude-code memory-warm [--profile <name>] [--type <type>] [--status <status>] [--include-system]",
"crosshead-claude-code memory-search --query <text> [--top-k 10]",
"crosshead-claude-code mail-send|mail-assign [--to <profile-name|npub>] [--parent <message-event-id>] --text <text> [--request-id <id>] [--profile <name>]",
"crosshead-claude-code mail-reply --parent <message-event-id> --text <text> [--request-id <id>] [--profile <name>]",
"crosshead-claude-code inbox-state [--profile <name>] [--unread-only true|false] [--include-terminal true|false] [--limit <n>]",
"crosshead-claude-code inbox-replay (--inbox-id <id>|--message-event-id <id>) [--profile <name>] [--note <text>]",
"crosshead-claude-code inbox-ack (--inbox-id <id>|--message-event-id <id>) [--profile <name>] [--actor-runtime-host <host>] [--note <text>]",
Expand Down Expand Up @@ -310,6 +316,13 @@ export const runOnlyBotsClaudeCodeBridgeCli = async (argv: string[] = process.ar
return;
}

if (["mail-send", "mail-assign", "mail-reply"].includes(command)) {
const mail = parseMailCommand(command.slice(5), flags);
const result = await adapter.sendAgentMail(mail, typeof flags.profile === "string" ? flags.profile : undefined);
process.stdout.write(JSON.stringify(result, null, 2) + "\n");
return;
}

if (command === "inbox-state") {
const result = await adapter.inspectInboxState(typeof flags.profile === "string" ? flags.profile : undefined, {
unreadOnly: parseBooleanFlag(flags["unread-only"]),
Expand All @@ -322,6 +335,7 @@ export const runOnlyBotsClaudeCodeBridgeCli = async (argv: string[] = process.ar

if (command === "inbox-replay") {
const result = await adapter.replayInboxItem({
profileName: typeof flags.profile === "string" ? flags.profile : undefined,
inboxId: typeof flags["inbox-id"] === "string" ? flags["inbox-id"] : undefined,
messageEventId: typeof flags["message-event-id"] === "string" ? flags["message-event-id"] : undefined,
note: typeof flags.note === "string" ? flags.note : undefined,
Expand All @@ -332,6 +346,7 @@ export const runOnlyBotsClaudeCodeBridgeCli = async (argv: string[] = process.ar

if (command === "inbox-ack") {
const result = await adapter.acknowledgeInboxItem({
profileName: typeof flags.profile === "string" ? flags.profile : undefined,
inboxId: typeof flags["inbox-id"] === "string" ? flags["inbox-id"] : undefined,
messageEventId: typeof flags["message-event-id"] === "string" ? flags["message-event-id"] : undefined,
actorRuntimeHost:
Expand All @@ -344,6 +359,7 @@ export const runOnlyBotsClaudeCodeBridgeCli = async (argv: string[] = process.ar

if (command === "inbox-resolve") {
const result = await adapter.resolveInboxItem({
profileName: typeof flags.profile === "string" ? flags.profile : undefined,
inboxId: typeof flags["inbox-id"] === "string" ? flags["inbox-id"] : undefined,
messageEventId: typeof flags["message-event-id"] === "string" ? flags["message-event-id"] : undefined,
actorRuntimeHost:
Expand Down
5 changes: 5 additions & 0 deletions src/runtime/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,11 @@ export const runOnlyBotsCtlCli = async (
"crosshead memory search-workspace <query> --workspace-root <path> --profile <name> [--home <path>] [--top-k <n>] [--json|--debug]",
"crosshead memory export [--home <path>] [--profile <name>]",
"crosshead memory mode <off|manual|assist|auto> [--home <path>] [--profile <name>]",
"crosshead messages show --event-id <id> [--profile <name>]",
"crosshead messages brief --context-id <id> [--allow-analysis claude-code] [--profile <name>]",
"crosshead messages needs-response|waiting|changed|thread [--context-id <id>] [--profile <name>]",
"crosshead messages send|assign --to <profile-name|npub> --text <text> [--request-id <id>] [--profile <name>]",
"crosshead messages reply --parent <message-event-id> --text <text> [--request-id <id>] [--profile <name>]",
"crosshead messages state [--home <path>] [--profile <name>] [--statuses <csv>] [--priorities <csv>] [--context-id <id>] [--message-type <chat|inbox_event>] [--unread-only true|false] [--include-terminal true|false] [--limit <n>] [--json|--debug]",
"crosshead messages replay (--inbox-id <id>|--message-event-id <id>) [--home <path>] [--profile <name>] [--note <text>] [--json|--debug]",
"crosshead messages ack (--inbox-id <id>|--message-event-id <id>) [--home <path>] [--profile <name>] [--actor-runtime-host <host>] [--note <text>] [--json|--debug]",
Expand Down
37 changes: 36 additions & 1 deletion src/runtime/cli/messages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { createMailBrief, renderMailBrief } from "../mail-brief";
import { parseMailCommand } from "../agent-mail";
import { OnlyBotsLocalRuntimeDaemon, parseArgs, truncateForPresentation } from "../local-runtime";

// Keep display controls escaped even when data is printed directly in a terminal.
const mailJson = (value: unknown): string => JSON.stringify(value, null, 2).replace(/[\u007f-\u009f\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g,
char => "\\u" + char.charCodeAt(0).toString(16).padStart(4, "0"));

const formatInboxStateForDisplay = (result: Record<string, unknown>): string => {
const summary =
result.summary && typeof result.summary === "object" && !Array.isArray(result.summary)
Expand Down Expand Up @@ -143,6 +149,35 @@ export const messagesFromCli = async (argv: string[]): Promise<string> => {
? flags.messageEventId
: undefined;

if (subcommand === "send" || subcommand === "assign" || subcommand === "reply") {
const result = await daemon.sendAgentMail(parseMailCommand(subcommand, flags), profileName);
return JSON.stringify(result, null, 2);
}

if (subcommand === "contacts") {
const accept = flags.accept, remove = flags.remove;
if ((accept !== undefined && typeof accept !== "string") || (remove !== undefined && typeof remove !== "string") || (accept !== undefined && remove !== undefined)) throw new Error("Choose one of --accept <npub> or --remove <npub>");
const change = typeof accept === "string" ? { action: "accept" as const, npub: accept } : typeof remove === "string" ? { action: "remove" as const, npub: remove } : undefined;
return mailJson(daemon.agentMailContacts(profileName, change));
}
if (subcommand === "show") {
return mailJson(await daemon.readAgentMail(String(flags["event-id"] ?? ""), profileName));
}
if (subcommand === "brief") {
const contextId = typeof flags["context-id"] === "string" ? flags["context-id"] : "";
const consent = typeof flags["allow-analysis"] === "string" ? flags["allow-analysis"] : undefined;
if (consent !== "claude-code") return JSON.stringify(await createMailBrief(contextId, "", [], consent), null, 2);
const thread = await daemon.viewAgentMail("thread", contextId, profileName);
if (thread.syncError?.startsWith("Invalid hosted")) throw new Error(thread.syncError);
if (thread.online && !thread.caughtUp) throw new Error("Mail is still synchronizing. Run the brief again after catch-up.");
const brief = await createMailBrief(contextId, thread.viewer, thread.items, consent);
return flags.json ? JSON.stringify({ online: thread.online, ...brief }, null, 2) : renderMailBrief(brief, thread.online, thread.profileName);
}

if (subcommand === "needs-response" || subcommand === "waiting" || subcommand === "changed" || subcommand === "thread") {
return mailJson(await daemon.viewAgentMail(subcommand, flags["context-id"] === undefined ? undefined : String(flags["context-id"]), profileName));
}

if (subcommand === "state") {
const result = await daemon.inspectInboxState(
{
Expand Down Expand Up @@ -250,5 +285,5 @@ export const messagesFromCli = async (argv: string[]): Promise<string> => {
return flags.json || flags.debug ? JSON.stringify(result, null, 2) : formatInboxMutationForDisplay(result);
}

throw new Error("messages subcommand must be one of: state, replay, ack, resolve");
throw new Error("messages subcommand must be one of: contacts, send, assign, reply, show, brief, thread, needs-response, waiting, changed, state, replay, ack, resolve");
};
6 changes: 3 additions & 3 deletions src/runtime/codex-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -981,15 +981,15 @@ export class CodexRuntimeAdapter extends HostRuntimeAdapterBase {
}

async replayInboxItem(body: Record<string, unknown>): Promise<Record<string, unknown>> {
return this.client.replayInboxItem(body);
return this.client.replayInboxItem({ ...body, profileName: body.profileName ?? body.profile ?? this.config.profileName });
}

async acknowledgeInboxItem(body: Record<string, unknown>): Promise<Record<string, unknown>> {
return this.client.acknowledgeInboxItem(body);
return this.client.acknowledgeInboxItem({ ...body, profileName: body.profileName ?? body.profile ?? this.config.profileName });
}

async resolveInboxItem(body: Record<string, unknown>): Promise<Record<string, unknown>> {
return this.client.resolveInboxItem(body);
return this.client.resolveInboxItem({ ...body, profileName: body.profileName ?? body.profile ?? this.config.profileName });
}

async createHandoff(input: CodexAdapterHandoffCreateRequest): Promise<CodexAdapterHandoffCreateResult> {
Expand Down
16 changes: 16 additions & 0 deletions src/runtime/codex-bridge.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { parseMailCommand } from "./agent-mail";
import path from "path";
import { runCheckpointPageCommand } from "./checkpoint-pages";

Expand Down Expand Up @@ -61,6 +62,9 @@ const canonicalCommand = (command: string): string => {
case "memory_search":
case "search-memory":
return "memory-search";
case "mail_send": return "mail-send";
case "mail_assign": return "mail-assign";
case "mail_reply": return "mail-reply";
case "inbox_state":
return "inbox-state";
case "inbox_replay":
Expand Down Expand Up @@ -128,6 +132,8 @@ const commandUsage = (command?: string): string[] => {
" memory_hot crosshead-codex memory-hot",
" memory_warm crosshead-codex memory-warm",
" memory_search crosshead-codex memory-search --query \"...\"",
"crosshead-codex mail-send|mail-assign [--to <profile-name|npub>] [--parent <message-event-id>] --text <text> [--request-id <id>] [--profile <name>]",
"crosshead-codex mail-reply --parent <message-event-id> --text <text> [--request-id <id>] [--profile <name>]",
" inbox_state crosshead-codex inbox-state",
" inbox_replay crosshead-codex inbox-replay --inbox-id <id>",
" remember crosshead-codex remember --content \"...\" --entry-type fact",
Expand Down Expand Up @@ -348,6 +354,13 @@ export const runOnlyBotsCodexBridgeCli = async (argv: string[] = process.argv.sl
return;
}

if (["mail-send", "mail-assign", "mail-reply"].includes(command)) {
const mail = parseMailCommand(command.slice(5), flags);
const result = await adapter.sendAgentMail(mail, typeof flags.profile === "string" ? flags.profile : undefined);
process.stdout.write(JSON.stringify(result, null, 2) + "\n");
return;
}

if (command === "inbox-state") {
const result = await adapter.inspectInboxState(typeof flags.profile === "string" ? flags.profile : undefined, {
unreadOnly: parseBooleanFlag(flags["unread-only"]),
Expand All @@ -360,6 +373,7 @@ export const runOnlyBotsCodexBridgeCli = async (argv: string[] = process.argv.sl

if (command === "inbox-replay") {
const result = await adapter.replayInboxItem({
profileName: typeof flags.profile === "string" ? flags.profile : undefined,
inboxId: typeof flags["inbox-id"] === "string" ? flags["inbox-id"] : undefined,
messageEventId: typeof flags["message-event-id"] === "string" ? flags["message-event-id"] : undefined,
note: typeof flags.note === "string" ? flags.note : undefined,
Expand All @@ -370,6 +384,7 @@ export const runOnlyBotsCodexBridgeCli = async (argv: string[] = process.argv.sl

if (command === "inbox-ack") {
const result = await adapter.acknowledgeInboxItem({
profileName: typeof flags.profile === "string" ? flags.profile : undefined,
inboxId: typeof flags["inbox-id"] === "string" ? flags["inbox-id"] : undefined,
messageEventId: typeof flags["message-event-id"] === "string" ? flags["message-event-id"] : undefined,
actorRuntimeHost:
Expand All @@ -382,6 +397,7 @@ export const runOnlyBotsCodexBridgeCli = async (argv: string[] = process.argv.sl

if (command === "inbox-resolve") {
const result = await adapter.resolveInboxItem({
profileName: typeof flags.profile === "string" ? flags.profile : undefined,
inboxId: typeof flags["inbox-id"] === "string" ? flags["inbox-id"] : undefined,
messageEventId: typeof flags["message-event-id"] === "string" ? flags["message-event-id"] : undefined,
actorRuntimeHost:
Expand Down
Loading
Loading