Skip to content

refactor(workflowkit): export the plan-ref steps, ahead of the pipeline lowering's move - #501

Merged
github-actions[bot] merged 1 commit into
mainfrom
feat/planrefs-exported
Nov 12, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
feat/planrefs-exported

Conversation

@aitrawog

@aitrawog aitrawog commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Leg 1 of unit 1's decomposition (TODO.md 2.1, tracker opencharly/spec#304 row 1). Unit 1 moves the pipeline kind's authored body out of spec/schema into plugin-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), with charly at c3f4769 (v2026.316.1207, unit 0 in), spec at 721eac7, plugin-pipeline at 2f435c7, sdk at c68597b:

$ grep -n "^#Pipeline:\|^#PipelineValue:" spec/schema/pipeline.cue
185:#Pipeline: {
207:#PipelineValue: #Pipeline @go(-)

The body is still spec's, and plugin-pipeline composes rather than owns it — its schema imports github.com/opencharly/spec/schema and declares no #Pipeline:

$ grep -rl "^#Pipeline:" --include='*.cue' plugin-pipeline/ spec/schema/
spec/schema/pipeline.cue

The capability is already in the shape unit 0's contract requires:

$ grep -n 'Class: "kind", Word: "pipeline"' plugin-pipeline/candy/plugin-pipeline/plugin.go
34:		{Class: "kind", Word: "pipeline", InputDef: "#PipelineValue"},

And the Go type's consumers are exactly the 6 files spec#304 measured — all in sdk/workflowkit, none in charly:

$ grep -rn "spec\.Pipeline\b" --include='*.go' charly sdk | grep -v '_test.go'
sdk/workflowkit/graph.go:32:func GraphEdges(p *spec.Pipeline) []GraphEdge {
sdk/workflowkit/graph.go:68:func GraphNodes(p *spec.Pipeline) []string {
sdk/workflowkit/graph.go:100:func RenderGraph(p *spec.Pipeline, format string) (string, error) {
sdk/workflowkit/graph.go:115:func GraphMermaid(p *spec.Pipeline) string {
sdk/workflowkit/graph.go:128:func GraphDot(p *spec.Pipeline) string {
sdk/workflowkit/graph.go:153:func GraphASCII(p *spec.Pipeline) string {
sdk/workflowkit/lower.go:45:func Lower(p *spec.Pipeline, projectDir, genDir, charlyBin string) ([]byte, []byte, error) {
sdk/workflowkit/validate.go:46:func ValidatePipeline(p *spec.Pipeline) error {
$ grep -rl "spec\.Pipeline\b" --include='*.go' sdk/workflowkit/ | wc -l
6
$ grep -rl "spec\.Pipeline\b" --include='*.go' charly/charly/ | wc -l
0

So unit 1 is not satisfied, and the tracker's plan — "the type must move to the plugin's params and workflowkit must take it as a parameter" — is not implementable as written: sdk cannot name a type that lives in plugin-pipeline (the dependency runs the other way), and Go generics cannot express structural field access, so a workflowkit that 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, and sdk/workflowkit keeps 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)

# repo what state
1 sdk export the plan-ref steps (PlanRefs, RewritePlanRefs) and keep the ref grammar in its one home this PR
2 plugin-pipeline declare #Pipeline / #PipelineValue + the step/trigger defs in its own schema/pipeline.cue; regenerate params/ (params.Pipeline); move validate.go/lower.go/graph.go + their tests + testdata/ into a repo-local workflowkit package; bump the sdk pin scheduled, spec#304
3 sdk delete the moved graph.go/lower.go/validate.go + their tests + testdata/ from workflowkit scheduled, spec#304
4 spec delete the #Pipeline* body defs from schema/pipeline.cue and regenerate (spec.KindValueDefs drops pipeline) scheduled, spec#304

#PipelineClassRoutes stays in spec: it is not a kind body but a table over spec's own #ProviderClassNames, and its extraction lives in spec/internal/schemagen (vocab mode), which no plugin can run — moving it would drag the whole vocabulary generator into every plugin. #PipelineWord in schema/instrument.cue is 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/*.tsv or TODO.md path 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.go collects a plan's $step.path references 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 grammar refRe, and refRe is package-private in workflowkit/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)

$ git diff --name-only origin/main...HEAD
workflowkit/lower.go
workflowkit/planrefs.go
workflowkit/planrefs_test.go
workflowkit/validate.go
$ git diff --shortstat origin/main...HEAD
 4 files changed, 150 insertions(+), 52 deletions(-)
file change
workflowkit/planrefs.go new: PlanRefs, RewritePlanRefs and their shared walkScalarValues, moved verbatim from lower.go and exported, with a header stating why the ref grammar stays here
workflowkit/planrefs_test.go new: the two properties the goldens cannot see — document-order dedupe with mapping keys excluded, and the single leftmost-longest pass
workflowkit/lower.go the two helpers and their walker deleted; the planRefs/rewritePlanRefs call sites renamed to the exported names
workflowkit/validate.go planRefNames's RefIDs(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-lint v2.13.2, go test, and the cross-compile matrix), run on the committed tree under the toolchain go.mod declares (go 1.26.8):

$ git rev-parse HEAD
f7a51f8adeed0f4adae1ac4557eafcaa3de0615c
$ test -z "$(gofmt -l .)"              # rc=0, no output
$ go vet ./...                          # rc=0, no output
$ go test ./... | tail -3
ok  	github.com/opencharly/sdk/storekit	0.208s
ok  	github.com/opencharly/sdk/vmshared	0.129s
ok  	github.com/opencharly/sdk/workflowkit	0.019s
$ golangci-lint run ./...               # v2.13.2, GOTOOLCHAIN=go1.26.8
0 issues.
$ for a in amd64 arm64 arm 386; do GOOS=linux GOARCH=$a CGO_ENABLED=0 go build ./... && echo "build $a ok"; done
build amd64 ok
build arm64 ok
build arm ok
build 386 ok

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):

$ git diff --stat origin/main...HEAD -- workflowkit/testdata
(no output — every golden untouched)
$ go test ./workflowkit/ -run 'TestLower|TestPlanRefs|TestRewritePlanRefs' -v
--- PASS: TestLowerCarriesLanesStep (0.00s)
--- PASS: TestLowerGolden (0.00s)
--- PASS: TestLowerRefsBraceForm (0.00s)
--- PASS: TestLowerInputSchemaKey (0.00s)
--- PASS: TestLowerRedoCarry (0.00s)
--- PASS: TestLowerNoRedoEmitsNoKey (0.00s)
--- PASS: TestLowerCharlyStep (0.00s)
--- PASS: TestLowerNestedPlan (0.00s)
--- PASS: TestLowerRejectsInvalid (0.00s)
--- PASS: TestPlanRefsDistinctInDocumentOrder (0.00s)
--- PASS: TestRewritePlanRefsOnePassAndBraceForm (0.00s)
ok  	github.com/opencharly/sdk/workflowkit	0.014s

The plant — the new tests are red on ASSERTIONS, then restored byte-identical

Plant 1 drops PlanRefs' dedupe:

$ go test ./workflowkit/ -run 'TestPlanRefsDistinctInDocumentOrder'
--- FAIL: TestPlanRefsDistinctInDocumentOrder (0.00s)
    planrefs_test.go:44: PlanRefs = [$b.two $a.one $b.two $c.three $a.one], want [$b.two $a.one $c.three]
FAIL

Plant 2 replaces the single-pass rewrite with the map-based "replace each key" shortcut — which passes every golden and corrupts a prefix ref:

$ go test ./workflowkit/ -run 'TestRewritePlanRefsOnePassAndBraceForm'
--- FAIL: TestRewritePlanRefsOnePassAndBraceForm (0.00s)
    planrefs_test.go:71: rewritten plan = "echo ${REF_1} ${REF_1}.y", want "echo ${REF_1} ${REF_2}"
FAIL

Restored, and verified byte-identical against the hashes taken immediately before the plants:

$ sha256sum planrefs.go planrefs_test.go   # before planting
a903b2719e7469ea5667748f2d464ec7f15698809b8ad3de474ba977c852712b  planrefs.go
68c645171f82394f528af5392af5773ad847160443d53b4905bbb973699dec6b  planrefs_test.go
$ sha256sum -c /tmp/oc21/sdk-preplant2.sha   # after restoring
planrefs.go: OK
planrefs_test.go: OK
$ git status --short
(no output — the restored tree is the committed tree)

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, and charly pins the released sdk:

$ grep -n 'opencharly/sdk' charly/charly/go.mod
71:	github.com/opencharly/sdk v0.2026309.2334

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.yml in the charly checkout of this session's umbrella worktree:

bed: check-loader-flat-import-local
calver: 2026.316.1459
driver: /home/atrawog/Sync/Atrapub/lo/dsh/opencharly/.worktrees/dsh-unit1-pipeline/opencharly/charly/bin/charly
driver_version: 2026.316.1208
driver_size: 56557895
driver_mtime: 2026-11-12T14:55:23Z
repo_override: github.com/opencharly/opencharly=/home/atrawog/Sync/Atrapub/lo/dsh/opencharly/.worktrees/dsh-unit1-pipeline/opencharly
runner_stderr: runner.stderr.log
steps:
  - name: deploy-add
    duration_seconds: 255
    ok: true
    status: PASS
    skipped: 0
  - name: bring-up-members
    duration_seconds: 0
    ok: true
    status: PASS
    skipped: 0
  - name: check-live
    duration_seconds: 198
    ok: true
    status: PASS
    skipped: 0
    checks:
      - id: loader-flat-import-validates
        status: PASS
        text: "a flat import plus a plugin-provided kind validates (both the decode fix and the flat-file read are exercised)"
        reason: exit=0
  - name: update
    duration_seconds: 233
    ok: true
    status: PASS
    skipped: 0
  - name: cleanup
    duration_seconds: 188
    ok: true
    status: PASS
    skipped: 0
  - name: cleanup-members
    duration_seconds: 0
    ok: true
    status: PASS
    skipped: 0
total_seconds: 874
diagnostics:
  errors: 0
  warnings: 0
  advisories: 0
  allowlisted: 0
  errors_fatal: true
  warnings_fatal: false
  advisories_fatal: false
  cache_ratio: not-applicable-no-build-steps
skipped_checks: 0
ok: true
status: PASS

The R9 chain for the binary that drove the bed:

$ ./charly/bin/charly version
2026.316.1208
$ bash charly/scripts/calver.sh
2026.316.1208

(go version -m cannot prove a charly binary's commit — the build is -buildvcs=false by design — so charly version == scripts/calver.sh is the honest chain, together with the bed's own recorded driver_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's AGENTS.md and the umbrella's. No git or gh action preceded them.

  • R1 — RCA every anomaly, then fix or file. Two anomalies were handled, neither introduced here. (a) golangci-lint run ./... reported 68 undefined: yaml typecheck 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 under GOTOOLCHAIN=go1.26.8 → 0 issues. (b) workflowkit's graph renderers have no caller anywhere in the materialized tree — measured and filed as opencharly/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 of planrefs.go records 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.go in this same commit, and each moved symbol now has one definition:

    $ grep -rn "planRefs\|rewritePlanRefs\|walkScalarValues" workflowkit/*.go
    workflowkit/planrefs.go:31:	walkScalarValues(plan, func(n *yaml.Node) {
    workflowkit/planrefs.go:51:		walkScalarValues(plan, func(n *yaml.Node) {
    workflowkit/planrefs.go:56:// walkScalarValues calls fn on every scalar VALUE in a node subtree (mapping KEYS are
    workflowkit/planrefs.go:58:func walkScalarValues(n *yaml.Node, fn func(*yaml.Node)) {
    workflowkit/planrefs.go:65:			walkScalarValues(c, fn)
    workflowkit/planrefs.go:69:			walkScalarValues(n.Content[i], fn)
    workflowkit/planrefs_test.go:5:// Before they were exported, `planRefs`/`rewritePlanRefs` were reached only THROUGH
    workflowkit/validate.go:72:			plan: len(s.Plan) > 0, planRefs: planRefNames(s.Plan), steps: len(s.Steps) > 0, input: nonZeroInput(s.Input),
    workflowkit/validate.go:95:				run: b.Run, pipeline: b.Pipeline, plan: len(b.Plan) > 0, planRefs: planRefNames(b.Plan), charly: len(b.Charly) > 0,
    workflowkit/validate.go:154:			run: b.Run, pipeline: b.Pipeline, plan: len(b.Plan) > 0, planRefs: planRefNames(b.Plan), charly: len(b.Charly) > 0,
    workflowkit/validate.go:174:	planRefs                        []string
    workflowkit/validate.go:225:	errs = append(errs, checkRefNames(where+".plan", v.planRefs, v.refsAmong, v.knobs, false)...)

    The walkScalarValues hits are its ONE definition and its call sites, in the new file. The validate.go hits are the pre-existing stepView.planRefs struct field and the planRefNames helper — different identifiers, untouched, and no relation to the moved functions.

  • R6 — preserve user work and Git safety. git status --short was empty before the commit and after it, and empty again after the plants were restored. The branch is one commit off fresh origin/main:

    $ git merge-base --is-ancestor origin/main HEAD && echo "origin/main is ancestor"
    origin/main is ancestor

    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/testdata is 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-kind ref — 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 from charly/scripts/bootstrap-charly.sh in this session, never a shared install. No new runtime OS dependency.

  • R10 — fresh disposable proof. The bed is disposable: true, driven by charly check run, and read from its summary.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

  • Class: plugin-library refactor (mechanism relocation plus two new exported functions). No schema, wire type, CLI flag or generated artifact changes.
  • Breaking change + rollback: none — the two functions are the previous private helpers verbatim under new names; the exported surface only gained PlanRefs and RewritePlanRefs; and the only in-tree callers (three sites inside sdk/workflowkit) are updated in this commit. Rollback is a git revert of the squash: nothing else in the org consumes the new names yet (leg 2 will).
  • Consumers: plugin-pipeline (via workflowkit.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 the charly workflow graph command 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; a STATUS comment carrying the measured decomposition is posted there with this PR.

Assisted-by: DeepSeek Harness ollama-cloud/deepseek-v4.1-flash (fully tested and validated)

…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)
@github-actions

Copy link
Copy Markdown

Review — PASS

Head SHA: f7a51f8adeed0f4adae1ac4557eafcaa3de0615c (branch: feat/planrefs-exported)

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.
Checklist: All applicable rules PASS or NA — R0/R1 (two anomalies RCA'd; graph-renderer dead-code filed as sdk#500, not in an edited file), R2/R5 (grammar stays single in expr.go; private helpers deleted in the same commit; grep output internally consistent), R3, R4, R6 (pre-push amend only, origin/main ancestor), R7 (plants turn the new direct tests red on assertions, restored byte-identical), R8, R9 (charly version == calver), R10 (bed ok:true/0 warnings; body honestly scopes that the bed cannot contain an unmerged sdk — producer-first, so proof-that-cannot-exist is not a block, and the change IS proven by the direct tests + byte-identical goldens that fail without it), A1 (body complete, Assisted-by: AI footer present and last), A2/A3 (tier fully tested and validated justified — the changed functions execute live under go test on a fresh build), QUAL. opencharly/spec#304 tracker STATUS + ## Filed issues satisfied; no second open PR exists, so no cross-thread WAITING/HOLDING is due.
Placement: CORRECT — workflowkit (sdk) is the right layer: PlanRefs/RewritePlanRefs are kind-blind (*yaml.Node) mechanisms sharing the refRe grammar with the expression validator; a plugin-side copy would be a second grammar implementation (R2). No alias growth, no new kit import into core, no *Legacy* smell.
Comment thread: empty (0 comments) — nothing to disposition.

Verdict: PASS


ollama-cloud/deepseek-v4.1-flash — action-review.

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) November 12, 2026 15:24
@github-actions
github-actions Bot merged commit e91e784 into main Nov 12, 2026
8 checks passed
charly-auto-merge Bot added a commit that referenced this pull request Nov 12, 2026
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