Skip to content

feat: xcind-run — bins and scripts runner - #94

Merged
simensen merged 16 commits into
mainfrom
xcind-run-bins-and-scripts-runner
Sep 4, 2026
Merged

simensen merged 16 commits into
mainfrom
xcind-run-bins-and-scripts-runner

Conversation

@simensen

@simensen simensen commented Sep 2, 2026

Copy link
Copy Markdown
Member

Summary

XCIND_TOOLS was metadata only: nothing executed a tool. This PR adds the missing runner, bin/xcind-run, and a second declarative map, XCIND_SCRIPTS, so per-project commands move out of personal x-* alias files and into the shared .xcind.sh. The data model is declarative strings, so it ports to Scind (scind run) later.

  • Rename and harden bins (26b4e9d): XCIND_TOOLS → XCIND_BINS, JSON key tools → bins, path= → cmd= (default: the bin's name), new use=/desc= validation, duplicate names error instead of first-wins. No BC shim: the only planned consumer (JetBrains plugin) does not exist yet.
  • Course correction (a9d5d8f): the first pass had also implemented a scripts grammar (name:service;@ref bin args) that contradicted the settled design. That model, its tests, and a broken premature completion function are removed.
  • Scripts model (bb1d3bf): XCIND_SCRIPTS entries are name: followed by steps, one per line. The first # comment is the description; a leading - ignores that step's failure. A pure-bash tokenizer (no eval) splits step text and flags bare $@/"$@" for arg splicing. Bins and scripts share one namespace.
  • Dispatcher (0613f56): xcind-run <name> [args…] with -T/--no-tty and --list [--names]. Step kinds: @<bin>, @<script> (cycles fail with the call path), @exec, @run, @compose, and host steps via bash -c — the only place expansion happens. Steps stop at the first failure with its exit status. The keywords also work as the CLI name (xcind-run @exec app …). Runs the same pipeline as xcind-compose, including EXECUTE hooks. Registered in all seven install/packaging manifests.
  • Shell surface (df2a331): --init-shell [--prefix] emits x-<name>() wrapper functions; bash and zsh completions; full docs pass (new docs/guides/bins-and-scripts.md, CLI/configuration references, specs, glossary).

Test plan

  • make check: 1036 + 756 + 189 + 192 assertions, zero failures, lint clean. Dispatch is covered end to end through a docker PATH shim; completion tests cover both shells, including live name completion through the real pipeline.
  • contrib/test-all --bash-versions: PASS on bash 3.2, 4.0, 4.4, 5.0, 5.1, 5, latest.
  • contrib/check-file-manifest: in sync.
  • Live smoke tests in examples/workspaceless/acmeapps against real docker: xcind-config --json | jq '.bins, .scripts', resolve bins.npm.cmd, --list, --list --names, @compose config --services, eval "$(xcind-run --init-shell)".

Out of scope (recorded follow-ups)

workdir= (host cwd → container workdir), use=auto, service-name validation, workspace-scoped xcind-run -a app, and the Scind forward-port.

…tion

Add bin parsing library (xcind-run-lib.bash) that validates entries,
rejects duplicates, defaults cmd to name, and supports desc/use keys.
Replace __xcind-resolve-tools with __xcind-runner-bins-json.

Update JSON contract: tools → bins, add scripts placeholder.
Update SHA computation for XCIND_BINS.
Update resolve keys, completions, tests, and example config.
The first pass implemented XCIND_SCRIPTS as name:service;@ref bin args,
which contradicts the settled design (newline-separated steps, step
kinds @exec/@run/@compose/@bin/@script, host steps, '#' comment desc,
'-' ignore prefix, $@ splicing, pure-bash tokenizer). Remove the parser,
its tests, and the premature xcind-run completions (the zsh function
recursively called itself instead of the binary).

Keep the XCIND_SCRIPTS=() default and its SHA fold; emit scripts: {} as
a JSON-contract placeholder until the real parser lands.

Also harden the kept bins code:
- guard bins_json resolution with || return 1 (repo convention)
- unset XCIND_SCRIPTS in reset_xcind_state
- make the bins empty-array guard safe under set -u on bash 3.2
XCIND_SCRIPTS entries are `name:` followed by steps, one per line (a
single-line form is allowed). Lines are trimmed, blanks skipped; the
first '#' comment is the description; a leading '-' marks a step whose
failure is ignored (kept in the stored step); a bare '-' is an error.
Bins and scripts share one namespace: a name in both fails resolution.

Add __xcind-runner-split, a pure-bash tokenizer with no eval (chosen so
Xcind matches what a Go shellwords library will do in Scind): states
unquoted/single/double, backslash escapes, no expansion, and $@ / "$@"
flagged for arg splicing. Unterminated quotes return 64.

The JSON contract's scripts key now carries {steps: [raw steps], desc?}
and both arrays already fold into the cache SHA. Example app gains a
small XCIND_SCRIPTS.
bin/xcind-run runs declared bins and scripts inside the app's Compose
services. Runner flags go before the name: -T/--no-tty forces -T (it is
also automatic when stdin or stdout is not a terminal), and --list
[--names] prints the runnable names (a leading '_' hides an entry but
it stays runnable).

Bins exec (or run --rm) their cmd in their service and always append
the caller's args. Script steps run in order and stop at the first
failure with its exit status; a step's leading '-' ignores its failure.
The first word picks the step kind: @exec/@run/@compose keywords,
@<bin>/@<script> references (cycles are caught with a call stack), and
anything else runs on the host via bash -c — the only place expansion
happens. Args splice at bare $@ tokens; a one-step script with no $@
appends them; a multi-step script with no $@ rejects args with 64.
The keywords also work as the CLI name (xcind-run @exec app …).

The bins parser now fills parallel arrays (parse/emit split), the
cross-namespace check moved into __xcind-runner-load, and xcind-run
joins xcind-compose as an EXECUTE-hook consumer. Registered in all
seven install/packaging manifests; dispatch is covered end to end by
a docker PATH shim in the test suite.
xcind-run --init-shell [--prefix PREFIX] prints one wrapper function per
visible bin and script — x-<name>() { xcind-run <name> "$@"; } — for
eval in a shell rc (default prefix x-). Hidden (leading _) names are
skipped, like --list.

Add native xcind-run completions for bash and zsh: flags, then bin and
script names via `xcind-run --list --names` for the first non-flag word,
and nothing after a name. Completion tests cover both shells, including
live name completion through the real pipeline.

Docs: new docs/guides/bins-and-scripts.md (grammar, step kinds, $@, -,
_, --init-shell, alias migration); xcind-run sections in both CLI
references; XCIND_BINS/XCIND_SCRIPTS in both configuration references
and the app schema; SHA-input and EXECUTE-consumer spec updates;
glossary Tool → Bin plus Script and Step.
The variable was set on every source but never referenced, spawning a
subshell needlessly on every xcind command invocation.
Commands that never touch bins/scripts parsing (xcind-compose,
xcind-proxy) no longer pay the cost of sourcing the 840-line run-lib.
A new __xcind-ensure-run-lib guard loads it on first use.
Replace the nested O(n×m) loop with a comma-delimited seen-string and
case-glob scan, matching the pattern used in the per-array parsers.
Add a __XCIND_RUNNER_LOADED sentinel so repeated calls (e.g. from both
bin/xcind-run and __xcind-resolve-json) skip the parse+validate work.
reset_xcind_state clears the sentinel for test isolation.
Reject prefix values containing special characters (semicolons, spaces,
etc.) that would produce broken shell function definitions.
Add a default case so an unexpected @-keyword returns 1 instead of
silently succeeding with no docker invocation.
- Fix stale zsh completion descriptions for bins/scripts
- Hoist metadata-loop locals out of the XCIND_BINS parse loop
- Document --list/--names/--init-shell exclusivity in --help
- Clear runner arrays in reset_xcind_state so dispatch tests cannot leak
- Add test/run-tests.sh: runs the four test files as background
  processes with per-file buffered logs replayed in fixed order;
  make test now uses it. Wall time drops from ~40s to ~22s,
  bounded by test-xcind.sh.
- Replace three sleep-1 mtime waits in test-xcind-proxy.sh with
  touch -t backdating; a wrongful rewrite stamps "now", so the
  mtime assertions keep their power.
- Shim timeout(1) in the two sections that /dev/tcp-probe free
  ports: on WSL2 a connect to an unbound loopback port hangs until
  the 1s cap instead of being refused. The real-listener busy-port
  probe stays real. Proxy file drops from ~15.5s to ~10.2s.
- test/run-tests.sh now accepts an optional file list (basename or
  test/-prefixed), failing fast on an unknown name, so CI jobs can
  run OS-gated subsets through the same runner as make test.
- tests.yml: add test/run-tests.sh to the shellcheck list; run the
  test job through the runner (ubuntu: all four suites, macos: all
  but the proxy suite, gates unchanged); collapse the kislyuk-yq
  job's three steps into one runner call; run the bash-version
  suites in a single container instead of three.
A hand-written `x-config() { xcind-config "$@"; }` loses completion:
nothing is registered for `x-config`, so it falls back to filenames.

`xcind-shell-aliases [PREFIX]` defines one function per xcind command and
registers that command's completion function against the new name, so a
short name completes exactly like the command it wraps. Default prefix
`x-`, validated against [a-zA-Z0-9_-] with the same wording as
`xcind-run --prefix`.

Lives in both completion scripts because the command-to-function mapping
already exists there, and because registering completion requires running
in the caller's shell — there is nothing to eval.

Install-scoped, unlike `xcind-run --init-shell`: the command list comes
from the completion script rather than an app's .xcind.sh, so one call per
shell covers every directory and no app resolution runs. Excludes
xcind-prompt, which draws prompt segments and has no completion.

Re-registration is sound because no completion function reads the invoked
command name. A test asserts the wrapper map and the complete -F / compdef
registrations agree, so the two cannot drift.

Also adds xcind-run to the completion lists in both CLI references, which
had omitted it.
The "no '=' in this pair" check compared the extracted key to the
extracted value. For a pair with no '=', both are the whole pair, so the
test worked — but it also fired whenever the value happened to equal the
key. `cmd=cmd` and `desc=desc` were rejected as unknown attributes, and
`use=use` reported the wrong error.

Test the pair itself with [[ $pair != *=* ]]. The message interpolates
$pair, which equals $key for a pair with no '=', so the wording for the
legitimate case is unchanged. `use=use` now reports the accurate
"expected exec or run" error.

Bins case 14 captures a parse failure and asserts on it rather than
letting errexit abort the whole suite, so a regression here reports three
failed assertions instead of killing the run.
@simensen
simensen merged commit addd421 into main Sep 4, 2026
17 checks passed
@simensen
simensen deleted the xcind-run-bins-and-scripts-runner branch September 4, 2026 17:38
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