Adopt PromptKit usage and backend evidence

This commit is contained in:
2026-11-22 20:58:10 +00:00
parent ba6c9035b1
commit 0d5e13c7a9
9 changed files with 103 additions and 7 deletions

View File

@@ -264,6 +264,12 @@ part of this work.
## Stage 5: Adopt PromptKit v0.25.0 and preserve existing report evidence ## Stage 5: Adopt PromptKit v0.25.0 and preserve existing report evidence
**Complete.** Selected the published module and checked its license notice;
ckprompt forwards provider and explicit false zero-cost inspection data. Smoke
projection/render tests cover reasoning, absent and zero ratios, percentages,
and retained single/aggregate evidence in text, YAML, and JSON. The affected
Go 1.27.4 workspace suite passes.
1. Select the published PromptKit v0.25.0 in ckprompt's module files; use no sibling 1. Select the published PromptKit v0.25.0 in ckprompt's module files; use no sibling
replacement. Preserve ConfigKit v1.4.0 and unrelated dependency selections. replacement. Preserve ConfigKit v1.4.0 and unrelated dependency selections.
Check the selected upstream notices and update the PromptKit attribution entry Check the selected upstream notices and update the PromptKit attribution entry

View File

@@ -41,3 +41,10 @@ This module is licensed under the [GNU Lesser General Public License v3.0 or
later](COPYRIGHT). The accompanying [LICENSE](LICENSE) contains the full LGPL later](COPYRIGHT). The accompanying [LICENSE](LICENSE) contains the full LGPL
v3 and GPL v3 texts. See [third-party attribution](docs/oss/attribution.md) v3 and GPL v3 texts. See [third-party attribution](docs/oss/attribution.md)
for incorporated and dependency notices. for incorporated and dependency notices.
Smoke-test reports default to text; use `--format yaml` or `--format json` for
structured output. Reports preserve native reasoning-token and cache-hit evidence.
Backend provider conventions are selected explicitly in PromptKit configuration;
for example, application-defined OpenRouter backends need `provider: openrouter`.
See the [PromptKit backend format](https://forge.maximumdirect.net/base-layer/promptkit/src/tag/v0.25.0/docs/formats.md#backend-definitions)
for provider and zero-cost settings.

View File

@@ -2,16 +2,16 @@
## PromptKit ## PromptKit
Selected module: `go.maximumdirect.net/promptkit` at `v0.24.0`. Selected module: `go.maximumdirect.net/promptkit` at `v0.25.0`.
Copyright (C) 2026 Eric Rakestraw Copyright (C) 2026 Eric Rakestraw
SPDX-License-Identifier: LGPL-3.0-or-later SPDX-License-Identifier: LGPL-3.0-or-later
License and notices: [LGPL v3.0](../../LICENSE) | License and notices: [LGPL v3.0](../../LICENSE) |
[LICENSE](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/5ea60e9b96651fd7dfcbc7d05b6f43d131df358f/LICENSE). [LICENSE](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/207677e9948dc5699073a4d6620d21139033c72d/LICENSE).
[Source](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/5ea60e9b96651fd7dfcbc7d05b6f43d131df358f). [Source](https://forge.maximumdirect.net/base-layer/promptkit/src/commit/207677e9948dc5699073a4d6620d21139033c72d).
## ConfigKit ## ConfigKit

View File

@@ -6,7 +6,7 @@ require (
go.maximumdirect.net/ckconfig v0.10.0 go.maximumdirect.net/ckconfig v0.10.0
go.maximumdirect.net/commandkit v0.7.0 go.maximumdirect.net/commandkit v0.7.0
go.maximumdirect.net/configkit v1.4.0 go.maximumdirect.net/configkit v1.4.0
go.maximumdirect.net/promptkit v0.24.0 go.maximumdirect.net/promptkit v0.25.0
go.yaml.in/yaml/v4 v4.0.0 go.yaml.in/yaml/v4 v4.0.0
) )

View File

@@ -19,6 +19,8 @@ go.maximumdirect.net/configkit v1.4.0 h1:TfOupZbQ23/ZMs+xt5lmyukCF11ekqKep8KbmFQ
go.maximumdirect.net/configkit v1.4.0/go.mod h1:ewu6blSokUDCMovy8JBXAdXRikGmlHXAQpFghnPWRfs= go.maximumdirect.net/configkit v1.4.0/go.mod h1:ewu6blSokUDCMovy8JBXAdXRikGmlHXAQpFghnPWRfs=
go.maximumdirect.net/promptkit v0.24.0 h1:C6UFY8WgW10PIEuXQN2Z0qi0at5mD3/GQoPul6alYHo= go.maximumdirect.net/promptkit v0.24.0 h1:C6UFY8WgW10PIEuXQN2Z0qi0at5mD3/GQoPul6alYHo=
go.maximumdirect.net/promptkit v0.24.0/go.mod h1:o2axdkV11KTPDgk81i2vrJ66dtcedXRhau/Ko3YSZ4A= go.maximumdirect.net/promptkit v0.24.0/go.mod h1:o2axdkV11KTPDgk81i2vrJ66dtcedXRhau/Ko3YSZ4A=
go.maximumdirect.net/promptkit v0.25.0 h1:vJOfxauwASllOSDceR2oypJ4NEwIh2s6F8dDexEzdM8=
go.maximumdirect.net/promptkit v0.25.0/go.mod h1:o2axdkV11KTPDgk81i2vrJ66dtcedXRhau/Ko3YSZ4A=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
go.yaml.in/yaml/v4 v4.0.0 h1:/LG1pNO84Z4l603j/xMn69CcS5OYhMQ/f7l2LoQUGuw= go.yaml.in/yaml/v4 v4.0.0 h1:/LG1pNO84Z4l603j/xMn69CcS5OYhMQ/f7l2LoQUGuw=
go.yaml.in/yaml/v4 v4.0.0/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0= go.yaml.in/yaml/v4 v4.0.0/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=

View File

@@ -38,7 +38,8 @@ func TestResourceInspectionsForwardNativeReports(t *testing.T) {
extra := map[string]any{} extra := map[string]any{}
prompt := &promptkit.PromptInspection{PromptID: "p", PromptHash: "hash", Description: &empty, Inputs: &inputs, Messages: []promptkit.PromptMessageInspection{{Role: "user", Content: "captured {{.topic}}"}}} prompt := &promptkit.PromptInspection{PromptID: "p", PromptHash: "hash", Description: &empty, Inputs: &inputs, Messages: []promptkit.PromptMessageInspection{{Role: "user", Content: "captured {{.topic}}"}}}
profile := &promptkit.ProfileInspection{ProfileID: "p", Temperature: nil, MaxTokens: &zero, APIKeyRequired: &no, ExtraParams: &extra} profile := &promptkit.ProfileInspection{ProfileID: "p", Temperature: nil, MaxTokens: &zero, APIKeyRequired: &no, ExtraParams: &extra}
backend := &promptkit.BackendInspection{BackendID: "b", Endpoint: "https://example.invalid", QueueCapacity: &zero, ExtraParams: &extra} provider := "vllm"
backend := &promptkit.BackendInspection{BackendID: "b", Provider: &provider, ZeroCost: &no, Endpoint: "https://example.invalid", QueueCapacity: &zero, ExtraParams: &extra}
var selections []ckconfig.Selection var selections []ckconfig.Selection
calls := 0 calls := 0
suite := Suite[struct{}, struct{}]{ suite := Suite[struct{}, struct{}]{

View File

@@ -121,7 +121,7 @@ func runSmokeTest[I, S any](invocation commandkit.Invocation, suite Suite[I, S],
return definitionFailure(invocation.Context, smokeFailureMessage(input.kind), acquired.Explanation, operationErr) return definitionFailure(invocation.Context, smokeFailureMessage(input.kind), acquired.Explanation, operationErr)
} }
_ = invocation.Reporter().Report(commandkit.Report{Value: smokeReportFromNative(acquired.Value)}) _ = invocation.Reporter().Report(commandkit.Report{Value: smokeReportFromNative(acquired.Value), TextTemplate: smokeTextTemplate})
if operationErr != nil { if operationErr != nil {
return definitionFailure(invocation.Context, smokeFailureMessage(input.kind), acquired.Explanation, operationErr) return definitionFailure(invocation.Context, smokeFailureMessage(input.kind), acquired.Explanation, operationErr)
} }
@@ -184,7 +184,7 @@ func runSmokeAggregate[I, S any](invocation commandkit.Invocation, suite Suite[I
if len(results) == 0 { if len(results) == 0 {
return definitionFailure(invocation.Context, "PromptKit aggregate smoke testing did not produce any results.", combineSmokeExplanations(explanations), errors.Join(operationErrors...)) return definitionFailure(invocation.Context, "PromptKit aggregate smoke testing did not produce any results.", combineSmokeExplanations(explanations), errors.Join(operationErrors...))
} }
_ = invocation.Reporter().Report(commandkit.Report{Value: smokeResultsReport(results)}) _ = invocation.Reporter().Report(commandkit.Report{Value: smokeResultsReport(results), TextTemplate: smokeAggregateTextTemplate})
if len(operationErrors) > 0 { if len(operationErrors) > 0 {
return definitionFailure(invocation.Context, "One or more PromptKit smoke tests failed.", combineSmokeExplanations(explanations), errors.Join(operationErrors...)) return definitionFailure(invocation.Context, "One or more PromptKit smoke tests failed.", combineSmokeExplanations(explanations), errors.Join(operationErrors...))
} }

View File

@@ -1,6 +1,10 @@
package ckprompt package ckprompt
import ( import (
"bytes"
"text/template"
commandkit "go.maximumdirect.net/commandkit"
"time" "time"
promptkit "go.maximumdirect.net/promptkit" promptkit "go.maximumdirect.net/promptkit"
@@ -88,6 +92,8 @@ type smokeAttemptDTO struct {
type smokeUsageDTO struct { type smokeUsageDTO struct {
PromptTokens smokeTokenCount `json:"prompt_tokens"` PromptTokens smokeTokenCount `json:"prompt_tokens"`
CompletionTokens smokeTokenCount `json:"completion_tokens"` CompletionTokens smokeTokenCount `json:"completion_tokens"`
ReasoningTokens smokeTokenCount `json:"reasoning_tokens"`
CacheHitRatio *float64 `json:"cache_hit_ratio"`
TotalTokens smokeTokenCount `json:"total_tokens"` TotalTokens smokeTokenCount `json:"total_tokens"`
CachedTokens smokeTokenCount `json:"cached_tokens"` CachedTokens smokeTokenCount `json:"cached_tokens"`
CacheWriteTokens smokeTokenCount `json:"cache_write_tokens"` CacheWriteTokens smokeTokenCount `json:"cache_write_tokens"`
@@ -222,11 +228,33 @@ func durationString(duration *time.Duration) *string {
} }
func smokeUsageFromNative(usage promptkit.ObservedTokenUsage) smokeUsageDTO { func smokeUsageFromNative(usage promptkit.ObservedTokenUsage) smokeUsageDTO {
var ratio *float64
if value, ok := usage.CacheHitRatio(); ok {
ratio = &value
}
return smokeUsageDTO{ return smokeUsageDTO{
PromptTokens: smokeTokenCount(usage.PromptTokens), PromptTokens: smokeTokenCount(usage.PromptTokens),
CompletionTokens: smokeTokenCount(usage.CompletionTokens), CompletionTokens: smokeTokenCount(usage.CompletionTokens),
ReasoningTokens: smokeTokenCount(usage.ReasoningTokens),
CacheHitRatio: ratio,
TotalTokens: smokeTokenCount(usage.TotalTokens), TotalTokens: smokeTokenCount(usage.TotalTokens),
CachedTokens: smokeTokenCount(usage.CachedTokens), CachedTokens: smokeTokenCount(usage.CachedTokens),
CacheWriteTokens: smokeTokenCount(usage.CacheWriteTokens), CacheWriteTokens: smokeTokenCount(usage.CacheWriteTokens),
} }
} }
// The text view retains the full structured evidence and adds readable ratios.
var smokeTemplateFuncs = template.FuncMap{
"smokeEvidence": func(value any) (string, error) {
var b bytes.Buffer
err := commandkit.RenderReport(&b, commandkit.Report{Value: value}, commandkit.FormatYAML)
return b.String(), err
},
"percent": func(value *float64) float64 { return *value * 100 },
}
var smokeTextTemplate = template.Must(commandkit.ParseTextTemplate("smoke", `{{smokeEvidence .}}{{with .Usage.CacheHitRatio}}# Cache hit ratio: {{printf "%.1f" (percent .)}}%
{{end}}{{range $index, $attempt := .Attempts}}{{with $attempt.Usage.CacheHitRatio}}# Attempt {{$index}} cache hit ratio: {{printf "%.1f" (percent .)}}%
{{end}}{{end}}`, smokeTemplateFuncs))
var smokeAggregateTextTemplate = template.Must(commandkit.ParseTextTemplate("smoke aggregate", `{{smokeEvidence .}}{{range .Tests}}{{with .Report}}{{with .Usage.CacheHitRatio}}# Cache hit ratio: {{printf "%.1f" (percent .)}}%
{{end}}{{range $index, $attempt := .Attempts}}{{with $attempt.Usage.CacheHitRatio}}# Attempt {{$index}} cache hit ratio: {{printf "%.1f" (percent .)}}%
{{end}}{{end}}{{end}}{{end}}`, smokeTemplateFuncs))

View File

@@ -1,8 +1,12 @@
package ckprompt package ckprompt
import ( import (
"bytes"
"errors" "errors"
commandkit "go.maximumdirect.net/commandkit"
"strings"
"testing" "testing"
"text/template"
"time" "time"
promptkit "go.maximumdirect.net/promptkit" promptkit "go.maximumdirect.net/promptkit"
@@ -215,3 +219,51 @@ func containsSmokeKey(value any, want string) bool {
} }
return false return false
} }
func TestSmokeUsageReasoningAndCacheRatioRepresentations(t *testing.T) {
known := func(n int) promptkit.ObservedTokenCount {
return promptkit.ObservedTokenCount{Value: n, Known: true, Complete: true}
}
usage := promptkit.ObservedTokenUsage{PromptTokens: known(8), CachedTokens: known(1), ReasoningTokens: known(3)}
projected := smokeUsageFromNative(usage)
if projected.CacheHitRatio == nil || *projected.CacheHitRatio != 0.125 || projected.ReasoningTokens.Value != 3 {
t.Fatalf("usage=%#v", projected)
}
usage.CachedTokens = known(0)
zero := smokeUsageFromNative(usage)
if zero.CacheHitRatio == nil || *zero.CacheHitRatio != 0 {
t.Fatalf("zero ratio=%#v", zero)
}
usage.PromptTokens = promptkit.ObservedTokenCount{}
if smokeUsageFromNative(usage).CacheHitRatio != nil {
t.Fatal("unknown ratio is present")
}
report := smokeReportDTO{Kind: promptkit.SmokeTestAuthentication, Supported: true, Usage: projected, Attempts: []smokeAttemptDTO{{Usage: zero}}}
for _, tc := range []struct {
name string
value any
tmpl *template.Template
}{
{"single", report, smokeTextTemplate},
{"aggregate", smokeAggregateDTO{Tests: []smokeResultDTO{{Kind: promptkit.SmokeTestAuthentication, Report: &report}}}, smokeAggregateTextTemplate},
} {
t.Run(tc.name, func(t *testing.T) {
for _, format := range []commandkit.Format{commandkit.FormatText, commandkit.FormatYAML, commandkit.FormatJSON} {
var out bytes.Buffer
if err := commandkit.RenderReport(&out, commandkit.Report{Value: tc.value, TextTemplate: tc.tmpl}, format); err != nil {
t.Fatal(err)
}
text := out.String()
if !strings.Contains(text, "reasoning_tokens") || !strings.Contains(text, "cache_hit_ratio") || !strings.Contains(text, "attempts") || !strings.Contains(text, "supported") {
t.Fatalf("missing evidence: %s", text)
}
if format == commandkit.FormatText && (!strings.Contains(text, "12.5%") || !strings.Contains(text, "0.0%")) {
t.Fatalf("ratios: %s", text)
}
if format != commandkit.FormatText && !strings.Contains(text, "0.125") {
t.Fatalf("raw ratio: %s", text)
}
}
})
}
}