Skip to content

feat(core)!: K3 build-engine core-minimization — reentry-class + render-seam + feature-command - #139

Merged
atrawog merged 10 commits into
mainfrom
feat/k3-build-zero-kit
Jul 17, 2026
Merged

atrawog merged 10 commits into
mainfrom
feat/k3-build-zero-kit

Conversation

@atrawog

@atrawog atrawog commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

The charly-side (super) leg of the K3 "build-engine → plugin-build" cutover, part of the ongoing core→plugin metric program (charly/*.go files importing sdk/kit/sdk/deploykit/sdk/buildkit: 157 → 0). Depends on sdk PR opencharly/sdk#65 merging first.

Four whole-file / real retirements, no remainders left behind:

  1. charly/box_labels_cmd.go deleted — the hidden __box-labels core reentry. candy/plugin-box's labels command now calls kit.ResolveRuntime/kit.ResolveLocalImageRef/kit.InspectImageLabels directly (pure container-storage probes, zero loader coupling) — dispatchLabels drops its hostClient parameter entirely, matching the new command group's already-zero-reentry shape. canonicalLabelKey/sortedLabelKeys moved with it. Also fixes a latent FormatCLIError bug this move exposed (its kit.ErrImageNotLocal ref-extraction assumed the sentinel's message was the WHOLE error text — broke the instant the error crossed the compiled-in command dispatcher's generic "command %q: %w" wrap; no prior caller had ever exercised that path). Added the test FormatCLIError never had.

  2. Render-seam production move — charly/host_build_render_seam.go drops 5 of its 9 dispatch cases (RenderSeamRenderService/RenderSeamDetectionBuilder/RenderSeamExternalBuilder/RenderSeamRewriteHeaderCopy/RenderSeamValidateEgress): candy/plugin-build's render no longer calls back for these (sdk-side commit wires the direct InvokeProvider dispatch). The underlying host functions (RenderService, egressValidate/validateTextEgress, resolveDetectionBuilderStageSeam, resolveExternalBuilderStageSeam, rewriteHeaderCopyForRemote) are not deleted — they remain load-bearing for tasks.go's toDeploykit(), a separate, parallel deploykit.Generator construction charly core itself uses for generate.go's helper wrappers and step_emit_hostbuild.go's live calls (found via grep before touching anything, avoiding a real regression). So this piece is metric-neutral by itself (154, unchanged) but is real, live-verified decoupling of candy/plugin-build from those 5 host callbacks.

  3. charly/effective_version.go deleted — a 13-line, one-caller shim (computeEffectiveVersions delegating to deploykit.ComputeEffectiveVersions), inlined at its sole call site in generate.go's NewGenerator.

  4. charly/host_build_feature.go drops its kit/deploykit import entirely — its plan-to-summary transform (kit.KeywordOf/kit.ValidatePlanSteps/deploykit.DescriptionInfo) was calling only sdk-portable functions on data already in hand. Moved into candy/plugin-feature/command.go (which already owns the list/pending/validate grammar): the host now ships raw spec.FeatureEntity data (description + []Step, sdk PR changes the wire shape) and the plugin computes summary/steps/validation itself. What's left host-side is exactly LoadConfig/ScanCandy — the loader Mechanism, nothing else.

Metric

charly/*.go kit-importing files: main = 154 → this branch = 150 (verified against current origin/main, branch is 0 commits behind).

Test plan

  • go build/go vet/go test ./... clean across charly, candy/plugin-box, candy/plugin-feature, candy/plugin-build
  • golangci-lint run ./... — 0 issues on every touched package
  • Live-verified on a rebuilt binary against box/fedora's real check-pod bed, full R10 sequence (build → check-image → deploy-add → config → start → check-live → feature-run → fresh-rebuild → feature-run-rebuild → cleanup), run twice (once for the render-seam move, once after the final refactor), both PASS 12/12 — confirms the external-builder splice, the supervisord service render, and the remote header-copy materialization all render correctly in the generated Containerfile
  • Live-verified charly box labels <ref> (default listing, --format, --all, and the missing-image error path) against a real locally-built image, both before and after the FormatCLIError fix
  • Live-verified charly feature list (with and without a kind filter), charly feature pending, and charly feature validate against box/fedora (a real project, 3 baked box entities) — correct output, including a genuine pre-existing validation finding (2 box entities with an empty description:) unrelated to this refactor
  • git grep R5 self-test clean (no stale references to deleted symbols outside CHANGELOG/)

Companion PRs: opencharly/sdk#65 (merge first), a plugins docs leg (stale charly/effective_version.go skill references).

Claude-Session: https://claude.ai/code/session_01R8UGGr3ui1959oTb5JuSif

atrawog added 7 commits July 17, 2026 02:18
#39)

Consumer half of the sdk spec.DoMode/spec.ExecContext/spec.StepDoMode move:
checkspec.go's local kit.DoMode alias is gone (VerbCatalog/VerbSpec now
carry spec.DoMode/spec.ExecContext directly); layers.go, planrun_adapter.go,
description_collect.go, and candy/plugin-box/validate_check.go repointed
from kit.X/deploykit.X to spec.X. checkspec.go's deploykit.OpInContext
DI-hook registration relocated to layers.go (which already imports
deploykit for other reasons) so checkspec.go now imports neither kit nor
deploykit at all.

Assisted-by: Claude Sonnet 5 (analysed on a live system)
…/plugin-box

Deletes the __box-labels core reentry: BoxLabelsCmd's whole Run() body was
pure container-storage probing (kit.ResolveRuntime/ResolveLocalImageRef/
InspectLabels), zero live-loader coupling — unlike its pkg/inspect-overlay/
list-tags/fetch/refresh siblings, which genuinely need host-coupled state
and stay K5-doomed reentries. candy/plugin-box's `labels` command now calls
the promoted sdk/kit.InspectImageLabels (prior commit) directly, so the
labels word needs no host reentry at all — dispatchLabels drops its
hostClient parameter entirely, matching the `new` group's zero-reentry
shape. canonicalLabelKey/sortedLabelKeys move with it; the misplaced
TestApplySecretRefresh_NamedAllAndUnmatched (actually testing secrets.go's
ApplySecretRefresh) moves to secrets_test.go where it belongs.

Also fixes a latent FormatCLIError bug this move exposed: its ref-extraction
assumed kit.ErrImageNotLocal's message was the WHOLE error text (a bare
strings.TrimPrefix), which broke the instant a compiled-in command's error
crossed dispatchInProcCommand's generic "command %q: %w" wrap (candy/
plugin-box's labels command is the first ErrImageNotLocal caller to hit that
path — every prior caller went through the old __box-labels SUBPROCESS
reentry, whose own inner FormatCLIError call never saw the outer wrap).
Now finds the marker anywhere in the message via strings.LastIndex, so
`charly box labels <missing-image>` renders the friendly "run box pull"
recommendation correctly whether ErrImageNotLocal is bare or wrapped.

Live-verified on a rebuilt binary against a real check-pod image: happy
path (`box labels`, `--format`, `--all`), the missing-image error path
(pre- and post-fix), all via box/fedora's check-pod fixture. Metric:
kit-importing charly/*.go files 155 -> 154.

Assisted-by: Claude Code Claude Sonnet 5 (analysed on a live system)
Claude-Session: https://claude.ai/code/session_01R8UGGr3ui1959oTb5JuSif
Removes host_build_render_seam.go's RenderSeamRenderService/
RenderSeamDetectionBuilder/RenderSeamExternalBuilder/RenderSeamRewriteHeaderCopy/
RenderSeamValidateEgress cases: candy/plugin-build's render no longer calls
back for these (sdk commit — the seams now dispatch directly via
InvokeProvider). Their underlying host functions (RenderService,
egressValidate/validateTextEgress, resolveDetectionBuilderStageSeam,
resolveExternalBuilderStageSeam, rewriteHeaderCopyForRemote) are NOT deleted
— they remain load-bearing for toDeploykit(), a SEPARATE, parallel
deploykit.Generator construction charly core itself uses for
generate.go's helper wrappers (GlobalOrderForBox/GenerateInitFragments/
CollectBuilderRuntimeEnv/BuildStageContext/CandyCopySource) and
step_emit_hostbuild.go's live emitTasks/buildStageContext calls — verified by
grep before touching anything (caught before an incorrect deletion, R1).
So this cutover does NOT retire any whole file from charly/*.go's kit-import
list (metric unchanged at 154) — genuine, live-verified decoupling of
candy/plugin-build from 5 of 9 render-seam host callbacks, but not a
metric-moving change under the "whole files out of core" scoreboard.

Live-verified: box/fedora's check-pod bed, full R10 sequence (build through
fresh-rebuild), PASS (12/12 steps) — the external-builder splice, the
supervisord service render, and the remote header-copy materialization
(.build/_buildconfig/templates/supervisord.header.conf) all confirmed
correct in the generated Containerfile + runtime checks.

Assisted-by: Claude Code Claude Sonnet 5 (fully tested and validated)
Claude-Session: https://claude.ai/code/session_01R8UGGr3ui1959oTb5JuSif
…e (K3)

computeEffectiveVersions was a 13-line, ONE-caller shim doing nothing but
delegating to deploykit.ComputeEffectiveVersions. Inlines the call directly
at its sole call site (generate.go's NewGenerator) and deletes the file
outright — a whole FILE off charly/*.go's kit-import list, not a partial
extraction (per the velocity-correction strategy: the metric is whole files,
not LOC/coupling reduction alone). Updated the test file's calls to the
direct deploykit form (same behavior, no charly wrapper) and swept the one
stale generate.go/unified.go comment reference.

Verified: go build/vet/test clean; charly box validate (box/fedora, exit 0)
+ the check-pod bed's build step both exercise this exact code path live.
Metric: 154 -> 153.

Assisted-by: Claude Code Claude Sonnet 5 (fully tested and validated)
Claude-Session: https://claude.ai/code/session_01R8UGGr3ui1959oTb5JuSif
…t/deploykit

Moves the plan-to-summary transform (keyword/text/agent/check flattening +
kit.ValidatePlanSteps + deploykit.DescriptionInfo) from
host_build_feature.go into candy/plugin-feature/command.go, which already
owns the list/pending/validate grammar. The host now enumerates every
kind: entity's RAW description + plan (spec.Step, already a plain
CUE-sourced wire type) and ships it as-is; the plugin computes
summary/steps/validation itself. host_build_feature.go needs no
kit/deploykit import as a result -- a genuine whole-file drop off the
core kit-import list (not a partial split), per the binding
architectural rule that a host-coupled REMAINDER left behind is a failed
move: the ONLY thing still core-side is LoadConfig/ScanCandy (the
loader Mechanism itself), which the file's own doc comment already named.

Updated host_build_feature_test.go to assert on the raw Plan field (and
call kit.ValidatePlanSteps directly, matching the plugin's own call);
added command_test.go in candy/plugin-feature covering the moved
planSteps/summary transform.

Live-verified on box/fedora (a real project with 3 baked box entities):
`charly feature list` (with/without a kind filter), `charly feature
pending`, and `charly feature validate` (correctly flags 2 pre-existing
box entities with an empty description: field, unrelated to this
refactor -- exit 1, as expected) all render byte-equivalent output to
the pre-refactor design. go build/vet/test/golangci-lint clean across
sdk, charly, and candy/plugin-feature. Metric: 151 -> 150.

Assisted-by: Claude Code Claude Sonnet 5 (fully tested and validated)
Claude-Session: https://claude.ai/code/session_01R8UGGr3ui1959oTb5JuSif
atrawog added 3 commits July 17, 2026 04:02
…erContext

The render-seam production move promoted buildServiceRenderContext/
flattenedEnvMap/sortedEnvList to sdk/deploykit as BuildServiceRenderContext
(so both charly's own RenderService and candy/plugin-build's render share
one source, R3) but left charly's OWN local copies in place instead of
repointing to the promoted version -- a genuine duplicate this cutover
introduced, caught while re-auditing per the operator's "keep hunting"
directive. RenderService now calls deploykit.BuildServiceRenderContext
directly; the file drops its kit import (no longer needs kit.ExpandPath
locally) but gains deploykit (needed for the call + the already-present
CandyModel-adjacent seam) -- metric-neutral, but a real duplication fix.

All 9 existing service_render_test.go tests pass unchanged (byte-identical
rendered output through the shared function). Live-verified: box/fedora's
check-pod bed (which exercises supervisord service rendering directly),
full R10, PASS 12/12.

Assisted-by: Claude Code Claude Sonnet 5 (fully tested and validated)
Claude-Session: https://claude.ai/code/session_01R8UGGr3ui1959oTb5JuSif
R5 fix: image.go's BoxCmd migration-inventory comment still named the
deleted box_labels_cmd.go (a PR-validation blocker — a false claim would
have shipped). Now names labels.go and the 2026-07 K3 externalization.

Bucket-1 fold-in (a read-only spike into toDeploykit()'s remaining
Generator-consumers): generateInitFragments and candyCopySource have zero
non-test callers — their own doc comments named a caller
(deploy_target_pod.go) that no longer exists, and candy/plugin-deploy-pod/
overlay.go already calls deploykit.Generator.GenerateInitFragments/
.CandyCopySource directly on its own NewRenderGeneratorFromProject
Generator, bypassing these wrappers entirely. Deleted both from
charly/generate.go. Their test coverage (TestGenerateInitFragments,
TestGenerateRelayInitFragments, TestCandyCopySource) moved WITH the real
logic to sdk/deploykit/init_test.go + sdk/deploykit/candy_stage_test.go
(sdk commit 95c8577) rather than being discarded, since neither function
had any coverage of its own in that package.

Metric-neutral (150; both deletions were charly-core-only, no kit/
deploykit import at stake).

R10: go build/vet/test clean on both repos (charly 88s full pass, sdk
deploykit pass); golangci-lint 0 issues on both. charly check run
check-pod (box/fedora, per-worktree binary rebuilt from this branch):
PASS, 12/12 steps including the fresh-rebuild gate and post-rebuild
feature verification (total 217s), clean teardown.

Assisted-by: Claude Sonnet 5 (fully tested and validated)
sdk#65 merged as e779c531 (tagged v0.2026198.254); plugins#81 merged as
4a2ac8d2 (tagged v2026.198.0256). Repoints both submodule pointers from
their pre-squash branch tips to the real merged commits (the sdk#63
lesson: a pre-squash tip becomes unreachable after squash-merge).

Assisted-by: Claude Sonnet 5 (fully tested and validated)
@atrawog

atrawog commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

Independent PR validation — PASS

Fresh, independent re-derivation across 3 rounds (fresh worktree, trusting no author/orchestrator claims):

Round 1 (head fc5906b/771275c/2b68894): metric independently re-walked file-by-file: main=154, branch=150 (confirmed, not trusted). Architecture gate on every kept/touched core file: host_build_feature.go holds ONLY LoadConfig/ScanCandy (legit M-mechanism), zero remainder; host_build_render_seam.go's 4 remaining cases each name a real constraint (2 ride K1 loader-connect, 1 needs a Go type-assertion against a builtin's concrete type — not a vague "host-coupled" claim); checkspec.go legitimately keeps VerbCatalog as D-data. charly feature list/pending/validate live-exercised against box/fedora — matches claims exactly. check-pod bed PASS 12/12.

Found ONE real issue: charly/image.go's migration-inventory comment still named the deleted box_labels_cmd.go as if it still existed ("already document their own... notes") — an R5 stale reference the author's own unified.go sweep pattern should have caught but missed. CHANGES REQUESTED.

Round 2 (head 1a03a2e, the R3 self-fix): re-verified build/vet/test/lint clean, metric still 150, the 3 dissolved service_render.go duplicate functions genuinely gone (confirmed deploykit.BuildServiceRenderContext's promoted logic is byte-identical). check-pod bed PASS 12/12 (independent re-run).

Round 3 (head 0183b60, the R5 fix + Bucket-1 dead-code deletion): confirmed the image.go fix is correct and complete; confirmed generateInitFragments/candyCopySource had zero non-test callers (verified candy/plugin-deploy-pod/overlay.go calls dg.GenerateInitFragments/dg.CandyCopySource directly on its own Generator — the real production path, independent of the deleted wrappers); confirmed their test coverage was genuinely ported (not discarded) to sdk/deploykit/init_test.go + candy_stage_test.go verbatim. Full build/vet/test/lint clean, metric still 150. check-pod bed PASS 12/12 (final, independent re-run against this exact head).

Final gitlink bump (6f282d4): repointed sdk → e779c531 (the actual merged sdk#65 SHA, not the pre-squash branch tip — the sdk#63 lesson) and plugins → 4a2ac8d2 (the actual merged plugins#81 SHA). Rebuilt + re-ran full build/vet/test with these final gitlinks: clean. Metric re-confirmed on this exact commit: 150.

Landing: sdk#65 merged as e779c531ac48e4806711f3215c256ae04caf4414 (tagged v0.2026198.254), plugins#81 merged as 4a2ac8d258c17ce167da8c85a2f74716d6f2e38e (tagged v2026.198.0256). Merging charly#139 now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant