Skip to content

feat(lang): write a tool in .wic - #609

Merged
vjaganat90 merged 7 commits into
PolusAI:masterfrom
vjaganat90:feat/wic-tools
Nov 18, 2026
Merged

vjaganat90 merged 7 commits into
PolusAI:masterfrom
vjaganat90:feat/wic-tools

Conversation

@vjaganat90

@vjaganat90 vjaganat90 commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

What

  • A .wic document whose defining key is command: (a command line with {input} placeholders) or script: (a bash script that reads each input as the variable of its name) is a tool, as steps: makes a workflow. The parser reads it into its own nodes and one function lowers it to the CommandLineTool it means; the builder's .command(), .script() and Output.of() lower through the same function.
  • One kind of tool: a .cwl or .wic tool is read when a step first asks, under the one key discovery gave it, through every door (run:, id:, a Python Step, Workflow.from_wic, a converter). A line owns its CWL places: one the author also wrote is wic058, and script: refuses anything that would add to its command line. A tool key of the wrong shape is wic059. Tools are language 0.1.0; a compile pinned to 0.0.1 that reaches one is wic060.
  • --insert_steps_automatically inserts a converter as an ordinary step, in one pass, by the rule every edge uses. The flag, inference_rules, Inference(insert_steps=True, format_rules=...) and what they compile are unchanged.

Why A tool had to be written as a CWL CommandLineTool by hand; this is the tool half of the .wic language. Inference looks only backwards, so a converter inserted before a step changes nothing decided before it: the fixed-point loop, iteration_limit and wic022 go.

Before, the CWL an author wrote:

class: CommandLineTool
cwlVersion: v1.2
stdout: counts.txt
hints:
- class: DockerRequirement
  dockerPull: debian:bookworm-slim
baseCommand: wc
inputs:
  text:
    type: File
    inputBinding: {position: 1, prefix: -w}
outputs:
  counts: {type: stdout}

After, in Python and in .wic (docs/cookbook/tally_words.py and .wic, which lower to the CWL above):

inputs = Inputs(text=Input(cwl.file))
CommandLineTool('tally_words', inputs, Outputs(counts=Output.stdout())) \
    .docker('debian:bookworm-slim', as_hint=True).stdout('counts.txt').command('wc', '-w', inputs.text)
command: wc -w {text}
inputs: {text: File}
outputs: {counts: stdout}
stdout: counts.txt
docker: debian:bookworm-slim

@vjaganat90
vjaganat90 force-pushed the feat/wic-tools branch 2 times, most recently from d54d2fb to 0801d5b Compare November 17, 2026 20:45

@darkclad darkclad left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed this PR's own commits (f2100fa..0801d5b, on top of #608). lang/tool.py is one lowering, and the builder, inline run:, run: x.wic, discovery by stem and the root-tool path all go through it. The python-script tool lowers to the same command line as before: the driver, types and script at positions 1-3, then --name flags. Discovery cannot shadow a .cwl with a .wic, and workflow steps name .wic with the suffix, so indexing tool documents by stem only reaches names that were unresolvable before. Probing the lowering directly, the script: env bindings (arrays, booleans, nulls), needs: sizes, docker: as a hint and the $(/backslash escaping all come out as the reference says. The head and base tests/core suites on Windows fail the same 64 tests, all environmental (no cwltool, Nextflow or container engine), and the head passes 53 more. mypy is clean on the changed modules. CI is green.

Two small points inline, neither blocking.

Comment thread src/sophios/lang/tool.py Outdated
SCRIPT_FILE: Final = '.script.sh'

_WORD = re.compile(r"""(?:'[^']*'|"[^"]*"|[^\s'"])+""")
_PLACEHOLDER = re.compile(r'\{\{|\}\}|\{([A-Za-z_]\w*)\}|[{}]')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A placeholder name is [A-Za-z_]\w*, but a CWL input id can hold - or .. With inputs: {in-file: File}, command: cat {in-file} is refused as "{ in '{in-file}' starts no placeholder; write {{ for a brace that is text", which points the author at the wrong fix. Either accept the CWL id characters here, or say that the input name cannot be a placeholder (and mention it next to the script: name rule in wic-reference.md §2.4).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 37fe8cc, where I rebuilt the tool reader: a placeholder names any input the tool declares, - and . included, so command: cat {in-file} with inputs: {in-file: File} lowers to cat with in-file at position 1. A {name} that names no input is wic058, and §2.4 says so. The property in tests/core/test_tools.py draws in-file and in.file among the input names.

Comment thread src/sophios/lang/tool.py Outdated
| ({'itemSeparator': ' '} if _kind(port.get('type'))[1] else {})
_listing(cwl, refuse).append({'class': 'File', 'basename': SCRIPT_FILE, 'contents': text})
cwl['baseCommand'] = 'env'
cwl['arguments'] = [*(cwl.get('arguments') or []), {'position': 1, 'valueFrom': 'bash'},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An arguments: entry written beside script: without a position defaults to 0, so it is sorted before bash. With arguments: [hello], the command line is env hello x=... bash .script.sh, and env runs hello. §2.4 tells a command: author to give an argument a position, but says nothing about this for script:, where getting it wrong breaks the invocation rather than reordering words. A wic058 for a position below 3 here, or a line in the script: bullet (arguments for the script are $1... from position 3), would cover it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 37fe8cc: script: owns the whole command line, so arguments: beside it is wic058, with or without a position. So are baseCommand:, an inputBinding anywhere in an input, a record input and an entry at .script.sh. The command line is always env name=value ... bash .script.sh; test_a_script_owns_its_command_line draws those keys and checks the refusal, and §2.4 lists them.

A mapping that says command: or script: is a tool, read as steps: makes a workflow, each word and port with its place. Adds wic058 and wic059, the schema and render of a tool, and lang_version 0.1.0 with wic060 for a compile pinned below it.

@darkclad darkclad left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Both points from the last round hold at aef7ab98. command: cat {in-file} {in.x} lowers to cat with the two inputs at positions 1 and 2. Any arguments: beside script: is wic058, with or without a position, and so is a record input. With the reader rebuilt on the parser's own nodes, the builder, an inline run:, run: x.wic, discovery and a root tool all reach the one command_line_tool lowering, and the python-script tool keeps its command line. I probed the other lines directly: the script: env bindings, a flag before an optional input, docker: and needs: beside their own requirements, shell characters, a type written as an output line, and the list form all come out as §2.4 says. The 0.1.0 language version and the single-pass converter insertion (wic022 retired) are both stated in the spec and in edge-inference.md. The head and base tests/core suites on Windows fail the same 64 tests, all environmental (no cwltool, Nextflow or container engine), and the head passes 15 more. mypy is clean on the 22 changed modules, and CI is green. The only new noise is five Hypothesis "overly large repr" warnings from test_a_document_the_parser_recovered_never_raises, now that its documents include tools.

One lowering writes the places a line owns and refuses any the author also wrote, in one walk. The parser lowers once and keeps the CWL on the tool.
I read a tool file when a step first asks, whether it is a .cwl or a .wic. Discovery files each tool once, so the
doors, Python included, find the same tool, and a .wic root is the workflow of one step that runs it.
I build the tool from the objects that declare it, so Python and .wic lower through the one function. The
python_script adapter builds Port and Word objects too, and the cookbook shows a tool written both ways.
One matching rule, one pass: a converter qualifies when an output fits the input and it reads an output upstream;
the job gives the rest of its inputs. wic022 and iteration_limit go.
I add the tool document to the reference (§2.4), the steps and tool-builder
pages, the spec's versioning, the architecture and the converter rule.
@vjaganat90
vjaganat90 force-pushed the feat/wic-tools branch 3 times, most recently from 681d54c to 58b12d7 Compare November 18, 2026 23:00
I check a document's own rules (step ids, names, edges, scatter, outputs) once, for a parsed and a Python-built
document alike, and Resolve looks nothing up for one Check has not made a CheckedDocument of; lowering and its tests
assume them. The Python-against-its-bundle law is held once, in the pairs, and no test fakes the platform.

@darkclad darkclad left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Since aef7ab98, the lowering commit only trims fixture cases that the script property now draws, and the new commit moves the checks of a document's own nodes (step ids, names, edge producers, scatter: shape, workflow outputs) out of Lower into ir/check.py. They run once per document, after its wic: steps: contributions and before Resolve looks anything up, so a bad step id is no longer reported as a missing process. The rules and messages carry over unchanged, and Lower's dict of edge definitions is safe now that Check refuses a second producer. The preflight change is fine: _docker_processes returns 0 when pgrep is missing, so dropping the win32 guard changes nothing on Windows. The pairs now cover renaming after binding in place of test_canonical_path.py, though not its randomized file and step names. On Windows, tests/core at 603c2194 fails the same 64 tests as its base, all environmental (no cwltool, Nextflow or container engine). mypy is clean on the changed modules, and CI is green.

@vjaganat90
vjaganat90 merged commit 252d37a into PolusAI:master Nov 18, 2026
3 checks passed
@vjaganat90
vjaganat90 deleted the feat/wic-tools branch November 18, 2026 23:30
vjaganat90 pushed a commit that referenced this pull request Nov 24, 2026
launch reads nothing of this machine: run_local places a local run (its
paths, the default output directory, this process's environment) before
the backend launches it, and a runner's own name is the program another
machine runs. prepare is write, which returns the folders the runner's
machine must make, then this machine's check, pulls and folders; needs
says what a check judges. A CWL runner's write leaves the files its
prepare leaves, the job's empty directory in the runner's own form.
outcome reads through read and writes nothing, and the run writes the
summary a runner printed. Local runs are what they were on #609: 39,300
launches, and the command line over the 456 .wic files of docs, examples
and tests, with no difference.
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.

2 participants