Skip to main content

OpenCode usage data provider for `mngr usage` (per-agent in-process plugin that captures per-message cost + tokens)

Project description

imbue-mngr-opencode-usage

OpenCode data provider for mngr usage. Single responsibility: install a second in-process TypeScript plugin into each OpenCode agent so each assistant message appends one event to $MNGR_AGENT_STATE_DIR/events/opencode/usage/events.jsonl. The mngr usage CLI walks those events files itself (see imbue-mngr-usage).

How the pieces fit

mngr_opencode_usage's on_after_provisioning hookimpl
  └─→ installs <config_dir>/plugin/mngr_opencode_usage_plugin.ts
        (alongside mngr_opencode's lifecycle plugin; OpenCode auto-loads plugin/*.ts)

OpenCode serve process, on each assistant message.updated
  └─→ mngr_opencode_usage_plugin.ts
        └─→ events/opencode/usage/events.jsonl (append one cost_snapshot event)

mngr usage
  └─→ aggregate_usage_source hookimpl (claims the "opencode" source)
        └─→ aggregate_session_incremental: sum each session's messages

All file I/O goes through host.write_text_file, so provisioning works for local and remote agents.

What gets captured

OpenCode computes cost and tokens per message and exposes them on each assistant message.updated event. The writer emits, per message, a self-contained event carrying:

  • cost.total_cost_usd -- OpenCode's own per-message cost (provenance is REPORTED; no estimation needed).
  • tokens -- {input, output, cache_read, cache_creation} (reasoning folded into output), for auditability.
  • model -- the provider-qualified <providerID>/<modelID>.
  • session_id + message_id -- the reader sums per session, keeping the freshest event per message_id so a streaming message's re-fires collapse to its final reading.

Why session-incremental

OpenCode reports each message's own cost, not a session running total. So the writer is stateless -- it appends one self-contained event per message and keeps nothing in memory. The reader (aggregate_session_incremental) recomputes each session's total from the append-only log, which makes it robust across mngr stop/start (a fresh serve process with empty memory loses no history).

cost_mode is API_KEY: OpenCode bills against a real provider key, so the cost is real spend, never an imputed subscription value.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

imbue_mngr_opencode_usage-0.1.1.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

imbue_mngr_opencode_usage-0.1.1-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file imbue_mngr_opencode_usage-0.1.1.tar.gz.

File metadata

File hashes

Hashes for imbue_mngr_opencode_usage-0.1.1.tar.gz
Algorithm Hash digest
SHA256 67cdbaca301001f7b76854be9489e48e3d7743836ddf88c1dc963e2467e8dbc6
MD5 bf2f178c57c973caee85610096d1f05c
BLAKE2b-256 3790b51032ea030b70599330ae98643d8e47812c0405f1a617cb2876d4302373

See more details on using hashes here.

Provenance

The following attestation bundles were made for imbue_mngr_opencode_usage-0.1.1.tar.gz:

Publisher: publish.yml on imbue-ai/mngr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file imbue_mngr_opencode_usage-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for imbue_mngr_opencode_usage-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7c110d614539546cf0c5499308bf7a7c2ff9848fc624a0415be01e3c75cc2769
MD5 199ae022cbde80635a12c2da0e24e520
BLAKE2b-256 56005ba60b32f5162ec0eab3c7c2f4fa80a05c6b26ca44f9b09fa04228631b86

See more details on using hashes here.

Provenance

The following attestation bundles were made for imbue_mngr_opencode_usage-0.1.1-py3-none-any.whl:

Publisher: publish.yml on imbue-ai/mngr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page