Plan automatic PromptKit usage reporting

This commit is contained in:
2026-11-22 09:55:13 +00:00
parent 1138960e96
commit a4aa76de33
2 changed files with 248 additions and 1 deletions

View File

@@ -0,0 +1,241 @@
# Automatic PromptKit Usage Reporting
Status: adoption goal agreed; design decisions open; implementation not started.
## Goal
Normal ckprompt installation should make an optional usage-reporting flag
available to application-owned commands as well as the PromptKit command family.
When an operator selects the flag, CommandKit should collect and present usage
for PromptKit executions in that invocation automatically.
Applications must not need to declare the flag on each command, attach observers
to individual requests, create accounting groups, wrap execution methods, take
snapshots, or add final reporting callbacks. Importing ckprompt alone continues
to install nothing; the integration participates through ordinary application
assembly. Merely exposing a report adapter would not meet this goal.
Audita review commands and Notarius pipelines motivate the feature. Their domain
execution remains application-owned. Applications continue to pass
`Invocation.Context` through their work and wait for work they own before
returning. PromptKit calls using unrelated contexts are outside the observation
scope. No engine-construction adapter or particular engine instance is required.
This roadmap records the adoption strategy and open decisions. It is not an
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.
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.
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.
## Current CommandKit Baseline
- Core v0.7.0 owns dispatch, typed input, reporting, and outcomes. Its
[execution path](../../execute.go) finalizes reporting internally and exposes
no public invocation extension for this use case.
- [Invocation](../../identity.go) already carries the execution context.
- ckprompt v0.11.0 installs inspection and smoke-test commands through
[Command and Declarations](../../integrations/ckprompt/command.go). The family
does not currently add observation to application-owned commands.
- [Suite](../../integrations/ckprompt/adapters.go) capabilities can be narrowed;
an empty suite currently yields an absent command. Existing construction,
registration, namespace, and absence contracts must be considered deliberately.
- Core [reporting](../cli.md#reporting) separates command results from diagnostics
and preserves application outcomes when presentation fails.
## Adoption Strategy
### Core invocation integration
Add a narrow, library-neutral capability sufficient for ckprompt to register an
invocation-wide flag, decorate the context before execution work begins, retain
private invocation state, and submit final presentation before reporting closes.
Choose its public shape under D2 below. Core must not import PromptKit or ckprompt,
including through its tests, examples, tools, or module requirements.
Capture this behavior through supported installation contracts. Validate it with
the installation batch so a failed registration does not partially install flags
or lifecycle behavior. Apply it to applicable application commands regardless of
their registration order. Preserve help, completion, aliases, typed bindings,
and ordinary installation collision handling through the existing CLI machinery.
Do not parse raw arguments again inside ckprompt or require consumer wrappers
around `App.Execute`.
Keep the mechanism proportionate to this need rather than introducing a general
application runtime, dependency-injection system, or plugin framework.
### ckprompt observation and final reporting
Normal installation registers the usage capability automatically. When the flag
is enabled, ckprompt creates one native `ExecutionGroup` for that invocation and
decorates its context with the upstream helper. Create the scope early enough
for application initialization and acquisition callbacks reached during command
execution to receive it, as well as the main handler. Do not invoke engine
loaders or providers merely to install the capability or display help.
On ordinary command completion, including returned failure or cancellation,
snapshot the group and submit the selected summary through core reporting before
the reporter closes. The collection does not require a successful `RunResult`.
Keep each invocation's group separate; do not retain a process-wide history or
cache a group on a reused engine or suite.
Delegate composition, concurrency within the pipeline, and accounting to
PromptKit. Do not accumulate attempt and terminal usage locally or discover and
intercept arbitrary engine calls. This work does not establish concurrent
`App.Execute` support or change panic recovery and process-lifetime contracts.
### 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.
The summary supplements the application result. Preserve its outcome, explanation,
and supported error identity. Report output failures through the existing
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.
## Open Decisions
All recommendations below are proposals, not selected contracts. Resolve these
choices before writing a concrete implementation plan; implementation should
then be able to proceed through that plan without intermediate design gates.
### D1: Flag name and selection
Choose the standard flag name and Boolean occurrence semantics. Recommend
`--usage`, because the summary can include both tokens and cost, disabled unless
selected. `--token-usage` is the narrower alternative discussed so far. Use the
existing typed parsing and help/completion conventions; explicitly document
repeated occurrences and `=false`. Automatic availability does not mean printing
a summary when the operator has not requested it.
### D2: Installation API and capability availability
Choose the smallest public core composition contract and how normal ckprompt
installation supplies it. Both `Command` and `Declarations` are current public
assembly paths; recommend giving both automatic usage support rather than making
consumers switch to a special usage-enabled factory. Assess source compatibility
before selecting any signature change.
Also decide how usage is installed when all inspection callbacks are absent.
An empty suite currently means no command and no namespace claim. Recommend
preserving that absence behavior and explicitly defining whether usage-only
installation is supported, without silently changing the meaning of an empty
suite. Usage-only support is not necessary for the ordinary nonempty installation
goal. The mechanism must not depend on wrapping the engine loader or on enabling
a particular inspection callback.
### D3: Output destination, visibility, and finalization order
Recommend a concise summary on the diagnostic destination, normally stderr,
shown in ordinary mode when requested. An ordinary Info message alone is
insufficient because it is hidden without verbose mode. Choose the generic core
reporting facility needed for this presentation rather than bypassing reporting.
Decide its interaction with `--quiet` and the precise position among deferred
messages and terminal explanations. Recommend quiet mode suppress the summary,
consistent with successful output suppression, and present it after normal
command reporting but before a terminal failure explanation. Explicitly document
the chosen precedence between quiet mode and the usage flag.
### D4: Text and structured summary access
Choose whether the initial feature is a text diagnostic summary or also exposes
a separately formatted machine-readable summary. Recommend text on the diagnostic
stream initially, independent of `--format`, which already governs main results.
If structured usage output is selected, define its destination, framing, format
selection, and interaction with existing results before implementation. Keep
serialization in core; do not alter arbitrary application result shapes or
silently introduce another JSON document on their result stream.
### D5: No observations and commands that do not execute models
Decide what an explicitly requested summary shows when no ordinary execution
events were observed, including inspection-only commands or early returned
failures. Recommend a concise "No PromptKit executions observed" message rather
than an unlabeled zero-cost total; retain upstream empty-group semantics in any
structured representation. Recommend help, completion, and parse-only failures
produce no usage summary and require no acquisition work. Specify the boundary
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.
## 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.
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
presentation through normal installation. Cover both current assembly paths
and application commands registered separately from the standard family.
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.
5. Update owning GoDoc, the CLI reference, consumer guidance, and internal
inventory as implementation lands. Review dependency alignment and attribution.
Retire this roadmap after completion, preserving any deferred scope separately.
This work is expected to require a core release as well as ckprompt. Follow the
[downstream alignment policy](../policy/release.md#commandkit-downstream-dependency-alignment):
release core, align and release ckconfig, then align and release ckprompt against
the published core and ckconfig versions. ckconfig need not acquire usage
functionality. Exact versions and publication remain separate release work.
## Verification And Completion
The decisive consumer check is a normally installed ckprompt integration plus
an application-owned pipeline command. Selecting the usage flag must produce its
summary without request observers, accounting state, or a final reporting step
in application code. Verify the alternate assembly path and later registration
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.
Do not duplicate those upstream domain suites in CommandKit.
Validate help/completion without acquisition, existing explicit observer
coexistence, preserved application outcomes, and the selected empty-scope and
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.

View File

@@ -1,8 +1,14 @@
# Future work # Future work
Status — optional shell validation and future capability proposals. Status — active adoption roadmap, optional shell validation, and future capability proposals.
No delivery dates are selected here. No delivery dates are selected here.
## Active roadmap
[Automatic PromptKit usage reporting](automatic-usage-reporting.md) records the
goal of invocation-wide usage reporting through normal ckprompt installation,
the upstream dependency, and open design decisions.
## Purpose and authority ## Purpose and authority
Earlier completed roadmaps, implementation plans, and review findings have been retired. Earlier completed roadmaps, implementation plans, and review findings have been retired.