CodexWrapper.Commands.Archive (CodexWrapper v0.4.0)

Copy Markdown View Source

Session lifecycle commands -- archive, unarchive, and delete a saved session.

Wraps codex archive <session>, codex unarchive <session>, and codex delete <session>. Each takes a session id (UUID) or a session name; the CLI prefers the UUID interpretation when the argument parses as one.

Usage

config = CodexWrapper.Config.new()

{:ok, _} = CodexWrapper.Commands.Archive.archive(config, "abc-123")
{:ok, _} = CodexWrapper.Commands.Archive.unarchive(config, "abc-123")

Deleting

codex delete permanently destroys the saved session; there is no undo, and unarchive/2 cannot bring it back. So delete/3 will not run unless the caller passes confirm: true:

CodexWrapper.Commands.Archive.delete(config, "abc-123")
#=> {:error, :confirmation_required}

CodexWrapper.Commands.Archive.delete(config, "abc-123", confirm: true)
#=> {:ok, ""}

Without the flag the CLI is never invoked, so a delete reached by mistake -- a wrong branch, a stale variable -- costs nothing. Archiving is the reversible option and should be the default reach.

Summary

Functions

Archive a saved session. Reversible with unarchive/2.

Build the argument list for an action and session.

Permanently delete a saved session.

Build a lifecycle command for the given action and session.

Unarchive a previously archived session.

Types

action()

@type action() :: :archive | :unarchive | :delete

t()

@type t() :: %CodexWrapper.Commands.Archive{action: action(), session: String.t()}

Functions

archive(config, session)

@spec archive(CodexWrapper.Config.t(), String.t()) ::
  {:ok, String.t()} | {:error, term()}

Archive a saved session. Reversible with unarchive/2.

build_args(action, session)

@spec build_args(action(), String.t()) :: [String.t()]

Build the argument list for an action and session.

delete(config, session, opts \\ [])

@spec delete(CodexWrapper.Config.t(), String.t(), keyword()) ::
  {:ok, String.t()} | {:error, :confirmation_required | term()}

Permanently delete a saved session.

Requires confirm: true. Without it this returns {:error, :confirmation_required} and the CLI is not invoked. See the module docs for why.

Options

  • :confirm - must be true for the delete to run

new(action, session)

@spec new(action(), String.t()) :: t()

Build a lifecycle command for the given action and session.

The session is an id (UUID) or a session name.

unarchive(config, session)

@spec unarchive(CodexWrapper.Config.t(), String.t()) ::
  {:ok, String.t()} | {:error, term()}

Unarchive a previously archived session.