Files
hapi/cli/src/commands/help.ts
T
weishuandClaude Opus 5.5 23122ccbc0 feat(hub): persist agent turns and report them through hapi usage
Whether a session's agent is thinking lived only in the session cache,
so once a turn ended nothing could say how long the agent had worked,
and a hub restart forgot even the turn in progress. Tools that track
time (Weft, for one) had no way to see when agents on other machines
were busy.

Schema v28 adds session_turns: a row opens when a session starts
thinking (a prompt queued through the hub, the agent reporting it,
or a patch) and closes when it stops, the session ends, or its
keepalives expire, at the last keepalive. Rows are only written on
those transitions, never per keepalive. Turns move with a session
when it is merged away.

At startup the hub closes turns left open by the previous process at
the session's newest message. If the agent carries on thinking within
10 minutes of the restart, the same turn continues, so the work between
that message and the restart isn't lost. The deadline counts from the
restart, and a keepalive or patch reporting idle, the session ending,
or a new prompt ends the chance: those start a new turn.

GET /api/activity returns, for the caller's namespace, each session's
turns in a window (default 24 h, at most 31 days) with what identifies
it (flavor, agent session id, machine, path, title) and the permission
prompts and questions it waited on, taken from agent_state.

`hapi usage [--since] [--until] [--json]` prints a summary or a
hapi.activity.v1 report for other tools, with distinct exit codes for
bad arguments (2), missing or refused credentials (3) and a hub too
old to answer (4). The summary counts only the part of each turn
inside the window and subtracts overlapping waits once. It reuses the
peer commands' token exchange.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 08:48:06 +08:00

44 lines
1.7 KiB
TypeScript

import { CREATABLE_AGENT_FLAVORS, getFlavorLabel } from '@hapi/protocol'
export function printCliHelp(): void {
const agents = [...CREATABLE_AGENT_FLAVORS].sort().map((agent) => (
` ${`hapi ${agent}`.padEnd(26)} ${getFlavorLabel(agent)}`
)).join('\n')
console.log(`HAPI - Coding agents with remote control
Usage:
hapi Choose an agent interactively
hapi <agent> [options] Start an agent session
hapi <command> [options] Run a HAPI command
Agents:
${agents}
Commands:
hapi auth Manage authentication
hapi resume [id] Choose or resume an existing HAPI session
hapi hub [--relay] Start the API + web hub
hapi server Alias for hapi hub
hapi runner Manage the background runner
hapi doctor Run diagnostics and troubleshooting
hapi ping-peer List peers or message another session
hapi inspect-peer <id> Read another session's metadata and messages
hapi set-mode <id> <mode> Change a session's permission mode
hapi usage [--json] When agents were working, across machines
hapi mcp Start the MCP stdio bridge
Options:
-h, --help Show HAPI help
-v, --version Show HAPI version
Examples:
hapi Choose an installed agent
hapi claude --resume Resume a Claude session
hapi codex --yolo Start Codex with automatic approvals
hapi auth login Configure authentication
Agent options belong after the agent name; supported options vary by agent.
Scripts and non-interactive shells must specify an agent explicitly.`)
}