Skip to content

Commit b049002

Browse files
committed
feat(kit)!: P12a check/ADE architecture fold — movable-now sub-batch
Relocates the genuinely-portable half of the P12-rest RDD trace (the check/ADE surface) into sdk/kit and sdk/deploykit: AgentGrader (+ RunAgentOnce/parseVerdict/buildGraderPrompt), ContainerInspection + ResolveCheckVarsBuild/Runtime, the HTTP-do path (HTTPClientFor/ DoHTTPRequest/FormatHTTPHeaders), ValidatePlanSteps, and the local-image resolution surface (ListLocalImages/ResolveLocalImageRef/ ExtractCalVerTag/LooksLikeFullRef/ErrImageNotLocal) plus CheckBoxContainerChain in deploykit. Every piece needed no host callback — the trace's actionable finding was that this batch has a much larger movable-now surface than the P8b-rest precedent. BareVolumeName relocated from deploykit to kit (a pure string helper with no deploykit-specific coupling) so checkvars.go's mergeRuntimeVars can call it without a kit->deploykit import cycle; deploykit's own caller now calls kit.BareVolumeName. The GATED-R-ITEM half of the trace (needs the live core *Config/*Generator graph) is unchanged and joins the tracked K-wave-exit list. Verified via: go build/vet/test + golangci-lint (0 issues, after clearing a stale shared lint cache referencing another worktree) on every sdk package; gofmt clean. Assisted-by: Claude (fully tested and validated)
1 parent 496e9a2 commit b049002

13 files changed

Lines changed: 1869 additions & 15 deletions

‎CHANGELOG/2026.197.1300.md‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# P12a — check/ADE architecture fold, sdk leg (movable-now sub-batch)
2+
3+
Relocates the genuinely-portable half of the P12-rest RDD trace (charly's
4+
check/ADE surface) into `sdk/kit` and `sdk/deploykit`, per the T-53 trace that
5+
found this batch has a materially larger movable-now surface than the P8b-rest
6+
precedent — no host callback needed for any of the pieces below.
7+
8+
## sdk/kit additions
9+
10+
- `kit/grader.go` (+ `grader_test.go`) — `AgentGrader` (the production
11+
`StepGrader`), `RunAgentOnce`, `parseVerdict`, `buildGraderPrompt`,
12+
`lastVerdictObject`, `lastLines`, `GraderDefaultTimeout`. Relocated from
13+
`charly/check_feature_grader.go`. Lives in `kit`, not `candy/plugin-check`,
14+
because core CONSTRUCTS an `&AgentGrader{}` value directly
15+
(`host_build_check_run.go`'s `hostFeatureLive`) — core may only import sdk,
16+
never a plugin candy, so the concrete type core instantiates must live where
17+
core can reach it.
18+
- `kit/checkvars.go` (+ `checkvars_test.go`) — `ContainerInspection` +
19+
siblings, `CheckVarResolver`, `ResolveCheckVarsBuild`,
20+
`ResolveCheckVarsRuntime`. Every dependency was already portable:
21+
`spec.BoxMetadata`, `vmshared.BundleNode` (unused param), and a plain
22+
`{engine} inspect` shell-out.
23+
- `kit/http_do.go` (+ `http_do_test.go`) — `HTTPClientFor`, `DoHTTPRequest`,
24+
`FormatHTTPHeaders`. Relocated from `charly/check_http.go`, itself
25+
previously relocated FROM `candy/plugin-http` INTO core solely to share one
26+
implementation between the in-proc and reverse-channel `HTTPDo` legs — core
27+
had no core-specific need for this logic at all.
28+
- `kit/planvalidate.go` — `ValidatePlanSteps`. Invoked by BOTH
29+
`charly box validate` and the externalized `charly feature` HostBuild seam;
30+
one copy reachable from both without a core→plugin import (R3).
31+
- `kit/local_image.go` (+ `local_image_test.go`) — `LocalImageInfo`,
32+
`ListLocalImages`, `ParseLocalImagesJSON`, `ResolveLocalImageRef`,
33+
`ResolveNewestLocalCalVer`, `ExtractCalVerTag`, `LooksLikeFullRef`,
34+
`ErrImageNotLocal`. `ParseLocalImagesJSON`/`ExtractCalVerTag` are exported
35+
(charly core's `retention.go` calls them from a different package now);
36+
`LooksLikeFullRef` had 4 OTHER core callers beyond the moved file — all
37+
repointed to `kit.LooksLikeFullRef` (R3 single-source).
38+
- `kit/deploy_name.go` — `SanitizeDeployName` (relocated from
39+
`charly/k3s_post.go`, which had 4 core call sites) + `BareVolumeName`
40+
(relocated from `sdk/deploykit/quadlet.go` — a pure string helper with no
41+
deploykit-specific coupling, needed by `checkvars.go`'s
42+
`mergeRuntimeVars` without a kit→deploykit import, which would cycle).
43+
44+
## sdk/deploykit additions
45+
46+
- `deploykit/check_box_chain.go` — `CheckBoxContainerChain`, the R44
47+
Option-A box-mode executor. Relocated from `charly/check_box_container.go`
48+
(imported only `sdk/kit` + stdlib — zero charly-core-only state). Lives
49+
alongside `ContainerChain` (deploykit already owns that constructor).
50+
`deploykit/quadlet.go`'s own `BareVolumeName` definition deleted in favor
51+
of calling `kit.BareVolumeName` (deploykit already imports kit elsewhere in
52+
this file).
53+
54+
## What did NOT move (per the trace, unchanged)
55+
56+
The GATED-R-ITEM half of the trace (`check_cmd.go`'s live-gather engine,
57+
`check_venue.go`/`check_members.go`'s resolvers, the `host_build_check_bed.go`/
58+
`host_build_check_run.go` session bodies, `description_collect.go`'s
59+
`CollectDescriptions`, etc.) needs the live core `*Config`/`*Generator`/
60+
registry graph and is NOT part of this leg — it joins the tracked K-wave-exit
61+
list (task #21's precedent) for a future wave once the loader/Config state
62+
itself becomes plugin-servable.
63+
64+
Assisted-by: Claude (fully tested and validated)

‎deploykit/check_box_chain.go‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package deploykit
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"os/exec"
7+
"sync/atomic"
8+
9+
"github.com/opencharly/sdk/kit"
10+
)
11+
12+
// check_box_chain.go — the R44 Option-A box-mode executor (P12a: relocated from
13+
// charly/check_box_container.go). Lives here (not sdk/kit) because it constructs a
14+
// ContainerChain (deploykit's own DeployExecutor), so it sits alongside that
15+
// constructor; it imports only kit + stdlib — zero charly-core-only state — so core's
16+
// sole call site (host_build_check_run.go's hostBuildCheckBox arms) now calls
17+
// deploykit.CheckBoxContainerChain directly.
18+
19+
// checkBoxContainerSeq makes each check-box container name unique across concurrent
20+
// `charly check box` runs in ONE process (the pid already separates processes).
21+
var checkBoxContainerSeq atomic.Uint64
22+
23+
// CheckBoxContainerChain is the R44 Option-A box-mode executor: instead of a fresh
24+
// `podman run --rm <img> bash` per check step (N container SETUPS — each a rootfs mount +
25+
// temp-/etc/passwd generation that races concurrent build-store churn, the exit-127
26+
// passwd-file-race root cause), it creates ONE long-lived container from imageRef and returns
27+
// a ContainerChain exec'ing into it (O(N)→O(1) setups), unifying box-mode with check-live's
28+
// `podman exec` model. The per-step isolation of `--rm` is intentionally traded for the shared
29+
// container: `check:` steps are idempotent goss-style probes and check-live ALREADY runs them
30+
// against ONE shared container, so box-mode merely aligns (see the check skill; any check
31+
// secretly relying on fresh-container isolation is flushed by the all-images gate).
32+
//
33+
// The single container-CREATE is the one remaining setup that can race the store; its failure
34+
// is CLASSIFIED (kit.ClassifyContainerInfraFailure): an infra failure returns a MARKED error so
35+
// the caller exits the INFRA class (a plain error → exit 1), never checks-failed — a residual
36+
// setup failure is surfaced LOUDLY, never absorbed by a retry (classify-only, R44 ruling).
37+
//
38+
// Returns the exec chain + a teardown closure (always safe to call, even on the error paths).
39+
func CheckBoxContainerChain(engine, imageRef string) (DeployExecutor, func(), error) {
40+
name := fmt.Sprintf("charly-checkbox-%d-%d", os.Getpid(), checkBoxContainerSeq.Add(1))
41+
// `--pull=never`: imageRef is already resolved-local (kit.ResolveLocalImageRef verified it),
42+
// so the check must NEVER reach the registry (a pull under churn can 403/hang).
43+
// `--entrypoint=` clears any baked entrypoint (matching the per-step probe); `sleep infinity`
44+
// (coreutils, present in every image) keeps the container alive for the per-step `podman exec` probes.
45+
create := exec.Command(engine, "run", "-d", "--name", name, "--pull=never",
46+
"--entrypoint=", imageRef, "sleep", "infinity")
47+
_, stderr, code, err := kit.RunCaptureCmd(create)
48+
if err != nil || code != 0 {
49+
if sig, ok := kit.ClassifyContainerInfraFailure(code, stderr); ok {
50+
return nil, func() {}, kit.ContainerInfraError(sig, code, kit.TrimPreview(stderr))
51+
}
52+
if err != nil {
53+
return nil, func() {}, fmt.Errorf("check-box container create failed: %w (stderr: %s)", err, kit.TrimPreview(stderr))
54+
}
55+
return nil, func() {}, fmt.Errorf("check-box container create failed (exit %d): %s", code, kit.TrimPreview(stderr))
56+
}
57+
teardown := func() {
58+
rm := exec.Command(engine, "rm", "-f", name)
59+
_, _, _, _ = kit.RunCaptureCmd(rm)
60+
}
61+
return ContainerChain(engine, name), teardown, nil
62+
}

‎deploykit/quadlet.go‎

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ func emitInstallSection(b *strings.Builder, cfg QuadletConfig) {
326326
// volume/bind's container path if declared, else home.
327327
func ResolveWorkingDir(volumes []VolumeMount, bindMounts []ResolvedBindMount, home, boxName, instance string) string {
328328
for _, v := range volumes {
329-
if BareVolumeName(v.VolumeName, boxName, instance) == "workspace" {
329+
if kit.BareVolumeName(v.VolumeName, boxName, instance) == "workspace" {
330330
return v.ContainerPath
331331
}
332332
}
@@ -338,20 +338,6 @@ func ResolveWorkingDir(volumes []VolumeMount, bindMounts []ResolvedBindMount, ho
338338
return home
339339
}
340340

341-
// BareVolumeName strips the "charly-<box>[-<instance>]-" prefix from a resolved
342-
// volume name.
343-
func BareVolumeName(volumeName, boxName, instance string) string {
344-
if instance != "" {
345-
if p := "charly-" + boxName + "-" + instance + "-"; strings.HasPrefix(volumeName, p) {
346-
return volumeName[len(p):]
347-
}
348-
}
349-
if p := "charly-" + boxName + "-"; strings.HasPrefix(volumeName, p) {
350-
return volumeName[len(p):]
351-
}
352-
return volumeName
353-
}
354-
355341
// LocalizePort applies a host bind address to a port mapping.
356342
func LocalizePort(mapping string, bindAddr string) string {
357343
if p, ok := kit.ParsePortMapping(mapping); ok {

0 commit comments

Comments
 (0)