From 55e0f8c8b0bc5999edf2bd4525e41808e9379818 Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Sun, 22 Nov 2026 19:15:35 +0000 Subject: [PATCH] Update the usage reporting roadmap for PromptKit v0.25.0 --- docs/roadmap/automatic-usage-reporting.md | 180 +++++++++++++++++----- 1 file changed, 141 insertions(+), 39 deletions(-) diff --git a/docs/roadmap/automatic-usage-reporting.md b/docs/roadmap/automatic-usage-reporting.md index e88261a..e81ce32 100644 --- a/docs/roadmap/automatic-usage-reporting.md +++ b/docs/roadmap/automatic-usage-reporting.md @@ -1,6 +1,7 @@ # Automatic PromptKit Usage Reporting -Status: adoption goal agreed; design decisions open; implementation not started. +Status: adoption goal agreed; upstream v0.25.0 reviewed and available; CommandKit +design decisions open; implementation not started. ## Goal @@ -26,22 +27,85 @@ implementation plan or a current CLI/API contract. ## Upstream Dependency -The reviewed [PromptKit roadmap](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/03209947f697b11bd633247c5800e9653bee13ef/docs/roadmap/invocation-scoped-token-usage.md) -accepts contextual observation and optional provider-reported USD cost. It is -pending implementation; no adopting release version has been selected. +Target `go.maximumdirect.net/promptkit v0.25.0`, released at commit +`207677e9948dc5699073a4d6620d21139033c72d`. Its annotated tag was verified against +the upstream remote. The [release notes][promptkit-release] and tagged public API +replace the earlier upstream proposal as the adoption baseline. The upstream +availability dependency is resolved; CommandKit's module selection remains +v0.24.0 until implementation. -Its planned `WithExecutionObserver` helper lets ckprompt associate an existing -`ExecutionGroup` with the invocation context. Ordinary runs, nested and concurrent -calls, multiple engines, prepared executions, and coordinated continuations -participate through the upstream execution boundaries. Prepared execution selects -the contextual observer when executed. Existing explicit observers compose with -contextual observation. +### Released observation and accounting API -Adopt the released public capability when available and recheck its final GoDoc -before implementation. PromptKit remains the owner of event generation, -observation scope, aggregation, duplicate accounting, token presence/completeness, -and provider cost interpretation. Do not implement a local accounting substitute -while waiting. Sibling checkouts are review evidence, not build dependencies. +The [observation API][promptkit-observations] provides: + +```go +func WithExecutionObserver(ctx context.Context, observer ExecutionObserver) context.Context +``` + +ckprompt can associate an existing `ExecutionGroup` with the invocation context. +Ordinary runs, nested and concurrent calls, multiple engines, prepared executions, +and coordinated continuations participate through upstream execution boundaries. +Explicit request observers run before contextual observers, which compose in +registration order; a nil contextual observer leaves the context unchanged. +Prepared handles retain explicit request observers but select contextual +observers when executed. No per-engine installation is needed. + +The released [group API][promptkit-groups] supplies `Observe(ExecutionEvent)` and +`Snapshot() ExecutionGroupSummary`. The detached snapshot exposes `Members`, +`TerminalCoverageComplete`, `Attempts`, `TransientRetries`, `RepairCalls`, `Usage`, +and `CostUSD`. It counts each run's first terminal event once. Coverage of members +and completeness of their reported usage/cost are separate facts. Use this +snapshot as the summary source, including after a returned failure; do not add +per-attempt, per-result, or terminal totals together locally. + +`ObservedTokenUsage` includes `ReasoningTokens` in addition to the existing token +categories. Reasoning is a subset of completion tokens, and cache reads/writes +do not add to token totals. Its `CacheHitRatio() (float64, bool)` derives the +ratio from complete, consistent input/cache-read counts; use that native helper +if the selected presentation includes a ratio. + +[Cost metadata][promptkit-cost] uses `ObservedCost` with `Value float64`, `Known`, +`Complete`, and `Source`. It appears as `CostUSD` on execution events, group +summaries, and successful `RunResult` values; injected clients may supply +`GenerateResponse.CostUSD` as `*float64`. Cost sources distinguish provider or +injected-client reports, configured-zero fallback, mixed contributions, and no +sourced contribution. Retain those distinctions rather than labeling every known +amount as a provider charge. Result cost is available without observation; +invocation accounting should still use the group because errors return no partial +result and `RunResult.Usage` has different successful-generation accounting. + +PromptKit owns event generation, observation scope, aggregation, duplicate +accounting, token presence/completeness, and cost interpretation. Reuse its public +contracts without adding local accounting, provider decoding, or pricing logic. +Sibling checkouts are review evidence, not build dependencies. + +### Released configuration and compatibility changes + +The final release expands the original proposal. Its +[backend settings][promptkit-backends] select provider conventions explicitly: +`provider` supports `openai-compatible`, `openrouter`, and `vllm`. Omitted, null, +or blank selects generic OpenAI-compatible behavior. Backend names and endpoint +hostnames do not select provider conventions. The bundled OpenRouter definition +already selects `openrouter`; application-defined OpenRouter backends must select +it explicitly for provider-specific usage, cost, and authentication defaults. + +Optional `zero_cost: true` supplies an upstream zero fallback when no usable +charge is reported. A usable reported amount, including zero, takes precedence. +Do not add a ckprompt default that declares local or otherwise unreported work +free. Present configured-zero evidence with its native source attribution. + +Provider selection also controls native reasoning/cache-field mappings and +authentication defaults. OpenRouter defaults to `openrouter_key`, vLLM to the new +`vllm_models` adapter, and generic backends have no authentication default. +Omitted/null authentication configuration uses the provider default; `kind: none` +declares authentication inapplicable. These diagnostics still run only when +explicitly requested. Forward selections and native findings without implementing +provider policy in CommandKit. + +The Go consumer minimum remains 1.27.0 and upstream dependencies, including +ConfigKit v1.4.0, are unchanged from v0.24.0. Public structs gained fields and native +JSON adds cost and reasoning usage. Review positional literals and strict result +decoders, and document applicable report/configuration changes during adoption. ## Current CommandKit Baseline @@ -58,6 +122,11 @@ while waiting. Sibling checkouts are review evidence, not build dependencies. - Core [reporting](../cli.md#reporting) separates command results from diagnostics and preserves application outcomes when presentation fails. +The existing ckprompt independent suite passed against released PromptKit v0.25.0 +using temporary module files and the other published dependencies. Tracked module +files were unchanged. This is a baseline compatibility check, not verification +of the planned usage integration, which does not yet exist. + ## Adoption Strategy ### Core invocation integration @@ -101,12 +170,12 @@ intercept arbitrary engine calls. This work does not establish concurrent ### Report content and delivery -Expose the upstream token categories and any provider-reported USD cost, keeping -unknown values, reported zero, incomplete subtotals, and terminal coverage -distinct. Select presentation under D3-D6. Describe these facts neutrally using -the adopted upstream meaning; no local pricing inference or billing guarantee is -needed. Do not round cost during adaptation; any text display precision is a -presentation choice. +Expose the upstream token categories and available USD cost, keeping unknown +values, reported or configured zero, cost sources, incomplete subtotals, and +terminal coverage distinct. Select presentation under D3-D6. Describe these facts +neutrally using the adopted upstream meaning; no local pricing inference or +billing guarantee is needed. Do not round cost during adaptation; any text +display precision is a presentation choice. The summary supplements the application result. Preserve its outcome, explanation, and supported error identity. Report output failures through the existing @@ -114,11 +183,26 @@ presentation-failure model, including when the command already failed. Do not append prose to an application's JSON result or write directly to process stderr outside the application's selected streams and core reporting lifecycle. -Smoke diagnostics retain their separate upstream reporting model. Do not add -their reported usage to an execution group or imply that an empty ordinary group -measures smoke-test usage. Their existing command reports remain available; -extending smoke cost presentation can be considered separately if the upstream -release supplies the necessary evidence. +### Existing report adaptation + +Backend inspection already forwards native `BackendInspection`; preserve its new +`Provider` and `ZeroCost` declarations, including explicit false, without +manufacturing runtime defaults in inspection reports. Configuration inspection +continues to expose upstream safe evidence and history. No new provider-selection +CLI flags or loader wrappers are needed for this adoption. + +The explicit [smoke usage projection](../../integrations/ckprompt/smoke_report.go) +currently lists five token fields. Extend it to retain native `ReasoningTokens` +in attempt and aggregate reports rather than silently dropping that added field. +Use D6 to decide cache-ratio presentation consistently across usage reports. + +Smoke diagnostics retain their separate upstream reporting model and are not +enrolled in ordinary context observation. Do not add their reported usage to an +execution group or imply that an empty ordinary group measures smoke-test usage. +v0.25.0's `SmokeTestReport` has no cost field; do not fabricate one from an +execution summary or attempt to infer it from token counts. Existing authentication +diagnostics should continue to expose native support and applicability findings, +including the new vLLM adapter, through the current smoke command. ## Open Decisions @@ -187,22 +271,32 @@ for input/preflight failures when designing the lifecycle hook. ### D6: Initial summary detail Choose the initial report fields and text precision. Recommend aggregate prompt, -completion, total, cached, and cache-write tokens; available USD cost; and clear -availability/completeness indicators. Include cost automatically when upstream -provides it, without a separate accounting opt-in. Decide whether run, attempt, -retry, and repair counts belong in the concise summary. Recommend deferring -per-model breakdowns, event traces, and persistent history; the native group -summary is sufficient for the initial invocation-total task. +completion, reasoning, total, cached, and cache-write tokens; available USD cost +with its source; and clear availability/completeness and terminal-coverage +indicators. Include cost automatically when the native summary provides it, +without a separate accounting opt-in, including explicit configured-zero evidence. + +Recommend exposing the native `Usage.CacheHitRatio()` when available, using +aggregate counts rather than averaging per-run ratios. Decide its text format +and whether it also appears in smoke reports; do not derive it independently. +Reasoning and cache values must be presented as details, not added to total tokens. +Decide whether run, attempt, retry, and repair counts belong in the concise +summary. Recommend deferring per-model breakdowns, event traces, and persistent +history; the native group summary is sufficient for the initial invocation-total +task. These remain CommandKit presentation decisions despite the released upstream +availability of the evidence. ## Delivery Sequence -1. Resolve D1-D6 and review the released upstream API. Select a compatible - PromptKit release without predicting its version or duplicating its roadmap. +1. Resolve D1-D6 against the reviewed PromptKit v0.25.0 API. Upstream implementation + and release are complete; no upstream feature work remains a prerequisite. 2. Implement and verify the neutral core installation, flag, context, and finalization support. Preserve existing reporting and assembly contracts. -3. Adopt the upstream release in ckprompt and attach observation and summary +3. Adopt PromptKit v0.25.0 in ckprompt and attach observation and summary presentation through normal installation. Cover both current assembly paths and application commands registered separately from the standard family. + Carry new native fields through existing reports and review maintained backend + fixtures for intended provider and authentication conventions. 4. Extend the maintained composed consumer to demonstrate the CommandKit-specific benefit: an application-owned command receives the flag and final summary without accounting code in its handler. Use offline injected-client evidence. @@ -227,10 +321,12 @@ so automatic behavior does not depend on a particular declaration layout. Use focused core tests for installation, flag forwarding, context decoration, finalization timing, visibility, invocation isolation, and writer failures. Use integration tests to establish that ckprompt passes the scoped context to the -native API and faithfully presents returned summary values, including cost, -unknown/zero/incomplete evidence, and available data after failure. Exercise a -representative multi-call consumer with the real upstream engine as useful; -PromptKit retains tests for its accounting, retries, repairs, and provider decoder. +native API and faithfully presents returned summary values, including reasoning, +cost sources, unknown/reported-zero/configured-zero/incomplete evidence, and +available data after failure. Verify the new reasoning field survives smoke +projection and explicit provider/zero-cost declarations survive backend inspection. +Exercise a representative multi-call consumer with the real upstream engine as +useful; PromptKit retains tests for its accounting, retries, repairs, and provider decoder. Do not duplicate those upstream domain suites in CommandKit. Validate help/completion without acquisition, existing explicit observer @@ -239,3 +335,9 @@ quiet-mode behavior. Keep checks offline. Run affected core and nested-module suites using the developer guide, including independent builds against released dependencies before release. No live inference, performance benchmark, or new concurrent-dispatch guarantee is needed. + +[promptkit-release]: https://forge.maximumdirect.net/base-layer/promptkit/src/tag/v0.25.0/docs/releases/v0.25.0.md +[promptkit-observations]: https://forge.maximumdirect.net/base-layer/promptkit/src/tag/v0.25.0/observations.go +[promptkit-groups]: https://forge.maximumdirect.net/base-layer/promptkit/src/tag/v0.25.0/execution_group.go +[promptkit-cost]: https://forge.maximumdirect.net/base-layer/promptkit/src/tag/v0.25.0/cost.go +[promptkit-backends]: https://forge.maximumdirect.net/base-layer/promptkit/src/tag/v0.25.0/docs/formats.md#backend-definitions