Transport-agnostic daemon API for H sessions, conversations, transcripts,
SSE subscriptions, and idempotent commands.
Every function accepts opts \ [] so isolated --no-start tests and the
full H.HTTP daemon share the exact same contract. Read
Local HTTP and SSE API on hiness.dev for
wire formats, idempotent request_id retries, and SSE cursor rules.
Summary
Functions
Archives (and unloads from RAM) or unarchives a session.
Browses directories in an execution environment (GET /api/v1/fs), enriching
each child directory with H.Catalog session counts/recency and listing
sessions rooted directly at path.
Idempotently creates (or attaches to) a session, persists it in H.Catalog,
and starts its supervised H.Session.Server.
Validates and dispatches a command envelope to H.Session.Server.
Forks a session's visible conversation history into a brand-new session bound
to an existing target cwd (allowing recovery/continuation when the original
cwd was deleted or moved).
Returns session detail, conversation ancestry forest, and live tasks.
Returns a bounded, read-only session-wide entry tree across all conversations and branches without waking unloaded archived sessions.
Looks up the durable outcome/status of a submission by request_id.
Returns the running instance's validated daemon options, or nil when not booted.
Lists configured execution environments ("host" plus any custom/remote environments).
Environment-scoped bounded recursive file discovery (GET /api/v1/fs/files).
Lists models from the configured H.Provider.
Session-scoped bounded recursive file discovery (GET /api/v1/sessions/:sid/files).
Lists sessions directly from H.Catalog ETS without waking unloaded sessions.
Lists sessions filtered by env_id, cwd, optional subtree, archived, and include_subsessions.
Opens a dedicated review session, reusing the last one for this workspace while empty.
Environment-scoped bounded read-only UTF-8 file reader (GET /api/v1/fs/file).
Reads a bounded review file from the worktree, HEAD, or a pinned commit.
Session-scoped bounded read-only UTF-8 file reader (GET /api/v1/sessions/:sid/file).
Boot recovery pass: starts supervised session runtimes for every unquarantined
session that was active: true in H.Catalog when the previous VM stopped,
reconciling unfinished work without waiting for a client reconnect.
Browses workspace directories, Git history, or a commit in the session's execution environment.
Saves an existing text file if its revision still matches, under the workspace lease.
Scans cursor-paged raw transcript entries for a conversation.
Stops all active runs across all conversations in a session.
Subscribes subscriber_pid (must equal self()) to H.PubSub for
{:conversation, session_id, cid} and atomically returns either a snapshot
JSON binary or missed replay frames from the 64-entry commit ring.
Subscribes subscriber_pid (must equal self()) to H.PubSub for :catalog
events and returns an atomic {:snapshot, seq, snapshot_json_bin} directly
from H.Catalog without waking any unloaded sessions.
Updates a session's needs_attention flag or tags without waking it.
Unregisters self() from H.PubSub topic {:submission, session_id, request_id}.
Race-free submission settlement watcher.
Formats a submission outcome map into its JSON wire representation.
Functions
@spec archive_session(String.t(), map(), keyword()) :: {:ok, %{session: map()}} | {:error, :not_found | {:bad_request, String.t()} | {:conflict, String.t()} | {:quarantined, String.t()} | term()}
Archives (and unloads from RAM) or unarchives a session.
@spec browse_workspace(map(), keyword()) :: {:ok, map()} | {:error, :not_found | :unknown_environment | :workspace_unavailable | {:bad_request, String.t()}}
Browses directories in an execution environment (GET /api/v1/fs), enriching
each child directory with H.Catalog session counts/recency and listing
sessions rooted directly at path.
@spec create_session(map(), keyword()) :: {:ok, %{session: map(), seq: non_neg_integer()}} | {:error, {:bad_request, String.t()} | {:conflict, String.t()} | term()}
Idempotently creates (or attaches to) a session, persists it in H.Catalog,
and starts its supervised H.Session.Server.
When session_id is omitted or empty, a unique <folder-slug>-<hex> ID is
minted automatically.
@spec execute_command(String.t(), map(), keyword()) :: {:ok, map()} | {:error, :not_found | {:bad_request, String.t()} | {:conflict, String.t()} | term()}
Validates and dispatches a command envelope to H.Session.Server.
@spec fork_session(String.t(), map(), keyword()) :: {:ok, %{session: map(), seq: non_neg_integer()}} | {:error, :not_found | {:bad_request, String.t()} | {:conflict, String.t()} | {:quarantined, String.t()} | term()}
Forks a session's visible conversation history into a brand-new session bound
to an existing target cwd (allowing recovery/continuation when the original
cwd was deleted or moved).
@spec get_session_detail(String.t(), keyword()) :: {:ok, %{session: map(), conversations: [map()], tasks: [map()]}} | {:error, :not_found | {:quarantined, String.t()} | term()}
Returns session detail, conversation ancestry forest, and live tasks.
@spec get_session_tree(String.t(), keyword()) :: {:ok, %{ session: map(), conversations: [map()], nodes: [map()], truncated: boolean() }} | {:error, :not_found | {:quarantined, String.t()} | term()}
Returns a bounded, read-only session-wide entry tree across all conversations and branches without waking unloaded archived sessions.
@spec get_submission(String.t(), String.t(), keyword()) :: {:ok, map()} | {:error, :not_found | {:bad_request, String.t()} | term()}
Looks up the durable outcome/status of a submission by request_id.
@spec instance_options() :: keyword() | nil
Returns the running instance's validated daemon options, or nil when not booted.
Lists configured execution environments ("host" plus any custom/remote environments).
@spec list_files(map(), keyword()) :: {:ok, map()} | {:error, :not_found | :unknown_environment | :workspace_unavailable | {:forbidden, String.t()} | {:bad_request, String.t()}}
Environment-scoped bounded recursive file discovery (GET /api/v1/fs/files).
Requires explicit env_id and absolute cwd and never falls back to the
daemon's local process cwd.
Lists models from the configured H.Provider.
Session-scoped bounded recursive file discovery (GET /api/v1/sessions/:sid/files).
Resolves {env_id, cwd} strictly from the session's H.Catalog record.
Lists sessions directly from H.Catalog ETS without waking unloaded sessions.
Lists sessions filtered by env_id, cwd, optional subtree, archived, and include_subsessions.
Opens a dedicated review session, reusing the last one for this workspace while empty.
@spec read_file(map(), keyword()) :: {:ok, map()} | {:error, :not_found | :unknown_environment | :workspace_unavailable | {:forbidden, String.t()} | {:bad_request, String.t()}}
Environment-scoped bounded read-only UTF-8 file reader (GET /api/v1/fs/file).
Requires explicit env_id, absolute cwd, and path. Enforces workspace
boundary containment (lexical + canonical symlink checks) and no_follow: true.
Reads a bounded review file from the worktree, HEAD, or a pinned commit.
Session-scoped bounded read-only UTF-8 file reader (GET /api/v1/sessions/:sid/file).
Resolves {env_id, cwd} strictly from the session's H.Catalog record.
@spec recover_active_sessions(keyword()) :: :ok
Boot recovery pass: starts supervised session runtimes for every unquarantined
session that was active: true in H.Catalog when the previous VM stopped,
reconciling unfinished work without waiting for a client reconnect.
Browses workspace directories, Git history, or a commit in the session's execution environment.
Saves an existing text file if its revision still matches, under the workspace lease.
@spec scan_entries(String.t(), term(), map(), keyword()) :: {:ok, %{items: [map()], next_cursor: nil | String.t()}} | {:error, :not_found | {:bad_request, String.t()} | term()}
Scans cursor-paged raw transcript entries for a conversation.
@spec stop_session(String.t(), map(), keyword()) :: {:ok, %{session: map()}} | {:error, :not_found | {:bad_request, String.t()} | {:quarantined, String.t()} | term()}
Stops all active runs across all conversations in a session.
@spec subscribe_conversation(String.t(), term(), pid(), term(), keyword()) :: {:ok, {:snapshot, non_neg_integer(), binary()} | {:replay, [{non_neg_integer(), binary()}]}} | {:error, :not_found | {:bad_request, String.t()} | term()}
Subscribes subscriber_pid (must equal self()) to H.PubSub for
{:conversation, session_id, cid} and atomically returns either a snapshot
JSON binary or missed replay frames from the 64-entry commit ring.
@spec subscribe_sessions(pid(), keyword()) :: {:ok, {:snapshot, non_neg_integer(), binary()}} | {:error, term()}
Subscribes subscriber_pid (must equal self()) to H.PubSub for :catalog
events and returns an atomic {:snapshot, seq, snapshot_json_bin} directly
from H.Catalog without waking any unloaded sessions.
@spec triage_session(String.t(), map(), keyword()) :: {:ok, %{session: map()}} | {:error, :not_found | {:bad_request, String.t()} | term()}
Updates a session's needs_attention flag or tags without waking it.
Unregisters self() from H.PubSub topic {:submission, session_id, request_id}.
@spec watch_submission(String.t(), String.t(), pid(), keyword()) :: {:ok, {:settled, map()} | {:pending, map()}} | {:error, :not_found | {:bad_request, String.t()} | term()}
Race-free submission settlement watcher.
Registers subscriber_pid (when subscriber_pid == self()) on H.PubSub topic
{:submission, session_id, request_id} before querying H.Session.Server.
- Returns
{:ok, {:settled, outcome}}immediately (and unregisters any new registration) if the submission is already terminal ("done","unanswered","withdrawn"). - Returns
{:ok, {:pending, outcome}}while keeping the registration active sosubscriber_piddeterministically receives{:submission_settled, outcome}after the durable commit succeeds.
Formats a submission outcome map into its JSON wire representation.