agent-relay-runner 0.84.0 → 0.86.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-relay-runner",
3
- "version": "0.84.0",
3
+ "version": "0.86.0",
4
4
  "description": "Unified provider lifecycle runner for Agent Relay",
5
5
  "type": "module",
6
6
  "bin": {
@@ -20,7 +20,7 @@
20
20
  "directory": "runner"
21
21
  },
22
22
  "dependencies": {
23
- "agent-relay-sdk": "0.2.64"
23
+ "agent-relay-sdk": "0.2.66"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/bun": "latest",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "agent-relay-runner",
3
3
  "description": "Thin Agent Relay runner bridge for Claude Code",
4
- "version": "0.84.0",
4
+ "version": "0.86.0",
5
5
  "agentRelayContracts": {
6
6
  "providerPluginProtocol": 1
7
7
  }
@@ -20,11 +20,11 @@ Examples:
20
20
  ```bash
21
21
  agent-relay /reply 206 "Sounds good, I'll take a look"
22
22
  agent-relay /reply 42 "Done — the fix is in commit abc123"
23
- agent-relay /reply 42 --stdin < .agent-relay/sessions/$AGENT_RELAY_ID/tmp/reply.md
23
+ agent-relay /reply 42 --body-file .agent-relay/sessions/$AGENT_RELAY_ID/tmp/reply.md
24
24
  agent-relay /reply 42 --body-file response.md
25
25
  ```
26
26
 
27
- Use `--stdin` or `--body-file` for long replies so shell quoting does not mangle the body. Oversized replies are automatically uploaded as an Agent Relay artifact and sent as an attached concise reply.
27
+ Use `--body-file` for long replies so shell quoting does not mangle the body. Oversized replies are automatically uploaded as an Agent Relay artifact and sent as an attached concise reply.
28
28
 
29
29
  The relay creates this per-session scratch dir for you (it is git-ignored locally), so staging there never pollutes the working tree and never collides with other agents. No cleanup needed — the dir is reaped when your session ends.
30
30
 
@@ -20,11 +20,11 @@ Examples:
20
20
  ```bash
21
21
  agent-relay /reply 206 "Sounds good, I'll take a look"
22
22
  agent-relay /reply 42 "Done — the fix is in commit abc123"
23
- agent-relay /reply 42 --stdin < .agent-relay/sessions/$AGENT_RELAY_ID/tmp/reply.md
23
+ agent-relay /reply 42 --body-file .agent-relay/sessions/$AGENT_RELAY_ID/tmp/reply.md
24
24
  agent-relay /reply 42 --body-file response.md
25
25
  ```
26
26
 
27
- Use `--stdin` or `--body-file` for long replies so shell quoting does not mangle the body. Oversized replies are automatically uploaded as an Agent Relay artifact and sent as an attached concise reply.
27
+ Use `--body-file` for long replies so shell quoting does not mangle the body. Oversized replies are automatically uploaded as an Agent Relay artifact and sent as an attached concise reply.
28
28
 
29
29
  The relay creates this per-session scratch dir for you (it is git-ignored locally), so staging there never pollutes the working tree and never collides with other agents. No cleanup needed — the dir is reaped when your session ends.
30
30
 
package/src/adapter.ts CHANGED
@@ -2,6 +2,7 @@ import type { AgentProfile, Message } from "agent-relay-sdk";
2
2
  import { isRecord } from "agent-relay-sdk";
3
3
  import type { SessionEvent } from "./session-insights";
4
4
  import { messageBodyMaxCharsFromEnv } from "./config";
5
+ import { relayReplyReminderText } from "./relay-instructions";
5
6
 
6
7
  export type SemanticStatus = "idle" | "busy" | "offline" | "error";
7
8
  type ProviderWorkKind = "provider-turn" | "subagent" | "background-script";
@@ -204,7 +205,7 @@ export function profileIsVanillaBase(config: Pick<RunnerSpawnConfig, "agentProfi
204
205
  return config.agentProfile?.base === "vanilla";
205
206
  }
206
207
 
207
- export const RELAY_CONTEXT = `[agent-relay] You are connected to Agent Relay, a real-time message bus between agents and users. When you receive a relay message: read it, do what it asks, and reply through the relay when a text response is needed. Use agent-relay /react <messageId> <emoji> for lightweight acknowledgement or approval. If Relay MCP tools are available, prefer relay_reply, relay_get_message, relay_get_thread, relay_send_message, relay_upload_artifact, relay_attach_artifact, relay_agent_status, relay_find_agents, relay_compact_and_resume, relay_recall, relay_spawn_agent, and relay_shutdown_agent. You never need to know or pass your own agent id — relay fills it from your token; use relay_whoami only if you need to reason about yourself. relay_compact_and_resume is for clean-seam self-resume after a context advisory: pass workingState and optional ruledOut; Relay owns the objective envelope. relay_recall searches your own archived pre-compaction segments by keyword when a discarded detail is needed. relay_spawn_targets / relay_spawn_agent / relay_shutdown_agent only appear if your profile grants spawning (a live-children quota); when present, call relay_spawn_targets FIRST for the live host/provider/model matrix + your quota, then stand up long-living child agents and shut down your own — find them later with relay_find_agents spawnedBy:me. CLI fallback: agent-relay /reply <messageId> --stdin < response.md; if a delivered message says it was truncated, fetch the full body with: agent-relay get-message <messageId>. For command details, run: agent-relay /guide`;
208
+ export const RELAY_CONTEXT = `[agent-relay] You are connected to Agent Relay, a real-time message bus between agents and users. When you receive a relay message: read it, do what it asks, and reply through the relay when a text response is needed. Use agent-relay /react <messageId> <emoji> for lightweight acknowledgement or approval. If Relay MCP tools are available, prefer relay_reply, relay_get_message, relay_get_thread, relay_send_message, relay_upload_artifact, relay_attach_artifact, relay_agent_status, relay_find_agents, relay_compact_and_resume, relay_recall, relay_spawn_agent, and relay_shutdown_agent. You never need to know or pass your own agent id — relay fills it from your token; use relay_whoami only if you need to reason about yourself. relay_compact_and_resume is for clean-seam self-resume after a context advisory: pass workingState and optional ruledOut; Relay owns the objective envelope. relay_recall searches your own archived pre-compaction segments by keyword when a discarded detail is needed. relay_spawn_targets / relay_spawn_agent / relay_shutdown_agent only appear if your profile grants spawning (a live-children quota); when present, call relay_spawn_targets FIRST for the live host/provider/model matrix + your quota, then stand up long-living child agents and shut down your own — find them later with relay_find_agents spawnedBy:me. For replies, prefer relay_reply or relay_send_message; CLI fallback: agent-relay /reply <messageId> "<your reply>". If a delivered message says it was truncated, fetch the full body with: agent-relay get-message <messageId>. For command details, run: agent-relay /guide`;
208
209
 
209
210
  // #306 — deliver the FULL message body by default. Only a pathological body beyond this
210
211
  // high cap truncates (with a get-message hint) so it can't nuke an agent's context; the 99%
@@ -353,7 +354,7 @@ export function providerMessageText(messages: Message[]): string {
353
354
  `[truncated: showing first ${maxChars} of ${message.body.length} chars]`,
354
355
  `Read full: agent-relay get-message ${message.id}`,
355
356
  `Body only: agent-relay get-message ${message.id} --body`,
356
- `Long reply: agent-relay /reply ${message.id} --stdin < response.md`,
357
+ `Long reply CLI fallback: agent-relay /reply ${message.id} --body-file response.md`,
357
358
  ].join("\n")
358
359
  : undefined;
359
360
  if (isMemoryContext) {
@@ -375,7 +376,7 @@ export function providerMessageText(messages: Message[]): string {
375
376
  if (replyable) {
376
377
  sections.push([
377
378
  "[agent-relay reply reminder]",
378
- `If this batch needs a response, send one useful reply to the latest relevant message: agent-relay /reply ${replyable.id} --stdin < response.md`,
379
+ relayReplyReminderText(replyable.id),
379
380
  "If you already delivered the useful response through Relay, do not send a separate status-only confirmation.",
380
381
  "If multiple messages arrived together, cover them in one reply instead of answering each line separately.",
381
382
  ].join("\n"));
@@ -1,6 +1,7 @@
1
1
  import type { Message } from "agent-relay-sdk";
2
2
  import { isRecord } from "agent-relay-sdk";
3
3
  import { isNotificationMessage, NOTIFICATION_NUDGE, providerAttachmentText, providerMessageBodyMaxChars } from "../adapter";
4
+ import { relayReplyReminderText } from "../relay-instructions";
4
5
 
5
6
  const REMINDER_EVERY_DELIVERIES = 5;
6
7
 
@@ -112,10 +113,12 @@ function formatMessage(message: Message, relaySurface: boolean): string {
112
113
  function replyReminder(message: Message, readOnly: boolean): string {
113
114
  const command = readOnly
114
115
  ? `agent-relay /reply ${message.id} "<your reply>"`
115
- : `agent-relay /reply ${message.id} --stdin < response.md`;
116
+ : relayReplyReminderText(message.id);
116
117
  return [
117
118
  "[agent-relay reply reminder]",
118
- `If this batch needs a response, send one useful reply to the latest relevant message: ${command}`,
119
+ readOnly
120
+ ? `If this batch needs a response, send one useful reply to the latest relevant message: ${command}`
121
+ : command,
119
122
  "If you already delivered the useful response through Relay, do not send a separate status-only confirmation.",
120
123
  "If multiple messages arrived together, cover them in one reply instead of answering each line separately.",
121
124
  ].join("\n");
@@ -3,6 +3,7 @@ import type { Message, ReplyObligation } from "agent-relay-sdk";
3
3
  import { errMessage, isRecord } from "agent-relay-sdk";
4
4
  import type { ProviderPermissionDecisionInput, ProviderStatusEvent, SemanticStatus, TerminalAttachSpec } from "./adapter";
5
5
  import { obligationRequiresExplicitReply } from "./reply-obligation-cache";
6
+ import { relayReplyActionText } from "./relay-instructions";
6
7
  import { logger, parseLogLevel, LOG_LEVELS } from "./logger";
7
8
  import { buildRateLimitProviderState } from "./rate-limit";
8
9
 
@@ -197,7 +198,7 @@ function replyObligationSummary(obligations: ReplyObligation[]): Record<string,
197
198
  pending: true,
198
199
  count: obligations.length,
199
200
  obligation,
200
- reason: `Pending Agent Relay response for message #${obligation.messageId} from ${obligation.from}${subject}. If it still needs an answer, run: ${obligation.replyCommand}. If multiple delivered messages are part of one current request, answer once to the latest relevant message. If the useful response was already delivered through Relay, do not send a separate status-only confirmation.`,
201
+ reason: `Pending Agent Relay response for message #${obligation.messageId} from ${obligation.from}${subject}. If it still needs an answer, use ${relayReplyActionText(obligation.messageId)}. If multiple delivered messages are part of one current request, answer once to the latest relevant message. If the useful response was already delivered through Relay, do not send a separate status-only confirmation.`,
201
202
  };
202
203
  }
203
204
 
@@ -3,7 +3,7 @@ export const CLAUDE_RELAY_MANUAL = `# Agent Relay
3
3
  - Agent Relay messages may come from humans, channels, or other agents.
4
4
  - Read the delivered message body and do the requested work.
5
5
  - Reply through Relay only when the sender still needs an answer.
6
- - Prefer \`agent-relay /reply <messageId> --stdin < response.md\` for the actual answer to an incoming Relay message.
6
+ - Prefer the inline MCP tools \`relay_reply\` or \`relay_send_message\` for the actual answer to an incoming Relay message.
7
7
  - Do not send \`/message\` with the useful answer and then a separate \`/reply\` that only says it was sent.
8
8
  - If multiple Relay messages arrive together, answer once to the latest relevant message and cover the current request. Do not separately acknowledge stale greetings or context.
9
9
  - If the useful response was already delivered through Relay, do not send an extra "sent", "done", or "drafts sent" confirmation unless the user explicitly asked for one.
@@ -25,6 +25,14 @@ This Claude session is running with restricted read-only Relay permissions. Do n
25
25
 
26
26
  agent-relay /reply <messageId> "<your reply>"`;
27
27
 
28
+ export function relayReplyActionText(messageId: number): string {
29
+ return `relay_reply (messageId: ${messageId}, body: "<your reply>"). CLI fallback: agent-relay /reply ${messageId} "<your reply>"`;
30
+ }
31
+
32
+ export function relayReplyReminderText(messageId: number): string {
33
+ return `If this batch needs a response, send one useful reply to the latest relevant message with ${relayReplyActionText(messageId)}`;
34
+ }
35
+
28
36
  /**
29
37
  * Provider-agnostic caveat injected into every spawned agent that runs in an
30
38
  * isolated workspace, regardless of which project it is working in. Isolated
@@ -224,6 +224,11 @@ export class AgentRunner {
224
224
  private readonly mcpProxySecret: string;
225
225
  private process?: ManagedProcess;
226
226
  private stopped = false;
227
+ // #633 — set when the provider terminally exits but the runner stays alive (Claude native
228
+ // auto-compaction / manual-resume hold). Rides on the offline status frame so the server fires a
229
+ // terminal `agent.exited` event with a #636 diagnosis instead of the death going silent. Cleared
230
+ // on any genuine restart back to busy/idle.
231
+ private terminalProviderExit?: Record<string, unknown>;
227
232
  private exitCommandInProgress = false;
228
233
  private restartInProgress = false;
229
234
  // Set for the whole unexpected-exit restart, including the pre-restart backoff
@@ -1010,6 +1015,14 @@ export class AgentRunner {
1010
1015
  },
1011
1016
  });
1012
1017
  this.process = undefined;
1018
+ // #633: the runner stays alive (manual-resume hold), so neither the orchestrator tmux-gone
1019
+ // path nor the heartbeat reaper will ever fire. Stamp the terminal marker so the SAME offline
1020
+ // status frame (published by setProviderStatus below) carries it; the server's bus status
1021
+ // handler turns that edge into a terminal `agent.exited` event with a #636 diagnosis.
1022
+ this.terminalProviderExit = {
1023
+ reason: hasResumeId ? "claude-exit-manual-resume-available" : "claude-exit-manual-intervention-required",
1024
+ ...diagnostics,
1025
+ };
1013
1026
  this.setProviderStatus({
1014
1027
  status,
1015
1028
  reason: "provider-turn",
@@ -1241,6 +1254,9 @@ export class AgentRunner {
1241
1254
  // re-inject any pending spawner obligation so it surfaces the /reply command.
1242
1255
  if (this.options.provider !== "claude") void this.reInjectPendingObligation();
1243
1256
  }
1257
+ // A genuine restart back to forward progress clears the terminal-exit marker so a later offline
1258
+ // doesn't re-announce a stale provider exit.
1259
+ if (status === "busy" || status === "idle") this.terminalProviderExit = undefined;
1244
1260
  if (status === "busy") {
1245
1261
  this.claims.clearTerminalStatus();
1246
1262
  this.claims.startWork(reason, id, typeof update === "string" ? {} : {
@@ -1828,6 +1844,14 @@ export class AgentRunner {
1828
1844
  terminalFailureReason: terminalFailure.reason,
1829
1845
  terminalFailureMessage: terminalFailure.message,
1830
1846
  } : {}),
1847
+ // #633 — terminal provider-exit marker (runner alive, provider gone). Drives the server's
1848
+ // silent-death terminal event + #636 post-mortem.
1849
+ ...(this.terminalProviderExit ? {
1850
+ terminalProviderExit: this.terminalProviderExit,
1851
+ ...(typeof this.terminalProviderExit.claudeResumeId === "string"
1852
+ ? { lastError: `Claude provider exited; resume id ${this.terminalProviderExit.claudeResumeId} captured for manual recovery` }
1853
+ : { lastError: "Claude provider exited; manual intervention required" }),
1854
+ } : {}),
1831
1855
  busyReasons: this.claims.reasons(),
1832
1856
  activeWork,
1833
1857
  activeSubagents,