Skip to content

feat(kit): a step's process environment carries the host's values as DATA - #475

Merged
github-actions[bot] merged 1 commit into
mainfrom
feat/step-env-data-channel
Oct 24, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
feat/step-env-data-channel

Conversation

@aitrawog

Copy link
Copy Markdown
Contributor

Summary

A host's resolved values could reach a command only as shell SOURCE. The kit had exactly one channel for them: kit.ExpandOpVars substitutes a value into the step's command TEXT, and the shell then parses that text. A value that is DATA therefore becomes SOURCE — a $(…) inside a value EXECUTES, and a value carrying a space arrives as two words. This is the seam opencharly/plugin-task#34 names, and the mechanism belongs in the kit, where the plan walk lives.

The fix: a second channel, into the step's PROCESS ENVIRONMENT. A host hands the walk the values a step's environment should carry (kit.RunnerConfig.StepEnv); the walk merges them into the step's env:, and the command verb applies them as a shell-QUOTED export — so the value arrives as ONE WORD, whatever it contains. The two channels are not equivalent in kind, and that difference is the whole point:

channel the value is the shell sees
text (kit.ExpandOpVars) SOURCE — it is parsed as shell text $(…) runs, ; splits, a space splits
environment (this change) DATA — it is one word one word, whatever it contains

The consumer is already shipped; this change is the missing producer. The command plugin's verb reads the step's env: and renders it as shell exports — the version charly builds against is v0.2026277.738, and its source is pasted in How tested below. The kit fills op.Env; the verb exports it. One implementation each, and the consumer needs no change for the channel to work.

The seam is optional, and a host that does not implement it changes nothing. kit.StepEnvExporter is a separate OPTIONAL interface, not a method on the public kit.PlanContext — that interface's implementors live outside this repository, so a new method on it would break every consumer of the kit. A host that does not implement the seam exports nothing, and every verdict is unchanged.

A name the shell cannot export is disclosed, not dropped. export HOST_PORT:6379=… is a shell SYNTAX ERROR that would fail the whole step, so such a name is not exported — and the name is named in the step's message, because a value that vanishes silently reads exactly like a host that never supplied it. That is a NOTE, never a verdict: the step itself still runs.

The diff is four files — kit/stepenv.go (the channel), kit/planrun.go (the walk merges it), kit/runner.go (the host's seam), kit/stepenv_test.go (the coverage). Head 9070ab4d9af6980d422a466f2cf2b9d9db2939c5 — 4 files changed, 302 insertions(+), 0 deletions(-).

How tested

The changed path, executed live in a real process. The driver lives OUTSIDE this repository and imports the sdk through a replace, so it exercises the committed tree and not a copy of it:

$ cat /tmp/umbrella-leg/live-stepenv/go.mod
module live-stepenv

go 1.26.8

require (
	github.com/opencharly/sdk v0.0.0
	github.com/opencharly/spec v0.2026296.1036
)

replace github.com/opencharly/sdk => /home/atrawog/Sync/Atrapub/a/claude/opencharly/.worktrees/pin-1059/sdk

Its verb is the command plugin's SHAPE: it renders the step's env: as shell exports exactly as the shipped verb does — sorted keys, export NAME=<spec/shellquote.ShellQuote(value)> — and runs the step's command in a REAL sh -c process. The value under test carries shell metacharacters, and the two arms differ only in which channel delivers it:

$ cd /tmp/umbrella-leg/live-stepenv
$ go run .
env-channel    verdict=pass
env-channel    child stdout   = "$(touch /tmp/live-stepenv3333896352/marker) a b;c * ${HOME}"
env-channel    marker created = false
text-channel   verdict=pass
text-channel   child stdout   = " a b;c * /home/atrawog"
text-channel   marker created = true
LIVE_PROOF_OK: the value arrived as DATA on the data channel, and as SOURCE on the text channel

Both arms ran in the same process, in the same run, with the same value. On the data channel the child received the value VERBATIM and the $(…) inside it never ran. On the text channel — the kit's existing expansion, unchanged by this PR — the shell re-parsed the substituted value, the $(touch …) EXECUTED (the marker exists), and what the command printed was the substitution's output with ${HOME} expanded. That is the defect the new channel removes, shown next to its removal.

The same live proof against the tree with the channel removed — it fails loudly, so the proof discriminates:

$ cd /home/atrawog/Sync/Atrapub/a/claude/opencharly/.worktrees/pin-1059/sdk
$ python3 - <<'PY'
p = "kit/planrun.go"
s = open(p).read()
old = """	if ex, ok := pc.(StepEnvExporter); ok {
		expanded.Env, stepEnvRejected = MergeStepEnv(expanded.Env, ex.StepEnv())
	}"""
new = """	if ex, ok := pc.(StepEnvExporter); ok {
		_ = ex
	}"""
assert s.count(old) == 1, "the mutation anchor must appear exactly once"
open(p, "w").write(s.replace(old, new))
print("MUTATION APPLIED")
PY
MUTATION APPLIED
$ cd /tmp/umbrella-leg/live-stepenv && go run .
env-channel    verdict=pass
env-channel    child stdout   = ""
env-channel    marker created = false
env-channel    the value did not arrive intact
LIVE_PROOF_FAILED: env channel
exit status 1
LIVE_MUTANT_RC=1
$ cd /home/atrawog/Sync/Atrapub/a/claude/opencharly/.worktrees/pin-1059/sdk && git checkout -- kit/planrun.go
RESTORE_RC=0
$ cd /tmp/umbrella-leg/live-stepenv && go run .
env-channel    verdict=pass
env-channel    child stdout   = "$(touch /tmp/live-stepenv1875817729/marker) a b;c * ${HOME}"
env-channel    marker created = false
text-channel   verdict=pass
text-channel   child stdout   = " a b;c * /home/atrawog"
text-channel   marker created = true
LIVE_PROOF_OK: the value arrived as DATA on the data channel, and as SOURCE on the text channel
LIVE_RESTORED_RC=0

The coverage fails without the change. The same mutation, against the unit suite — the three arms that assert the delivery go red, and the tree is restored afterwards:

$ cd /home/atrawog/Sync/Atrapub/a/claude/opencharly/.worktrees/pin-1059/sdk
$ go test -count=1 ./...
ok  	github.com/opencharly/sdk	0.103s
ok  	github.com/opencharly/sdk/agentkit	0.594s
ok  	github.com/opencharly/sdk/artifactkit	0.010s
ok  	github.com/opencharly/sdk/buildcache	0.772s
ok  	github.com/opencharly/sdk/buildkit	0.009s
ok  	github.com/opencharly/sdk/buildkitdrive	0.007s
ok  	github.com/opencharly/sdk/candywalk	0.010s
ok  	github.com/opencharly/sdk/charlylib	0.012s
ok  	github.com/opencharly/sdk/checkkit	0.007s
ok  	github.com/opencharly/sdk/cmd/charly-lib-gen	0.004s
ok  	github.com/opencharly/sdk/deploykit	7.082s
ok  	github.com/opencharly/sdk/enginekit	0.005s
?   	github.com/opencharly/sdk/internal/spectest	[no test files]
ok  	github.com/opencharly/sdk/kit	12.879s
ok  	github.com/opencharly/sdk/llmkit	2.694s
ok  	github.com/opencharly/sdk/loaderkit	0.906s
ok  	github.com/opencharly/sdk/packagekit	0.017s
ok  	github.com/opencharly/sdk/storekit	0.561s
ok  	github.com/opencharly/sdk/vmshared	0.116s
ok  	github.com/opencharly/sdk/workflowkit	0.014s
FRESH_TEST_RC=0
$ python3 - <<'PY'
p = "kit/planrun.go"
s = open(p).read()
old = """	if ex, ok := pc.(StepEnvExporter); ok {
		expanded.Env, stepEnvRejected = MergeStepEnv(expanded.Env, ex.StepEnv())
	}"""
new = """	if ex, ok := pc.(StepEnvExporter); ok {
		_ = ex
	}"""
assert s.count(old) == 1, "the mutation anchor must appear exactly once"
open(p, "w").write(s.replace(old, new))
print("MUTATION APPLIED")
PY
MUTATION APPLIED
MUTATION_APPLIED_RC=0
$ go test -count=1 ./kit/ -run 'StepEnv|MergeStepEnv'
--- FAIL: TestRunOne_StepEnvReachesTheStepAsData (0.00s)
--- FAIL: TestRunOne_StepEnvReachesALowercaseName (0.00s)
--- FAIL: TestRunOne_StepEnvRejectsANonIdentifierNameAndSaysSo (0.00s)
MUTANT_RC=1
$ git checkout -- kit/planrun.go
RESTORE_RC=0
$ go test -count=1 ./kit/ -run 'StepEnv|MergeStepEnv'
ok  	github.com/opencharly/sdk/kit	0.003s
RESTORED_RC=0

The module gate, on this committed tree (9070ab4d9af6980d422a466f2cf2b9d9db2939c5) — this repo's gate set is its own AGENTS.md and its CI workflow (gofmt, go vet, golangci-lint v2.13.2, go test, and the cross-compile matrix), and every arm ran here with zero failures and zero warnings:

$ git rev-parse HEAD
9070ab4d9af6980d422a466f2cf2b9d9db2939c5
$ go build ./...
build_RC=0
$ go test ./... -count=1
FRESH_TEST_RC=0
$ test -z "$(gofmt -l .)"
gofmt_RC=0
$ go vet ./...
vet_RC=0
$ GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build ./...
cross-amd64_RC=0
$ GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build ./...
cross-arm64_RC=0
$ GOOS=linux GOARCH=arm CGO_ENABLED=0 go build ./...
cross-arm_RC=0
$ GOOS=linux GOARCH=386 CGO_ENABLED=0 go build ./...
cross-386_RC=0
$ GOTOOLCHAIN=go1.26.8 golangci-lint run --timeout 10m
0 issues.
lint_RC=0
$ GOTOOLCHAIN=go1.26.8 golangci-lint fmt --diff
FMT_DIFF_RC=0

golangci-lint runs here under the toolchain the repo declares (go 1.26.8), which is the same toolchain CI builds from go.mod; the host's own default Go is newer and cannot decode this module's export data, so the toolchain is pinned for the run rather than left to the host's default. That host limitation is itself filed, on #466.

The consumer, as shipped. The command plugin's verb — the version charly builds against, github.com/opencharly/plugin-command/candy/plugin-command v0.2026277.738 — already reads the step's env: and renders it as shell exports, quoting every value:

$ sed -n '79,82p' "$(go env GOMODCACHE)"/github.com/opencharly/plugin-command/candy/[email protected]/plugin.go
	cmd := in.Command
	if len(op.Env) > 0 {
		cmd = envExports(op.Env) + cmd
	}
$ sed -n '192,205p' "$(go env GOMODCACHE)"/github.com/opencharly/plugin-command/candy/[email protected]/plugin.go
func envExports(env map[string]string) string {
	if len(env) == 0 {
		return ""
	}
	keys := make([]string, 0, len(env))
	for k := range env {
		keys = append(keys, k)
	}
	slices.Sort(keys)
	var b strings.Builder
	for _, k := range keys {
		fmt.Fprintf(&b, "export %s=%s\n", k, shellquote.ShellQuote(env[k]))
	}
	return b.String()
}

That is the consumer side of the channel, already in production: the kit's job is to put a host's values into op.Env, and the verb's job is to export them. The live driver above reproduces this renderer exactly (same sorted keys, same spec/shellquote.ShellQuote), so the process the proof measured is the process production runs.

Rulebook compliance

Rule How it is honoured
R0 /charly-internals:plugin, /charly-internals:go, /charly-internals:install-plan, /charly-internals:git-workflow, /charly-internals:root-cause-analyzer, /charly-internals:strict-policy and /charly-internals:go-quality were loaded before the change was written, and this repo's own AGENTS.md was read first.
R1 The RCA is on the issue thread (#473): the mechanism (the kit had ONE channel for a host's resolved values, and it was the text channel, so a value that is data became source), the missed control (no test asserted that a value's characters survive the trip to the command, so a value that silently becomes a different program was invisible to the kit's own suite), the blast radius (every step in every plan whose command carries a substituted value), and the root fix (a second channel, into the process environment, with its coverage and its disclosure). Two residuals that this change surfaced are genuinely separable from it — the text channel's closure question and the check engine's own variable vocabulary — and both are FILED in their owning repos, listed under Filed issues below.
R2 One implementation per behaviour. The merge is kit.MergeStepEnv, the disclosure is kit.StepEnvRejectionNote, and the walk calls both. The shell rendering of the env stays where it already lives — the command plugin's envExports — and is NOT copied into the kit: the kit fills op.Env and the verb exports it.
R3 No workaround: no retry, no sleep, no suppression, no special case per verb or per host. The value is delivered by the mechanism the product already had.
R4 The product changed before the prose. The only prose is the godoc on the new exported surface, and no documented command changed.
R5 This change introduces a channel; it migrates nothing and deprecates nothing, so no legacy path is left behind by it. The text channel is untouched BY DESIGN — whether it may still carry a param is an operator decision, filed as #474 — and no name, path, shim or alias was introduced here. The four changed files are the ones named in Summary.
R6 git status was stated before the commit, and it was empty. The work lives in the session worktree at .worktrees/pin-1059/sdk on branch feat/step-env-data-channel, branched off fresh origin/main 306d3d15c28f91d0a88a1bd2913007751f3fa36b. No other session's branch, worktree or file was touched, and no submodule was edited.
R7 The coverage fails without the change — shown twice, once against the unit suite and once against the live driver, and the live driver itself is the changed path executing in a real sh -c process with its output retained. A test that cannot fail would be invalid, and both proofs above go red on the mutation.
R8 N/A — this change crosses no service boundary. The live proof runs a real local process (sh), not a mock of one.
R9 N/A — the sdk is a library; it ships no binary. The live proof is built from this committed tree through a replace, and the tree was clean when it ran.
R10 The change class is this module's gate (build, test, gofmt, vet, golangci-lint v2.13.2, and the cross-compile matrix), run on the committed tree above, with zero failures and zero warnings. The sdk declares no disposable: true bed, so no R10 target is affected by this change.

Change classification

Go source change in the sdk's kit package — the plan walk's delivery of a host's resolved values to a command step. No schema change, no wire-type change, no capability change, no OCI-label change. The new exported surface is four names plus one config field: kit.StepEnvExporter, kit.MergeStepEnv, kit.StepEnvRejectionNote, (*kit.Runner).StepEnv, and kit.RunnerConfig.StepEnv. kit.PlanContext is untouched, so no implementor outside this repository has to change.

The gate that owns this class is the module gate, run on the committed tree above.

On the attribution tier. fully tested and validated: the change-class gate passed on the final tree with zero failures and zero warnings — including golangci-lint v2.13.2 under the toolchain the repo declares — and the changed path executed live in a real process, with the output retained, in both the holding and the failing direction.

The consumer leg is not in this diff. opencharly/plugin-task#34 owns the task verb's side: it builds the task's merged env and hands it to the runner. This change gives that verb a channel to hand it over; the verb's own leg is a separate PR in that repo, and it may not require a change to the sdk's own API.

Filed issues

Both are genuinely separable from this change: the tree is correct and this PR's claim is true without them, and neither is touched by the diff.

Closes #473.

Agent: charly
Assisted-by: Claude Code minimax/minimax-m3.1-flash:cloud (fully tested and validated)

…DATA

The kit has one channel for a host's resolved values: ExpandOpVars
substitutes them into a step's command TEXT, and the shell then PARSES
that text. A value that is data therefore becomes source — a `$(…)` inside
a value EXECUTES — and a value carrying a space arrives as two words.

The environment is the other channel. A value delivered as an environment
variable is data, because the shell never re-parses the result of an
expansion: the command verb applies the env as a shell-QUOTED export, so
the value arrives as one word whatever it contains.

The seam is an OPTIONAL interface, not a new method on the public
PlanContext — that interface's implementors live outside this repository,
so a new method would break every consumer of the kit. A host that does
not implement it keeps exactly today's behaviour: nothing is exported, no
verdict changes.

The step's own `env:` wins on a name collision (the author speaking last
about their own step), the map is COPIED rather than merged in place (the
walk's `expanded := *c` shares the Op's Env map, so an in-place merge
would leak one run's values into the next), and a name the shell cannot
export is NOT exported but DISCLOSED — a value that vanishes silently
reads exactly like a host that never supplied it.

Assisted-by: Claude Code minimax/minimax-m3.1-flash:cloud (fully tested and validated)
@github-actions

Copy link
Copy Markdown

Review — PASS

What the diff does

The PR adds a second, non-textual delivery channel for a host's resolved values:

  • kit/stepenv.go (new) defines the optional StepEnvExporter seam, MergeStepEnv (copy-on-write merge with "step's own env: wins", invalid-identifier rejection, sorted rejected list), and StepEnvRejectionNote.
  • kit/planrun.go calls the seam after ExpandOpVars (so the two channels stay distinct: text expansion still uses EffectiveEnv, never StepEnv), assigns the merged copy back onto the struct-copied expanded, and appends the disclosure note to result.Message without touching the verdict.
  • kit/runner.go adds RunnerConfig.StepEnv, threads it through NewRunner, and exposes (*Runner).StepEnv() with a compile-time var _ StepEnvExporter = (*Runner)(nil) assertion.
  • kit/stepenv_test.go covers delivery-intact, lowercase name, non-mutation of the plan op, step-env-wins, invalid-name disclosure (still StatusPass), no-seam no-op, and the merge contract directly.

Checks applied

  • Correctness. MergeStepEnv correctly copies before mutating (addressing the shared Env map on expanded := *c), lets the step's own key win, validates names against ^[A-Za-z_][A-Za-z0-9_]*$, and returns sorted rejections. The walk wiring matches the signatures. The disclosure path is appended only after the step runs, and it never changes Status — matching the "NOTE, never a verdict" claim.
  • Honesty of the body. The stated "4 files changed, 302 insertions(+), 0 deletions(-)" reconciles exactly with the diffs (26 + 21 + 85 + 170 = 302, zero deletions). The head SHA, file list, and new exported surface (StepEnvExporter, MergeStepEnv, StepEnvRejectionNote, (*Runner).StepEnv, RunnerConfig.StepEnv) all match the diff. PlanContext is genuinely untouched.
  • Tests. The three delivery/disclosure tests genuinely fail without the merge (verified against the body's mutation transcript, which is internally consistent); the non-mutation, no-override, and no-seam tests are correctly regression guards. TestMergeStepEnv exercises the copy/reject/priority contract directly.
  • Security. The change deliberately routes values through the process environment so a consumer's ShellQuote keeps them as one word rather than shell source; invalid export names are dropped instead of producing a shell syntax error. No secrets, no injection surface introduced on the kit side.
  • Scope & cleanliness. Minimal, single-responsibility additions; no legacy path removed or duplicated; no shim/alias. Runner implements the optional seam behind a compile-time assertion so a shape change can't silently no-op.
  • Comments. None were provided, so no maintainer sign-off exists; the change is evaluated on its own evidence, which it carries.

Non-blocking observations

  • The disclosure note is only appended on the main RunWithEventually return path; if RunOne takes an earlier failure return (e.g. unresolved vars), a rejected name is not surfaced. That path already fails the step, so it does not contradict the stated contract ("the step itself still runs").
  • The "arrives as one word" guarantee ultimately depends on the consumer verb's ShellQuote; the PR correctly attributes that leg to the already-shipped command plugin rather than claiming the kit enforces it.

No blocking findings.

Verdict: PASS


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

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) October 24, 2026 18:50
@github-actions
github-actions Bot merged commit 38ac709 into main Oct 24, 2026
8 checks passed
charly-auto-merge Bot added a commit that referenced this pull request Oct 24, 2026
github-actions Bot pushed a commit to opencharly/plugin-task that referenced this pull request Oct 24, 2026
…nt as DATA (#47)

A task's `params:` are substituted into a plan step's TEXT, and the shell then
PARSES that text. A value that is DATA therefore becomes SOURCE: a `$(…)` inside
a value EXECUTES. The text channel cannot fix that — the value has to arrive by a
route the shell does not re-parse.

The environment is that route. A value delivered as an environment variable is
DATA, because the shell never re-parses the result of an expansion, and the
command verb applies the step's env as a shell-QUOTED export, so the value
arrives as ONE word whatever it contains. This change opens that channel: the
task's RESOLVED values — its `vars`, its `env`, its resolved `params` and
`TASK_DIR` — are handed to the SDK as `kit.RunnerConfig.StepEnv`, and the SDK's
`kit.MergeStepEnv` merges them into every step's environment.

Three rules bound the channel, and each is a rule the SDK's own merge already
owns, so the plugin adds no second implementation of any of them:

  - the step's OWN `env:` WINS a name collision — the author spoke last about
    their own step, and the task's value is a default;
  - a name the shell cannot export (outside `[A-Za-z_][A-Za-z0-9_]*`) is
    REJECTED and RETURNED, and the SDK renders it as a NOTE on the step's
    message ("not exported (not a valid shell identifier): …") — disclosed,
    never dropped silently;
  - a piped stdin is not a resolved value, so it is NOT exported. The map is
    CLONED before `captureStdin` mutates it, because the command verb renders an
    exported value into the command TEXT, and a NUL byte (a piped binary stream
    carries one) would make the exec un-runnable ("fork/exec /usr/bin/sh:
    invalid argument"). The stream keeps its own channel: `TASK_STDIN` /
    `TASK_STDIN_FILE` stay reachable through the text expansion they have
    always had.

A lowercase param is a second, independent win: the expander's grammar is
uppercase-only, so a lowercase param was previously unreachable from a step at
all. The environment is what makes it reachable BY NAME.

The evidence is a live arm, not a unit test alone. `scripts/gate-task.sh` grew
arm 1c: a task whose param carries `$(touch <marker>)` runs against a real
charly binary, and the arm asserts BOTH outcomes — the value arrives VERBATIM
in the step's environment, AND the marker file does not exist. The silent
outcome is the failure this channel exists to remove, so it is asserted too.
`candy/plugin-task/stepenv_test.go` covers the same contract at unit level: the
export, the collision rule, the disclosure of a non-exportable name, and the
stdin exclusion.

The pin bump also made ONE line of this repo's coherence control stale: its header
comment read "Measured at charly v2026.267.2313 (pinning sdk v0.2026266.1111 against
this module's v0.2026276.1822)", and "this module's v0.2026276.1822" named the pin
this module no longer carries. The measurement is history and stays; the false
present-tense claim does not, so the clause now reads "against a module pinning sdk
v0.2026276.1822 - the pin this module carried at the time of that measurement". The
control's self-test fixtures keep their versions on purpose: they are SYNTHETIC
(a leading pair, a lagging pair, an absent pin) and do not read this module's live
pins, so they still prove the comparator can pass and can fail.

Producer-first: the DATA channel is an SDK capability (`kit.StepEnvExporter`,
`kit.RunnerConfig.StepEnv`, `kit.MergeStepEnv`, `opencharly/sdk#475`, released as
`sdk v0.2026297.1851`), and this module's `require` therefore rises to it. This
repo's own coherence control (`scripts/check-coherence.sh`, run by the `coherence`
CI job on every PR) asserts that charly's `sdk`/`spec` pins LEAD this module's
requires, so the producer leg had to land first — and it has:
`opencharly/charly#1062` merged as `87f6302456f9c821877e719cbe90615368cd85bc`
with the tag `v2026.297.1957`, and charly's `main` now pins
`sdk v0.2026297.1851` / `spec v0.2026296.1036`. The live gate below was run
against that branch (`CHARLY_REF=feat/sdk-pin-1851`) and against `main`, which is
the configuration that ships.

The tier is `analysed on a live system`, not `fully tested and validated`: this
repo's own gate (build, test, vet, gofmt, the linter, `charly box validate`) and
its live gate (a real charly binary with this candy compiled in, driving the
changed path) both ran on the committed tree, and the changed path ran live —
but the FULL assembled bed is charly's, and by the producer-first order it
cannot run on this head until this change carries a tag that charly can pin.

Assisted-by: Claude Code minimax/minimax-m3.1-flash:cloud (analysed on a live system)
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.

the plan walk has no channel that carries a resolved value into a command step's process environment as DATA

1 participant