Extensible pap CLI
The Python distribution installs an initial pap command line for non-secret
configuration, company discovery, agent-identity inspection, and extension
negotiation diagnostics.
The executable is a small Typer host: its PAP command groups come from a
Datalayer Reactor
extension rather than being hard-coded into the host.
python -m pip install personal-agent-protocol
pap --help
The command groups are:
| Command | Purpose |
|---|---|
pap config | Show, get, set, unset, and list non-secret profiles and value provenance. |
pap company | Discover and verify a company's PAP document. |
pap agent | Verify personal-agent metadata and public JWKS; import the agent's signing key. |
pap extensions | List advertised PAP extensions and check one required major version. |
pap sessions | start, show, and end Sessions; renew a Session's access token with its refresh token (ยง5). |
pap auth | direct, device, and mediated sign-in, and disconnect (sign out, ยง4, ยง5.5). |
pap api | openapi calls, and mcp tools with a token for the MCP url only (ยง7). |
pap conversations | start, send, events, follow (SSE), handoff, direct, close (ยง8). |
pap operations | show, approve, send (Operations version 3). |
pap requirements | list and show the normative requirement ledger. |
pap conformance | run the conformance suite (--demo, --tls) and report JSON or JUnit. |
pap commands | list and run the live-session actions by ID, as Studio and a REPL do. |
pap exit-codes | List every exit code. |
Every protocol command is a thin adapter over the public SDK and prints either
friendly text or versioned JSON (--json, schema_version: 1).
Protected input and local stateโ
A token, code, password, private key, or callback URL is never a command-line
option. It is typed at a hidden prompt, or read one value per line from stdin
(--stdin) or a file descriptor (--input-fd N). With --no-input, a
command that needs input stops with exit code 4 instead of asking.
pap config set client_id https://agent.example/agent.json
pap agent key import --stdin < agent-signing-key.pem # printed: key:key-1 and its thumbprint
pap sessions start example.com --json # a new random `sid` names the Session
pap auth device "$SESSION" --scope orders:read # the user signs in on any device
pap auth mediated "$SESSION" --stdin < credentials.txt # one field per line, then the code
pap api openapi "$SESSION" GET /orders
pap api mcp "$SESSION" search_products --arguments '{"q": "jacket"}'
The CLI's personal agent is a Reactor host. Its defaults live under
$XDG_STATE_HOME/pap (or ~/.local/state/pap), owner-only and written
atomically: the token store (secrets.json, pap.tokenStore), the signing
key and one delegated key per user and company (keys.json), pairwise User IDs
(pairwise.sqlite3), and the non-secret Session records and approvals
(state.json). Commands name a Session by its handle, ses_ and its first sid
($SESSION), which pap sessions start prints. Plugins installed
under the personal_agent_protocol.plugins entry-point group are discovered
after these defaults and can replace any of them, for example with a system
keyring. Only opaque references (session:โฆ, refresh_โฆ, key:โฆ) are
printed.
Operations: approve, then sendโ
pap operations show "$SESSION" exc_5Rt2 # as the company returned it
pap operations approve "$SESSION" exc_5Rt2 --revision "$REVISION" # shows the company and summary;
# the user types the operation ID
pap operations send "$SESSION" exc_5Rt2 --revision "$REVISION"
pap api and pap conversations keep each operation the company returns, with
the request that returned it. Approval is taken at the host's approval surface or
the CLI's own prompt, for one exact operation ID and revision; no message, option,
or piped text counts as approval. send makes that same request again with the
approval, and only for a revision the user approved. New terms stop it with exit
code 6, to approve them. Exit code 5 means the outcome isn't known yet: run send
again, the same approval, performed at most once.
Exit codesโ
| Code | Meaning |
|---|---|
| 0 | Done. |
| 1 | The company refused, or the protocol failed (its error code is printed). |
| 2 | Usage error: an unknown command, option, or value. |
| 3 | Not configured: no signing key, no client_id or domain, or an unknown Session. |
| 4 | Input required, but --no-input was given or no terminal is attached. |
| 5 | Still pending: the user has not finished signing in before --timeout. |
| 6 | Not approved: no approval for this exact operation ID and revision, or new terms; or a live-session action the host's approval surface did not approve. |
| 130 | Interrupted. |
Conformanceโ
pap conformance run --demo --tls --format junit --output pap.xml
pap conformance run --demo --suite operations --format json --output report.json
pap conformance run --demo --world dpop-binding
pap conformance run --demo --world no-issuer
pap conformance report report.json --format junit
pap requirements show OPS-6-02
--demo runs the personal-agent suite against the in-process Manzanita
reference company. Against your own company, use
personal_agent_protocol.conformance with a UserDriver and Scenario for
it.
Configure a profileโ
pap config set domain example.com --profile work
pap config set timeout 5 --profile work
pap config show --profile work
pap config show --profile work --json
pap company verify --profile work --json
The accepted keys are domain, client_id, issuer, output,
store_provider, tenant, and timeout. Configuration is stored at
$XDG_CONFIG_HOME/pap/config.json, or ~/.config/pap/config.json when
XDG_CONFIG_HOME is unset. Writes are atomic and the file is created with
mode 0600.
Set PAP_PROFILE to select a default profile. Each supported key also has an
environment override, such as PAP_DOMAIN, PAP_CLIENT_ID, and PAP_TIMEOUT.
Environment values take precedence over profile values. pap config show
prints each effective value's source; its JSON representation is versioned
with schema_version: 1.
tenant (or PAP_TENANT; pap-cli by default) keeps applications apart in
one state directory: pairwise User IDs and delegated keys are per tenant, and
every command sees only its tenant's Sessions. pap sessions show lists them, and
another tenant's Session is answered like an unknown one (exit code 3), for
every command. A tenant is 1 to 64 letters, digits, ., _ or -.
The configuration store deliberately rejects unknown keys. Do not put access or refresh tokens, passwords, authorization codes, private keys, assertions, Session JWTs, or mediated secrets in this file or in command arguments. Commands that need secrets resolve Reactor contributions and expose only opaque references.
Inspect a companyโ
pap company discover example.com
pap company verify example.com --json
pap extensions list example.com --json
pap extensions check operations --version 3 example.com
Both company commands use the SDK's safe discovery client. verify therefore
checks the requested organization domain, OAuth issuer relationship, redirect
policy, response bound, and public-address preflight; it is not only a JSON
syntax check. JSON output contains no terminal decoration and currently uses
schema version 1.
Inspect a personal agentโ
pap agent metadata https://agent.example/agent.json
pap agent jwks https://agent.example/agent.json --json
# Or use a non-secret profile default.
pap config set client_id https://agent.example/agent.json --profile work
pap agent metadata --profile work --json
metadata does not follow redirects and requires the document's client_id
to equal the exact URL fetched. It validates HTTPS and same-domain JWKS and
redirect URIs. jwks first repeats that metadata verification, then retrieves
the key set through the same Reactor transport and URL-safety policy. JWKS
redirects are bounded and cannot leave the client ID host. Only public P-256
ES256 and RSA PS384 signing keys are accepted; private members and symmetric
keys are rejected. Both responses are public, schema-versioned inspection
output and never include assertions or private key material.
Why this is a Reactor extensionโ
personal_agent_protocol.cli only creates the host and calls
reactor.cli.extend(app). The distribution advertises its plugin using the
standard entry-point group:
[project.entry-points."datalayer.reactor.cli"]
pap = "personal_agent_protocol.cli_plugin:plugin"
PapCliPlugin.provide_cli contributes the config, company, agent,
extensions, and protocol Typer applications. A broken third-party CLI extension is warned
about and skipped by Reactor. Installed companion distributions can add their
own groups without importing PAP CLI internals or changing the pap host:
[project.entry-points."datalayer.reactor.cli"]
acme_pap = "acme_pap.cli:plugin"
import typer
from reactor import PluginManifest
class AcmePapCli:
def provide_cli(self, cli: typer.Typer) -> None:
acme = typer.Typer(name="acme", help="Acme PAP tools.")
@acme.command("inspect")
def inspect() -> None:
typer.echo("Acme inspection")
cli.add_typer(acme)
def plugin() -> tuple[PluginManifest, AcmePapCli]:
manifest = PluginManifest(name="acme.pap.cli", version="1.0.0")
return manifest, AcmePapCli()
Use provide_cli for command groups resolved when a command-line process
starts. Use provide_slash_commands for actions that run inside a live Studio
or REPL session: the PAP plugin registers its live-session
actions there. Reactor owns their enable, disable,
collision, and unregister lifecycle, so a command disappears when its plugin
does.
Keep extension command IDs globally namespaced, and call public SDK services
from command handlers. Do not couple an extension to
personal_agent_protocol.cli_plugin implementation details.
Live-session actionsโ
The PAP plugin registers a set of actions, by namespaced ID, in whichever
registry a host passes to provide_slash_commands: Reactor's command registry
(Studio's palette, and pap commands run), or a REPL's
SlashCommandRegistry. Every surface calls one implementation โ the same
coroutine as the pap command of the same name โ and gets the same versioned
JSON as that command's --json.
| Action | pap command | Arguments | Runs |
|---|---|---|---|
pap.company.discover | company discover | domain | at once |
pap.sessions.show | sessions show | [session] | at once |
pap.conversations.events | conversations events | session conversation_id [cursor] | at once |
pap.conversations.follow | conversations follow | session conversation_id [last_event_id] [max_events] | at once (at most 500 events) |
pap.operations.show | operations show | session operation_id | at once |
pap.requirements.list | requirements list | [role] [level] [status] [source] | at once |
pap.requirements.show | requirements show | requirement_id | at once |
pap.sessions.end | sessions end | session | after the host's approval surface says yes |
pap.auth.disconnect | auth disconnect | session | after the host's approval surface says yes |
pap commands list
pap commands run pap.sessions.show
pap commands run pap.operations.show "$SESSION" exc_5Rt2 # by position
pap commands run pap.requirements.list level='MUST NOT' role=company
pap commands run pap.sessions.end "$SESSION" # exit code 6: approval_required
session is a Session's handle, the ses_โฆ value pap sessions show lists. Arguments
are text: by position, as name=value, as a JSON object (a REPL
line or Studio), or as a mapping (Studio). An unknown name, a missing required
argument, or an unknown action is a usage error (exit code 2). An action runs
in the CLI's personal agent for the configured tenant, sees only that tenant's
Sessions, and never asks for input.
What is not an action stays CLI-only: configuration (pap config), raw
credential entry (pap agent key import, pap auth direct|device|mediated),
starting Sessions, renewing their access tokens, sending messages, calling APIs, and approving
or sending operations, which keep their own exact-ID-and-revision prompt.
The approval surfaceโ
The two actions that end what the user holds run only where the
host contributes an approval surface to the personal agent's Reactor
(pap.approvalSurface, for Python hosts). It receives an ApprovalRequest โ
the action's ID and name, a plain-words summary, its arguments (IDs, never a
credential), and the tenant โ before anything is done, and only True
approves:
| Refusal | When | Exit code |
|---|---|---|
approval_required | No approval surface is contributed: use the pap command itself. | 6 |
not_approved | The surface answered anything but True. | 6 |
approval_failed | The surface raised; its error is not repeated. | 6 |
approval_surface_ambiguous | Two surfaces at the winning order. | 6 |
A surface must ask the user on the host's own trusted UI: never a model, never a message in a conversation. Studio, for example, contributes its confirmation dialog and runs actions from its palette:
import asyncio
from reactor import PluginManifest, PluginPlatform
from reactor.slash import SlashCommandRegistry
from personal_agent_protocol import APPROVAL_SURFACES, ApprovalRequest
from personal_agent_protocol.cli_host import local_host
from personal_agent_protocol.cli_plugin import MANIFEST, PapCliPlugin
class StudioApproval:
"""Studio's own confirmation dialog: the user, not a model, answers."""
async def approve(self, request: ApprovalRequest) -> bool:
return await studio.confirm(title=request.action_name, text=request.summary)
def provide_contributions(self, contributions) -> None:
contributions.contribute(APPROVAL_SURFACES, self, contribution_id="studio", order=50)
host = local_host(plugins=[(PluginManifest(name="studio-approval", version="1"), StudioApproval())])
pap = PapCliPlugin(host=host)
platform = PluginPlatform()
platform.register_plugin(MANIFEST, pap) # the palette: Reactor's command registry
repl = SlashCommandRegistry()
pap.provide_slash_commands(repl) # a REPL: /pap.sessions.show, /pap.sessions.end โฆ
async def main() -> None:
shown = await platform.execute_command("pap.sessions.show")
print(shown["sessions"])
asyncio.run(main())