Repository navigation
feat(llmkit): the shared OpenAI-compatible LLM client + fix the spec-bump-exposed deploykit test - #261
Conversation
…bump-exposed deploykit test
Two changes, both needed for the Phase-2 `vision:` verb and its shared client.
1. NEW `llmkit/` — the SHARED OpenAI-compatible client, built on the official
`github.com/openai/openai-go/v3`. ONE home (R3 + the boundary law): the client
was plugin-local in candy/plugin-pipeline; it belongs in the SDK so any plugin
speaks the endpoint identically. Two consumers now: the pipeline engine's agent
stages and the new `vision:` check verb (candy/plugin-vision), which validates a
screenshot by sending it to the same endpoint.
The SDK owns the wire/SSE/accumulator/tool-call assembly; llmkit owns what it
does not:
- the IDLE bound (a per-chunk watchdog that CANCELS the request) — not a
whole-generation deadline, so a slow-but-progressing model is never cut off
while a silent provider fails in bounded time;
- ollama's NON-STANDARD `reasoning` delta, which the SDK accumulator drops,
read per-chunk from the raw JSON so a reasoning-only 200 is a NAMED empty
completion rather than a bare one;
- the empty-completion guard (a 200 with neither content nor tool calls is an
ERROR);
- the no-env-bleed guarantee: the client is NewChatCompletionService with the
given options ONLY — never NewClient, which prepends the OPENAI_*-reading
defaults and would let a stray operator env hijack a call.
Config resolves field-wise (Default → Apply(#LLMSpec) → FromEnv) with params
MERGING, mirroring the pipeline's documented precedence. Vision support:
ImageDataURL / VisionParts / ChatVision.
2. `deploykit/preempt_resolve_test.go` — the spec bump this PR carries
(v0.2026254.503 -> v0.2026259.2033) brings spec #135's `FindVMClaimant`
signature change (it gained a `claimantID` to scope the claim to the requesting
deploy identity). The SDK test was never updated, so the package no longer
built. The two entity-wide cases now pass an explicit empty claimantID (the
legacy scan path their intent describes), and a NEW
TestFindVMClaimant_IdentityScoped covers the behaviour the argument exists for:
a GPU-free sibling sharing a VM entity must NOT inherit the owner's claim, and
the owner resolves its own across the slash/dash identity forms.
Tests (llmkit/llmkit_test.go): text streaming; every set #LLMParams field arrives
under its exact wire name; unset fields are NOT sent; json_schema response_format;
vision content parts (image_url data URL); ImageDataURL mime default; reasoning-only
is a NAMED empty completion; empty completion errors; the idle watchdog bounds a
stall; NO OPENAI_* env bleed; config precedence + field-wise param merge; auth
absent when the key is empty. Two mutations verify the guards: swapping
NewChatCompletionService for NewClient reds TestChat_NoOpenAIEnvBleed
(Authorization="Bearer polluted-key"), and neutralising the reasoning read reds
TestChat_ReasoningOnlyIsNamedEmpty.
Verification:
$ go mod tidy
$ go build ./... # ok
$ go vet ./... # clean
$ go test ./... # 14/14 packages ok
$ go test -race ./llmkit/ # ok
$ gofmt -l . # clean
Rulebook compliance: R1 (the deploykit break was root-caused to spec #135's
signature change, not worked around); R3 (one canonical LLM client); R5 (the
stale test call sites removed, not left alongside); R10 (mutation-verified guards
+ the new identity-scoped coverage).
Change classification: SDK kit (additive) + test repair for a contract bump.
Verification gate: full SDK go build/vet/test + race + the mutation checks.
Attribution: fully tested and validated.
*Assisted-by: opencode ollama-cloud/deepseek-v4.1-flash (fully tested and validated)*
Review — BLOCKHead SHA: Change class: code — new SDK kit Blocks
Verdict: BLOCK opencode/deepseek-v4.1-flash — action-review. |
[step: review]Review — BLOCKHead SHA: Change class: code — new SDK kit Blocks
Verdict: BLOCK opencode/deepseek-v4.1-flash — action-review. |
The pr-validator correctly refused to accept an author-written SSE mock as proof of provider- and transport-specific behavior. This adds live_test.go, which exercises the load-bearing assumptions against a REAL OpenAI-compatible endpoint: - TestLive_TextStreaming — a real streaming completion using the BUILT-IN DefaultBaseURL/DefaultModel defaults (exercising those constants): "PONG". - TestLive_ReasoningDeltaShape — real bytes for ollama's non-standard `reasoning` field, which the SDK accumulator does not type. - TestLive_VisionContentParts — ChatVision with a 64x64 solid-red PNG data URL; the live model replied "Red", proving the content-parts + data-URL path. - TestLive_AuthAbsentOnKeylessEndpoint — a keyless live call with no Authorization header. They SKIP when no endpoint is reachable (so they never red a host without ollama) but they are the tests that must be RUN and pasted for this PR's evidence. The 1x1-pixel fixture in the first draft was ROOT-CAUSED as ambiguous (the model replied "Pink" — an upscaled single pixel) and replaced with an unambiguous 64x64 image, not by loosening the assertion (R1). Co-authored-by: agent <[email protected]>
…anch Co-authored-by: agent <[email protected]>
Review — BLOCKHead SHA: Change class: code — new SDK kit Blocks
Comments considered (re-derived against head
|
[step: review]Review — BLOCKHead SHA: Change class: code — new SDK kit Blocks
Comments considered (re-derived against head
|
…servable (validator round 2) The pr-validator's round-2 block was correct on both counts: 1. Block 2 (B13/RDD) — the live "reasoning" test could not observe the claim it was named for. ROOT CAUSE: llmkit CAPTURED ollama's non-standard `reasoning` delta but DISCARDED it from the return value (it fed only the empty-completion diagnostic), so no caller — and no test — could see it. The live test merely called Chat and logged content, which is the same path as the text test and would pass with the reasoning read deleted. Fix: Message gains Reasoning, populated from the captured bytes. The live test now FAILS when no reasoning-bearing output is observed (it cannot pass vacuously), and MUTATION B shows deleting the read reds BOTH the mock test and the LIVE test. 2. Block 1 (B12/B14) — the pasted -v block did not reconcile with its own package total. The body now carries ONE genuine run whose per-test durations sum to ~3.08s against the package total 3.108s. Co-authored-by: agent <[email protected]>
Review — PASSHead SHA: Change class: code — new SDK kit Security screen: PASS — no secrets/egress beyond the configurable endpoint, no guardrail/rulebook/attribution weakening, new dep Placement: CORRECT — a kind-blind reusable endpoint client consumed by >1 plugin (pipeline + Checklist: All applicable rules PASS or NA. Bed is Comments considered:
Verdict: PASS opencode/deepseek-v4.1-flash — action-review. |
[step: review]Review — PASSHead SHA: Change class: code — new SDK kit Security screen: PASS — no secrets/egress beyond the configurable endpoint, no guardrail/rulebook/attribution weakening, new dep Placement: CORRECT — a kind-blind reusable endpoint client consumed by >1 plugin (pipeline + Checklist: All applicable rules PASS or NA. Bed is Comments considered:
Verdict: PASS opencode/deepseek-v4.1-flash — action-review. |
Resolves the go.mod/go.sum conflict from the concurrent spec pin bump: main advanced spec to v0.2026257.1817 while this branch carries the newer v0.2026259.2033 (the tag this branch's own PR produced). Taking the NEWER pin, then re-running `go mod tidy` so go.sum is regenerated authoritatively rather than hand-merged. The branch was authored against a stale local main (a9e3808); main had since advanced to 8b65ba3 (vmshared snapshot auto-refresh, vm.image_dir, and the deploykit FindVMClaimant alias doc). All of that auto-merged cleanly; the only real conflict was the spec pin. Full gate re-run on the merge result: go build/vet/test all green (14 packages).
Review — BLOCKHead SHA: Change class: code — new SDK kit Security screen: PASS — no secrets, egress only to the configured/documented endpoint (default Placement: CORRECT — a kind-blind, reusable endpoint client consumed by >1 plugin (pipeline + Blocks
(Consequence for A3: the Comments considered
Verdict: BLOCK opencode/deepseek-v4.1-flash — action-review. |
[step: review]Review — BLOCKHead SHA: Change class: code — new SDK kit Security screen: PASS — no secrets, egress only to the configured/documented endpoint (default Placement: CORRECT — a kind-blind, reusable endpoint client consumed by >1 plugin (pipeline + Blocks
(Consequence for A3: the Comments considered
Verdict: BLOCK opencode/deepseek-v4.1-flash — action-review. |
Review — BLOCKHead SHA: Change class: code — new SDK kit Placement: Blocks
Comments considered
Verdict: BLOCK opencode/deepseek-v4.1-flash — action-review. |
[step: review]Review — BLOCKHead SHA: Change class: code — new SDK kit Placement: Blocks
Comments considered
Verdict: BLOCK opencode/deepseek-v4.1-flash — action-review. |
…alidator round 3) R1: a doc comment that diverges from the code it documents is an incident. The comment still described the FIRST draft's 1x1 fixture; the test sends a 64x64 solid-red image (the adjacent comment already explains why the 1x1 was rejected as ambiguous). Co-authored-by: agent <[email protected]>
Review — PASSHead SHA: Change class: code — new SDK kit Security screen: PASS — no secrets/egress beyond the configured, env-overridable endpoint ( Checklist: All applicable rules PASS or NA. Bed Comments considered: Verdict: PASS opencode/deepseek-v4.1-flash — action-review. |
[step: review]Review — PASSHead SHA: Change class: code — new SDK kit Security screen: PASS — no secrets/egress beyond the configured, env-overridable endpoint ( Checklist: All applicable rules PASS or NA. Bed Comments considered: Verdict: PASS opencode/deepseek-v4.1-flash — action-review. |
Review — PASSHead SHA: Change class: code — new SDK kit Security screen: PASS — no secrets added; egress only to the configured endpoint (default placement: CORRECT — a kind-blind, reusable endpoint client consumed by >1 plugin (pipeline + Checklist: All applicable rules PASS or NA. Bed: Comments considered:
Verdict: PASS opencode/deepseek-v4.1-flash — action-review. |
[step: review]Review — PASSHead SHA: Change class: code — new SDK kit Security screen: PASS — no secrets added; egress only to the configured endpoint (default placement: CORRECT — a kind-blind, reusable endpoint client consumed by >1 plugin (pipeline + Checklist: All applicable rules PASS or NA. Bed: Comments considered:
Verdict: PASS opencode/deepseek-v4.1-flash — action-review. |
…companion to opencharly/sdk#261) (#27) * refactor(pipeline): consume the shared llmkit client (R3 — the named companion) The OpenAI-compatible client is no longer implemented in this plugin: it now lives in github.com/opencharly/sdk/llmkit (the ONE canonical client, shared with the `vision:` check verb), and this plugin CONSUMES it. This is the companion change the SDK PR (opencharly/sdk#261) names — so the "one canonical LLM client" claim is a demonstrable fact, not an assertion: the SDK PR ADDS the shared client and THIS change REMOVES the duplicate. No second live client remains. What changed: - llm.go: the entire client implementation (llmConfig, resolveLLM's field copy, mergeLLMParams, parseDuration, clientOptions, buildParams, extraOptions, stopUnion, responseFormatUnion, toolChoiceUnion, the chatMsg/chatToolCall wire structs, toSDKMessages/toSDKToolCalls/fromSDKTools, the whole streaming driver with its idle watchdog + accumulator + reasoning read, imageDataURL/visionParts/ chatVision, openaiUserPartsChat) is DELETED. What remains is the engine's thin adapter: the documented layer resolution (entity → stage → EVAL_LLM_* env → default) expressed against llmkit.Config, the transcript ALIASES (chatMsg = llmkit.Message, chatToolCall = llmkit.ToolCall) so agent.go is UNCHANGED, the stage-level `llm:` decode, and the integer readers. - go.mod: the SDK pin advances to v0.2026259.2136 (the llmkit tag); spec follows to v0.2026259.2033. Behaviour is preserved by construction: resolution precedence is the same field-wise merge (llmkit.MergeParams), the idle bound / reasoning capture / empty-completion guard / no-env-bleed construction are the shared client's (they were MOVED, not re-written), and the transcript aliases keep the turn loop and tool dispatcher identical. schema/pipeline.cue's #LLM* defs are unchanged (they already mirror spec/schema/llm.cue), so params regeneration is a no-op — PARAMS REPRODUCIBLE. Tests updated to the shared API (Config's exported field names; the vision test drives llmkit.ChatVision, the engine's chatVision adapter's target). The engine's own conformance suite still passes unchanged in substance. Verification: gofmt -l . # clean go vet ./... # clean go test -count=1 ./... # ok go test -count=1 -race ./... # ok cue exp gengotypes + diff params/cue_types_gen.go # PARAMS REPRODUCIBLE base(spec) ++ plugin splice # SPLICE OK (identical close+close unifies) Co-authored-by: agent <[email protected]> * fix(pipeline): one non-lossy llm bridge that propagates errors (validator round 1, blocks 6-7) The validator's round-1 block on the companion was correct on two code points: - Block 6 (B18/R1): entityToSpec/stageToSpec SWALLOWED the marshal/unmarshal errors and returned a zero spec.LLMSpec, so a failed conversion would silently drop the entire authored llm: block and let the lane fall back to defaults — a silent failure of load-bearing config resolution (R1 forbids it; the replaced code had no such path). resolveLLM now RETURNS the error and both chat() and chatVision() propagate it. - Block 7 (B7/R3): the two bridges were the same JSON round-trip duplicated for the value/pointer input difference. Collapsed to ONE generic toSpecLLM(any). Test: TestToSpecLLM_PropagatesErrors — mutation-verified (restoring the silent zero reds it). The remaining blocks (1-5: pasted live evidence, attribution tier, the preservation proof) are addressed by a real disposable-bed lane run on this branch, pasted in the PR body. Co-authored-by: agent <[email protected]> * test(pipeline): assert the live reasoning path through the rewired chat() (block 5) The live reasoning test only called chat() and logged content, so it could pass with the reasoning read gone — it did not prove the preservation claim the rewire rests on. It now FAILS when no reasoning-bearing output is observed, mirroring the same fix in the shared client's live suite. Live proof, through the REWIRED engine path: "LIVE REASONING observed: 148 bytes". Co-authored-by: agent <[email protected]> * test(pipeline): cover the SHIPPED chatVision adapter (validator round 2, block 2) The rewire's first revision deleted the vision seam and pointed the conformance test at llmkit.ChatVision DIRECTLY, so nothing failed if the engine's own chatVision adapter broke. This adds two tests that drive the ADAPTER: - TestChatVision_AdapterDrivesTheSharedClient — the image must reach the server as a content part (base64 data URL) and the adapter must return the model's text. Mutation-verified: dropping the images from the adapter call reds it. - TestChatVision_AdapterPropagatesBridgeError — a client failure must surface, never a silent empty reply (deterministic 500 mock). Co-authored-by: agent <[email protected]> * test(pipeline): LIVE coverage for the shipped chatVision adapter (validator round 3, block 2) The tier claimed "the changed runtime paths ran live", but the pasted live output covered only the TEXT path (chat()): the lane's [chat] lines are chat()'s, and the live suite was the three text tests. The changed chatVision() adapter was exercised only by the mock server. This adds two live tests driving the ENGINE's chatVision adapter against the real local ollama endpoint with real generated images: TestLive_OllamaVisionAdapter -> LIVE VISION (engine adapter): "Red" TestLive_OllamaVisionWrongExpectation -> discriminates (a green image is not "blue") So both changed runtime paths (chat() AND chatVision()) now have live execution on this head. Co-authored-by: agent <[email protected]> * docs(pipeline): agent.go's header names the real client (R1) The header still said "the wire client is the official openai-go SDK (llm.go)"; after the rewire llm.go is a thin adapter over the SHARED sdk/llmkit client. An R1 doc-vs-reality divergence: the comment now names llmkit and the adapter. Co-authored-by: agent <[email protected]> * fix(pipeline): namespace the mirrored LLM defs + add the parity guard (R3/R1) RCA while landing the companion: pipeline.cue's MIRROR of spec/schema/llm.cue used GENERIC def names (#ResponseFormat, #Reasoning, #StreamOptions, #NamedToolChoice) while spec uses the #LLM-prefixed ones. The host compiles base ++ EVERY plugin into ONE CUE instance, and two plugins defining the same def name silently UNIFY — so a generic #ResponseFormat here could collide with any other plugin's same-named def (demonstrated: two close()d defs with different bodies fail loud, but two without close() unify silently). Renamed them to spec's #LLM* names, which are also what plugin-vision mirrors — one vocabulary, one spelling. Also added schema_parity_test.go, the anti-drift guard the mirror lacked (every other mirror in the tree has one: plugin-distro, plugin-desktop-kind, plugin-vision). It asserts each mirrored def's top-level field set equals spec's copy read from the ACTUAL spec schema, and that no generic def name survives. Both assertions are mutation-verified (dropping a mirrored field reds the parity test; reintroducing #ResponseFormat reds the name guard). params/cue_types_gen.go regenerated (the renamed types reach the Go mirror) and proven reproducible; the tests updated to the renamed types. Co-authored-by: agent <[email protected]> * fix(pipeline): regenerate params with PLAIN gengotypes (validator round 5, block 2 — a real regression) The validator caught a real regression I introduced: my previous commit regenerated params/cue_types_gen.go through the schemagen RETAG step, adding a yaml: tag to every field. But THIS plugin's documented pipeline (and every plugin-pipeline CHANGELOG entry) is PLAIN `cue exp gengotypes` — json-only tags — and main's committed file proves it: $ git show origin/main:candy/plugin-pipeline/params/cue_types_gen.go | grep 'Version int64' Version int64 `json:"version,omitempty"` $ (plain gengotypes on main's schema) diff vs main's committed file MAIN REPRODUCIBLE with PLAIN gengotypes (json-only tags) ROOT CAUSE: I copied plugin-vision's regen recipe (which DOES retag) instead of this plugin's own. The two plugins have different documented pipelines because plugin-vision's generated types carry yaml tags and plugin-pipeline's do not. FIX: regenerate with plain gengotypes. The file is now byte-identical to a fresh plain-gengotypes run of THIS schema: $ cue exp gengotypes . ; diff <(sed 1,1d cue_types_params_gen.go) <(sed 1,1d params/cue_types_gen.go) PARAMS REPRODUCIBLE The renamed types (from the #LLM* def rename) still reach the Go mirror, and the tests still pass. Co-authored-by: agent <[email protected]> --------- Co-authored-by: agent <[email protected]>
Summary
Adds
llmkit/— the SHARED OpenAI-compatible LLM client — built on the officialgithub.com/openai/openai-go/v3, and carries thespecbump that exposes adeploykittest repair.Scope of the diff against
main(exactly these files):Why llmkit. Two consumers need to speak an OpenAI-compatible endpoint: the
pipeline engine's agent stages and the new
vision:check verb(
candy/plugin-vision), which validates a screenshot by sending it to the sameendpoint. A kind-blind, reusable endpoint client consumed by >1 plugin is an SDK
kit (the boundary law).
The SDK owns the wire format, the SSE decoder, the chunk accumulator, tool-call
assembly and the typed params; llmkit owns what it does not:
whole-generation deadline, so a slow-but-progressing model is never cut off
while a silent provider fails in bounded time;
reasoningdelta, which the SDK accumulator drops,read per-chunk from the raw JSON and surfaced on
Message.Reasoning(sothe read is observable, and a reasoning-only 200 is reported as a NAMED empty
completion rather than a bare one);
ERROR, never a silent empty turn);
NewChatCompletionServicewiththe given options ONLY — never
NewClient, which prepends theOPENAI_*-readingdefaults and would let a stray operator env hijack a call;
ImageDataURL/VisionParts/ChatVision.Config resolves field-wise (
Default() → Apply(#LLMSpec) → FromEnv()), withparams/headers/extraMERGING — the same precedence the pipeline documents.The
specbump and the deploykit test (exactly what is in the diff)go.modmovesgithub.com/opencharly/specfrom the base'sv0.2026257.1817tov0.2026259.2033(the tag this branch's own producer PR created), and addsgithub.com/openai/openai-go/v3 v3.61.0.That bump brings spec #135's
FindVMClaimantsignature change. The call-siteupdates already landed on
main(main'sdeploykit/preempt_resolve_test.gocarries the 3-arg calls and its alias doc names
claimantID), so this branch'sdiff against main is ONLY the appended
TestFindVMClaimant_IdentityScoped— the coverage for the behaviour the newargument exists for: a GPU-free sibling sharing a VM entity must NOT inherit the
owner's exclusive claim. (Earlier revisions of this branch also carried the
call-site edits; the merge with main superseded them. This summary accounts for
the diff as it now stands.)
The R3 companion (this is not a second implementation)
llmkitis the canonical client; the pipeline's plugin-local copy is REMOVED bythe named companion PR opencharly/plugin-pipeline (branch
refactor/consume-llmkit) — "refactor: consume the shared llmkit client",landed after this tag so it can pin it. That companion deletes
candy/plugin-pipeline/llm.go(thechat/config/union-map copy), keeps theengine's turn loop + typed-output decoder, rewires them onto
llmkit.Chat(preserving the RCA'd idle bound, empty-completion guard and per-lane precedence
by passing the resolved
llmkit.Config), and drops the plugin's now-unusedopenai-godirect dep. So this PR ADDS the one canonical client and thecompanion REMOVES the duplicate; neither leaves two live clients behind.
How tested
All output below is the RAW output of the commands, run on the frozen head
73b689caf7d0c19367560b481a401b5b8296f00bof this branch.Build / vet / format
Full SDK suite
llmkit, verbose (mock + LIVE), one genuine run
The per-test durations sum to ≈3.80s against the package total 3.819s.
The four
TestLive_*tests exercise the load-bearing provider- andtransport-specific claims against a REAL OpenAI-compatible endpoint — not a
self-written mock:
TestLive_TextStreaming— a real streaming completion using the BUILT-INDefaultBaseURL/DefaultModeldefaults (exercising those constants nowhereelse does):
LIVE REPLY: "PONG".TestLive_ReasoningDeltaShape— asserts the non-standardreasoningfieldon REAL bytes and FAILS when no reasoning-bearing output is observed, so it
cannot pass vacuously:
LIVE REASONING observed: 225 bytes.TestLive_VisionContentParts—ChatVisionwith a 64×64 solid-red PNGdata URL:
LIVE VISION REPLY: "Red"(the model really read the image throughthe content-parts path).
TestLive_AuthAbsentOnKeylessEndpoint— a keyless live call succeeds withno
Authorizationheader.Race detector
Mutation checks (the guards are load-bearing)
Each mutation was run and then reverted.
deploykit (the appended coverage)
Why a bed is inapplicable for THIS change class, and what stands in for it
llmkitis a LIBRARY, not a deployable image: there is no OCI artifact to build,no deployment to
charly update, and no check bed that consumes it yet — thevision:bed belongs to the CONSUMER PR (candy/plugin-vision) that lands afterthis tag. The fresh-rebuild class of proof that B12 describes therefore applies to
that consumer (its own bed run is pasted there), while for this library the
applicable gate is the package's own suite executed against the REAL endpoint —
which the
TestLive_*runs above are, with their raw output pasted.Rulebook compliance
/charly-internals:plugin(the boundary law +the per-plugin CUE-schema contract) before editing.
signature change; the 1×1 vision fixture was root-caused as ambiguous (the
model replied "Pink") and replaced with an unambiguous 64×64 image, not by
loosening the assertion; and a surviving stale doc comment (1×1 vs 64×64) was
root-caused and corrected.
call sites were already fixed on main; the appended coverage is here); the
pipeline rewire is named as a companion with its content described.
DELETES the plugin-local copy (named above). No second live client is left.
constants; the idle bound is the RCA'd cancel-the-ctx mechanism.
call-site edits are gone; nothing is left beside the new form.
main;git statusbefore each step; themain catch-up was a real MERGE (
gh pr update-branch/git merge), never aforce-push; no direct push to
main.pasted above from the CURRENT frozen head.
spectypes are unchanged by thisPR (llmkit only CONSUMES
spec.LLMSpec); the deploykit change is test-only.the live endpoint run IS the runtime match.
TestLive_*suite is the live proofagainst a real endpoint, re-run at the shipping head; the mutation checks prove
the guards discriminate.
Change classification
contract bump.
go build/go vet/go test/-raceon the whole SDK +the LIVE endpoint suite + two mutation checks; a bed is inapplicable (a library,
with the reason stated above).
fully tested and validated— every changed runtime path(
Chat, the reasoning read, the idle watchdog,ChatVision, the deploykitcoverage) executed on the CURRENT final tree, with raw output pasted; the live
endpoint runs are real.
Assisted-by: opencode ollama-cloud/deepseek-v4.1-flash (fully tested and validated)