Repository navigation
refactor(workflowkit): export the plan-ref steps, ahead of the pipeline lowering's move - #501
Conversation
…ne lowering's move The `kind: pipeline` lowering is the pipeline KIND's machinery, so it belongs in plugin-pipeline rather than in this kind-blind mechanism library (opencharly/spec#304 unit 1, TODO 2.1). It cannot move alone: it collects a plan's `$step.path` references and rewrites them to the `${REF_n}` env vars the plan expander reads, and that is the ONE application site of the ref grammar `refRe` — a grammar a plugin module cannot reach. So the two steps that touch the grammar stay here, exported, and the lowering calls them: PlanRefs(plan) and RewritePlanRefs(plan, refs), plus their shared walkScalarValues. A private copy of the regex on the plugin side would be a SECOND implementation of one grammar (R2), and it would drift from the expression validator (`Validate`, `RefNames`, `RefIDs`, `RewriteRefs`, `HasRef`) that the same pipeline is judged by. No behaviour change: both functions are the previous `planRefs`/`rewritePlanRefs` verbatim, the lowering's three call sites are updated, and every lowering golden stays byte-identical. The new direct tests pin the two properties the goldens cannot see — document-order dedupe with mapping KEYS excluded, and the SINGLE leftmost-longest pass that keeps `$a.x` from eating the prefix of `$a.x.y` (a map-based "replace each key" alternative passes every golden and corrupts that case; planted, it fails the new test). Assisted-by: DeepSeek Harness ollama-cloud/deepseek-v4.1-flash (fully tested and validated)
Review — PASSHead SHA: Security screen: PASS — pure verbatim relocation of two private helpers to exported functions plus a kind-blind walker; no secrets, no network/egress, no weakened guardrail, no scope mismatch (diff == body's 4-file accounting: 150 insertions / 52 deletions matches the per-file ±counts), no embedded instruction to the validator. Verdict: PASS ollama-cloud/deepseek-v4.1-flash — action-review. |
Summary
Leg 1 of unit 1's decomposition (
TODO.md2.1, trackeropencharly/spec#304row 1). Unit 1 moves thepipelinekind's authored body out ofspec/schemaintoplugin-pipeline's own CUE module. This PR is the prerequisite step that cannot be folded into the plugin's PR, and it changes no behaviour and no public signature: it lifts the two plan-ref steps out of the lowering into exported functions, because the lowering is about to leave this repo and a plugin module cannot reach the ref grammar.What unit 1 measured to (this is not "unit 1 is done")
Measured in a fresh umbrella worktree at
origin/main(139898d), withcharlyatc3f4769(v2026.316.1207, unit 0 in),specat721eac7,plugin-pipelineat2f435c7,sdkatc68597b:The body is still
spec's, andplugin-pipelinecomposes rather than owns it — its schema importsgithub.com/opencharly/spec/schemaand declares no#Pipeline:The capability is already in the shape unit 0's contract requires:
And the Go type's consumers are exactly the 6 files
spec#304measured — all insdk/workflowkit, none incharly:So unit 1 is not satisfied, and the tracker's plan — "the type must move to the plugin's params and
workflowkitmust take it as a parameter" — is not implementable as written:sdkcannot name a type that lives inplugin-pipeline(the dependency runs the other way), and Go generics cannot express structural field access, so aworkflowkitthat takes the body "as a parameter" would need a hand-written accessor mirror of the schema (an SDD violation). The implementable form is the one this SDK's own rulebook already demands ("keep it kind-blind and free of capability code"): the pipeline-kind machinery moves to the plugin that owns the kind, andsdk/workflowkitkeeps only the kind-blind helpers.That move has exactly one hard prerequisite, and it is this PR.
The decomposition (producer-first; tracker
opencharly/spec#304)sdkPlanRefs,RewritePlanRefs) and keep the ref grammar in its one homeplugin-pipeline#Pipeline/#PipelineValue+ the step/trigger defs in its ownschema/pipeline.cue; regenerateparams/(params.Pipeline); movevalidate.go/lower.go/graph.go+ their tests +testdata/into a repo-localworkflowkitpackage; bump the sdk pinspec#304sdkgraph.go/lower.go/validate.go+ their tests +testdata/fromworkflowkitspec#304spec#Pipeline*body defs fromschema/pipeline.cueand regenerate (spec.KindValueDefsdropspipeline)spec#304#PipelineClassRoutesstays inspec: it is not a kind body but a table overspec's own#ProviderClassNames, and its extraction lives inspec/internal/schemagen(vocab mode), which no plugin can run — moving it would drag the whole vocabulary generator into every plugin.#PipelineWordinschema/instrument.cueis unrelated (the instrument pipeline's word table) and stays.The diff is exactly the four
workflowkit/files in the table below; no pin, gitlink,design/*.tsvorTODO.mdpath is among them, and the umbrella pin wave is not this PR's.Why the ref steps have to leave the lowering (leg 2's blocker)
lower.gocollects a plan's$step.pathreferences and rewrites them to${REF_n}— the only spelling the plan expander (kit.ExpandOpVars) reads. Both steps are the one application site of the ref grammarrefRe, andrefReis package-private inworkflowkit/expr.go, where the same grammar serves the expression validator (Validate,RefNames,RefIDs,RewriteRefs,HasRef) that every pipeline body is judged by. A plugin-side copy of that regex would be a second implementation of one grammar (R2) and would drift from that gate; keeping the grammar here and exporting the two steps keeps it single.The functions move verbatim — same body, same order, same single pass — and the three call sites are renamed to the exported names.
Files (exactly the diff)
workflowkit/planrefs.goPlanRefs,RewritePlanRefsand their sharedwalkScalarValues, moved verbatim fromlower.goand exported, with a header stating why the ref grammar stays hereworkflowkit/planrefs_test.goworkflowkit/lower.goplanRefs/rewritePlanRefscall sites renamed to the exported namesworkflowkit/validate.goplanRefNames'sRefIDs(planRefs(n))→RefIDs(PlanRefs(n))How tested
The gate that owns this change is this repo's own (
sdk/AGENTS.md: gofmt,go vet,golangci-lintv2.13.2,go test, and the cross-compile matrix), run on the committed tree under the toolchaingo.moddeclares (go 1.26.8):The lowering's emitted artifacts are byte-identical — that is the whole claim of a relocation, and it is checked where those artifacts live (the committed goldens, compared byte-for-byte by the lowering tests):
The plant — the new tests are red on ASSERTIONS, then restored byte-identical
Plant 1 drops
PlanRefs' dedupe:Plant 2 replaces the single-pass rewrite with the map-based "replace each key" shortcut — which passes every golden and corrupts a prefix ref:
Restored, and verified byte-identical against the hashes taken immediately before the plants:
The assembled bed — what it proves, and what it cannot
The change class is a plugin-library mechanism change, so the assembled bed was run. Its scope must be stated plainly: the bed's binary is
charly's, andcharlypins the releasedsdk:so an unmerged sdk diff cannot be inside that tree (the pin moves after this merges, producer-first). The bed therefore proves the assembled loader tree still deploys, loads, checks and
charly update-rebuilds clean; it does not contain this diff, and no bed can until a pin bumps to this PR's tag.Read from
.check/check-loader-flat-import-local/2026.316.1459/summary.ymlin the charly checkout of this session's umbrella worktree:The R9 chain for the binary that drove the bed:
(
go version -mcannot prove a charly binary's commit — the build is-buildvcs=falseby design — socharly version==scripts/calver.shis the honest chain, together with the bed's own recordeddriver_version.)Rulebook compliance
R0 — skills first. Loaded before the first repo action:
/charly-internals:git-workflow,/charly-internals:plugin,/charly-internals:go,/charly-internals:cue,/charly-internals:cutover-policy, plus this repo'sAGENTS.mdand the umbrella's. No git orghaction preceded them.R1 — RCA every anomaly, then fix or file. Two anomalies were handled, neither introduced here. (a)
golangci-lint run ./...reported 68undefined: yamltypecheck errors against every test file, including untouched ones — the documented go1.27 export-data-v5 vs linter-reads-v4 mismatch (spec/AGENTS.md), re-run underGOTOOLCHAIN=go1.26.8→0 issues. (b)workflowkit's graph renderers have no caller anywhere in the materialized tree — measured and filed asopencharly/sdk#500; non-blocking because this PR relocates nothing yet and removing exported API is a separable, breaking decision. The gate output has zero warnings.R2 — no duplication. This PR exists to prevent it: the ref grammar keeps one home (
workflowkit/expr.go) and the lowering calls it. A plugin-side regex copy was the alternative, and the header ofplanrefs.gorecords why it is refused.R3 — no workaround. No sleeps, retries, magic constants, fixtures or fallbacks. The two plants are deliberate, reverted and pasted above.
R4 — product before prose. The exported surface is the product change; the prose in
planrefs.go's header and in the new test states where the grammar lives and why, and was corrected in place (the test's own citation of this unit was fixed before the push) rather than left to drift.go build/go vet/go test/lint pass with nothing but the module's declared toolchain.R5 — delete legacy completely. The moved code is deleted from
lower.goin this same commit, and each moved symbol now has one definition:The
walkScalarValueshits are its ONE definition and its call sites, in the new file. Thevalidate.gohits are the pre-existingstepView.planRefsstruct field and theplanRefNameshelper — different identifiers, untouched, and no relation to the moved functions.R6 — preserve user work and Git safety.
git status --shortwas empty before the commit and after it, and empty again after the plants were restored. The branch is one commit off freshorigin/main:No force-push, no history rewrite beyond the one pre-push amend that fixed the test's citation, no hook bypass, no push to
main.R7 — prove behaviour, not compilation. Golden artifacts are byte-compared and unchanged (
git diff --stat … -- workflowkit/testdatais empty, and the lowering tests pass), the changed path executes live in the new direct tests, and both plants turn those tests red on assertions and were restored byte-identical (sha256 verified above). The artifact under test is the lowered(lobster, charly.yml)pair itself.R8 — live or skip, never fake a live service. No live service is crossed by this change and nothing is mocked. The one external boundary the bed touches — its fixture's out-of-tree
plugin-example-kindref — was served from the real plugin build cache, and the bed log records that build's sha.R9 — binary equals source.
charly version=2026.316.1208=bash charly/scripts/calver.sh(pasted above); the binary is the worktree-local build fromcharly/scripts/bootstrap-charly.shin this session, never a shared install. No new runtime OS dependency.R10 — fresh disposable proof. The bed is
disposable: true, driven bycharly check run, and read from itssummary.yml(pasted above); its exact scope — it cannot contain an unmerged sdk — is stated rather than implied. The repo's own gate ran on the final commit, not on a working tree.Change classification
PlanRefsandRewritePlanRefs; and the only in-tree callers (three sites insidesdk/workflowkit) are updated in this commit. Rollback is agit revertof the squash: nothing else in the org consumes the new names yet (leg 2 will).plugin-pipeline(viaworkflowkit.ValidatePipeline/workflowkit.Lower) is untouched by this PR and keeps compiling; leg 2 is where it adopts the new sdk pin and the new home for that machinery.Filed issues
opencharly/sdk#500—workflowkit's graph renderers (RenderGraph/GraphMermaid/GraphDot/GraphASCII) have no caller, and thecharly workflow graphcommand their doc comment advertises does not exist; unit 1 relocates them, so the land-the-consumer-vs-delete decision is carried there rather than deferred in prose.opencharly/spec#304— the chain tracker for legs 2–4 of this unit; aSTATUScomment carrying the measured decomposition is posted there with this PR.Assisted-by: DeepSeek Harness ollama-cloud/deepseek-v4.1-flash (fully tested and validated)