Current Agent Resolution And Safe Agent-Scoped CLI Behavior

Summary

AgentInbox should make the common case safe by default:

The CLI should not treat this as a hard permission boundary. It is an operator footgun reduction policy.

Problem

Today a shared AGENTINBOX_HOME can contain multiple agents from different terminal sessions.

This makes the current flow fragile:

  1. user runs agentinbox agent list
  2. user copies an agentId
  3. user performs inbox/subscription operations with that agentId

This is easy to mis-target when:

In practice, this can route inbox actions and notifications to the wrong terminal target.

Goals

Non-Goals

Terms

Session-Bound Agent

An agent with a terminal/runtime identity tied to the current interactive session, such as:

These agents can be resolved from local execution context.

Detached Agent

An agent without a current terminal-bound session context, such as:

These agents should be operated explicitly by --agent.

Current Agent

The agent that matches the current execution context.

Preferred matching order:

  1. terminal identity
    • tmux pane id
    • iTerm session id
    • tty
  2. runtime identity
    • runtimeKind + runtimeSessionId

Proposed CLI Behavior

1. Add agent current

Add:

agentinbox agent current

Behavior:

Suggested JSON response:

{
  "agentId": "agt_copper-fox",
  "bindingKind": "session_bound",
  "matchesCurrentTerminal": true,
  "matchesCurrentRuntime": true,
  "terminalIdentity": "iterm2:4B4CB6B2-A73B-4420-94A7-BD2CA216A285"
}

2. Default To Current Agent For Session Workflows

For agent-scoped commands used from an interactive terminal session, the CLI should resolve the current agent when --agent is omitted.

Examples:

agentinbox inbox read
agentinbox inbox ack --through <itemId>
agentinbox inbox watch
agentinbox subscription add <sourceId> --filter-json ...

Meaning:

Explicit Agent Override

Still support:

agentinbox inbox read --agent <agentId>
agentinbox subscription add --agent <agentId> <sourceId>

This is the primary path for detached agents.

3. Auto-Register For Current-Session Paths

If:

then the CLI should auto-register the current session before executing the command.

This should apply to commands such as:

This should not apply to:

Suggested JSON response extension:

{
  "agentId": "agt_copper-fox",
  "autoRegistered": true
}

4. Cross-Session Operations Should Warn, Not Fail

When the caller explicitly passes --agent, and:

the CLI should still execute the command, but return a structured warning.

This is not a hard permission boundary. It is a risk signal.

Why warning, not error

5. Warnings Must Be JSON-Structured

CLI output is JSON-first, so warnings should be returned in-band instead of only being printed to stderr.

Suggested shape:

{
  "subscriptionId": "sub_xxx",
  "warnings": [
    {
      "code": "cross_session_agent",
      "message": "Requested agent does not match the current terminal session.",
      "currentAgentId": "agent_a",
      "requestedAgentId": "agent_b"
    }
  ]
}

Rules:

6. Detached Agents Should Not Be Penalized

Cross-session warnings should only fire when the requested agent is another session-bound agent.

Detached agents should remain operable through explicit --agent without being treated as suspicious by default.

That means current-session safety logic must distinguish:

The CLI should not assume everything must map to a current terminal.

Suggested Command Policy

Current-session default

Explicit detached management

Discovery

agent list should ideally expose:

Acceptance Criteria

Notes

This RFC intentionally does not define a hard authorization or ownership model. It defines safer defaults and structured warnings for a local multi-session operator experience.