~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
#!/usr/bin/env python3
"""Validate workflows with pinned actionlint plus current GitHub syntax.
Until actionlint understands `$/`, normalize job-level call references and
step-level local action references to `./` in stdin only. Keeping the
original filename lets actionlint load the callee's inputs, secrets and
outputs, and the local action's inputs, from the repository. No diagnostics
are suppressed and no workflow files are rewritten.
The pinned actionlint also predates GitHub's `concurrency.queue` setting.
Validate its allowed values and blank that key in stdin, keeping the line
number while actionlint checks the remainder of the workflow. This covers the
workflow-level and job-level `concurrency` mappings. GitHub rejects
`queue: max` together with `cancel-in-progress: true`, so `queue: max` is
accepted only with `cancel-in-progress: false` or no such key; an expression
cannot be proven false and is rejected. A duplicated `queue` key in one
mapping is rejected, as actionlint rejects every other duplicated key.
"""
import argparse
import json
import re
import subprocess
import sys
from pathlib import Path
import yaml
from yaml.nodes import MappingNode, ScalarNode, SequenceNode
from yaml.tokens import ScalarToken
# The exact text a blanked `queue` pair may have: a plain or quoted key, one
# colon, and an optional anchor plus a plain or quoted single/max value.
QUEUE_PAIR = re.compile(
r"""(["']?)queue\1[ \t]*:[ \t]*(?:&[^\s,\[\]{}]+[ \t]+)?(["']?)(?:single|max)\2"""
)
def mapping_values(node, key):
if isinstance(node, MappingNode):
for name, value in node.value:
if isinstance(name, ScalarNode) and name.value == key:
yield value
def queue_edits(document, source: str) -> list:
"""Validate concurrency.queue and return edits that blank it."""
edits = []
concurrencies = list(mapping_values(document, "concurrency"))
for jobs in mapping_values(document, "jobs"):
for _, job in jobs.value if isinstance(jobs, MappingNode) else ():
concurrencies.extend(mapping_values(job, "concurrency"))
for concurrency in concurrencies:
if not isinstance(concurrency, MappingNode):
continue
if len(list(mapping_values(concurrency, "queue"))) > 1:
# actionlint rejects any other duplicated key; blanking every
# copy would hide a workflow GitHub rejects.
raise ValueError("concurrency.queue key is duplicated")
for key, value in concurrency.value:
if not isinstance(key, ScalarNode) or key.value != "queue":
continue
if not isinstance(value, ScalarNode) or value.value not in {
"single",
"max",
}:
raise ValueError("concurrency.queue must be single or max")
if value.value == "max" and any(
not isinstance(cancel, ScalarNode) or cancel.value != "false"
for cancel in mapping_values(concurrency, "cancel-in-progress")
):
# GitHub documents this pair as a workflow validation error.
# An expression cannot be proven false, so it is rejected too.
raise ValueError(
"concurrency.queue max requires cancel-in-progress: false"
" or no cancel-in-progress"
)
start, end = key.start_mark.index, value.end_mark.index
if end <= start:
# An alias value points back at its earlier anchor.
raise ValueError("concurrency.queue must not be an alias")
if "\n" in source[start:end]:
raise ValueError(
"concurrency.queue must be a scalar on one line"
)
if not QUEUE_PAIR.fullmatch(source[start:end]):
# An aliased or anchored key reports the position of its
# anchor, so the span may reach back over unrelated text.
# Blank only a span that is exactly the queue pair.
raise ValueError(
"concurrency.queue key must be a plain, unanchored"
" scalar and not an alias"
)
edits.append((start, end, " " * (end - start)))
return edits
def checked_edits(source: str, edits) -> str:
"""Apply edits and fail closed if the result is no longer valid YAML."""
result = apply_edits(source, edits)
if edits:
try:
yaml.compose(result, Loader=yaml.SafeLoader)
except yaml.YAMLError as exc:
# Blanking a pair in a flow mapping can leave an empty entry.
raise ValueError(
"blanking concurrency.queue leaves invalid YAML; put queue"
" last in a flow mapping or use a block mapping"
) from exc
return result
def apply_edits(source: str, edits) -> str:
"""Apply position-ordered, de-duplicated edits from the end backwards."""
# An aliased mapping or job is reached more than once and yields the
# same edit each time; identical edits count as one.
edits = sorted(set(edits), key=lambda edit: edit[:2], reverse=True)
for (later_start, _, _), (_, end, _) in zip(edits, edits[1:]):
if end > later_start:
raise RuntimeError("workflow edits must not overlap")
for start, end, value in edits:
source = source[:start] + value + source[end:]
return source
def strip_concurrency_queue(source: str) -> str:
"""Blank only concurrency.queue, for scanners that predate it."""
document = yaml.compose(source, Loader=yaml.SafeLoader)
return checked_edits(source, queue_edits(document, source))
def normalize_workflow_calls(source: str) -> str:
"""Adapt supported new syntax for the pinned linter in memory only."""
document = yaml.compose(source, Loader=yaml.SafeLoader)
ends = set()
edits = queue_edits(document, source)
for jobs in mapping_values(document, "jobs"):
if not isinstance(jobs, MappingNode):
continue
for _, job in jobs.value:
uses_nodes = list(mapping_values(job, "uses"))
for steps in mapping_values(job, "steps"):
if isinstance(steps, SequenceNode):
for step in steps.value:
uses_nodes.extend(mapping_values(step, "uses"))
for uses in uses_nodes:
if isinstance(uses, ScalarNode) and uses.value.startswith("$/"):
ends.add(uses.end_mark.index)
# Scalar tokens exclude any anchor before the value. Their end marks
# also identify aliased uses nodes, so a shared scalar is replaced once.
for token in yaml.scan(source):
if (
not isinstance(token, ScalarToken)
or token.end_mark.index not in ends
):
continue
start, end = token.start_mark.index, token.end_mark.index
raw = source[start:end]
if raw.startswith("$/"):
edits.append((start, start + 1, "."))
elif raw.startswith(("'$/", '"$/')):
edits.append((start + 1, start + 2, "."))
else:
# Escaped quotes and block scalars need re-encoding. JSON strings
# are valid YAML scalars; blank lines preserve following locations.
value = json.dumps("./" + token.value[2:])
edits.append((start, end, value + "\n" * raw.count("\n")))
return checked_edits(source, edits)
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--actionlint-arg", action="append", default=[])
parser.add_argument("files", nargs="+")
args = parser.parse_args()
failed = False
for filename in args.files:
try:
source = Path(filename).read_text(encoding="utf-8")
try:
source = normalize_workflow_calls(source)
except yaml.YAMLError:
# Let actionlint report malformed YAML using its normal
# diagnostics. A parse failure must never skip validation.
pass
except (ValueError, RuntimeError) as exc:
print(f"{filename}: {exc}", file=sys.stderr)
failed = True
continue
result = subprocess.run(
[
"actionlint",
*args.actionlint_arg,
"-stdin-filename",
filename,
"-",
],
input=source,
text=True,
check=False,
)
failed |= result.returncode != 0
except (OSError, UnicodeError) as exc:
print(f"{filename}: {exc}", file=sys.stderr)
failed = True
return int(failed)
if __name__ == "__main__":
sys.exit(main())