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.0.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.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for imbue_mngr_opencode_usage-0.1.0.tar.gz
Algorithm Hash digest
SHA256 af4910e834887b3f3a821673f86de0203757f0e344427da89bf1d3b242583b0a
MD5 d3eca8866674b690c2b411e4cf365f07
BLAKE2b-256 541bc980145f755d4603813d1de9b4bd4150456e99a901e07e7647f15ad80d6c

See more details on using hashes here.

Provenance

The following attestation bundles were made for imbue_mngr_opencode_usage-0.1.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for imbue_mngr_opencode_usage-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 26663cf7f41b48115e37a12ceeb40c04d7bb8795cea05cec1567cb7e98d2182d
MD5 4194fe38d64eb1f0b1a7819213729e62
BLAKE2b-256 179f8ca7c831336f296455456fef82314edbac8c49ffb6e9d1e708a2cd4cd5c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for imbue_mngr_opencode_usage-0.1.0-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