Repository navigation
fix(skill): stop pasting agent-supplied values into skill scripts (#4309) - #4344
Deepjyoti-Sarmah wants to merge 16 commits into
Conversation
|
Thanks for the pull request, @Deepjyoti-Sarmah. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify reviewed this change.
Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.
Not checked: tests were not run; formal verification proved 0 of 2 changed function(s) (1 sampled, not proven, 1 not verified).
Formal verification. PR-changed functions: 1/2 verified (0 proven, 1 may-equivalent, 0 distinguished) · 1 not verified (1 vacuous).
Not verified on this run: \_translate\_bash\_block (vacuous: never exercised).
Graphify review — findings
Stops agents from pasting the user's scan path and extraction-spec path into Python source in the skill steps, so a hostile folder name stays data, never code (#4309). Steps now read the root through a new read_scan_root() helper backed by graphify-out/.graphify_root, and the spec path through a quoted-heredoc .graphify_spec_path file that both cache read and cache write consume. read_scan_root() fails with "run Step 1 first" when the marker is missing or empty and rejects a non-directory; the interpreter substitution is also quoted as "$(cat graphify-out/.graphify_python)".
Worth a look
- strip() mangles scan roots with leading/trailing whitespace —
graphify/paths.py:419· Escalate · medium- agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Review partial — this diff was larger than one review pass covers, so later files were not reviewed; some findings may be missing.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 5036 functions depend on the 2101 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
monolith_roundtrip()— 3 callers, 6 callees
Verification — 5036 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 3813 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
368 of 368 test file(s) selected (100%) via static blast radius.
Escalated to a full run for safety — the selection is not trustworthy on its own (see below). CI should run the whole suite.
tests/test_affected_cli.py— impact, full-run-safetytests/test_affected_defines.py— full-run-safetytests/test_affected_member_seed.py— full-run-safetytests/test_agents_platform.py— impact, full-run-safetytests/test_analyze.py— impact, full-run-safetytests/test_anthropic_custom_endpoint.py— full-run-safetytests/test_antigravity_install.py— full-run-safetytests/test_apm_fallback_version.py— full-run-safetytests/test_architecture_doc.py— full-run-safetytests/test_astro_extraction.py— full-run-safetytests/test_astro_import_ids.py— full-run-safetytests/test_atomic_canvas_export.py— impact, full-run-safetytests/test_atomic_version_stamp.py— impact, full-run-safetytests/test_atomic_writes.py— impact, full-run-safetytests/test_backend_env_isolation.py— full-run-safetytests/test_backend_extras.py— full-run-safetytests/test_benchmark.py— impact, full-run-safetytests/test_benchmark_raw_graph.py— impact, full-run-safetytests/test_blade_extractor.py— full-run-safetytests/test_build.py— impact, full-run-safetytests/test_build_located_semantic_identity.py— impact, full-run-safetytests/test_build_merge_dedup_scope.py— impact, full-run-safetytests/test_build_merge_hyperedges_and_prune.py— impact, full-run-safetytests/test_build_merge_shrink_guard.py— impact, full-run-safetytests/test_builtin_global_type_refs.py— full-run-safetytests/test_cache.py— impact, full-run-safetytests/test_cache_stale_import_target.py— impact, full-run-safetytests/test_callflow_html.py— impact, full-run-safetytests/test_cargo_introspect.py— full-run-safetytests/test_cargo_missing_manifest.py— full-run-safetytests/test_carried_hyperedge_remap.py— impact, full-run-safetytests/test_case_sensitive_resolution.py— full-run-safetytests/test_charmap_encoding.py— impact, full-run-safetytests/test_chunking.py— impact, full-run-safetytests/test_cjs_module_extension.py— full-run-safetytests/test_claude_cli_backend.py— full-run-safetytests/test_claude_md.py— full-run-safetytests/test_cli_broken_pipe.py— full-run-safetytests/test_cli_export.py— impact, full-run-safetytests/test_cli_help.py— full-run-safetytests/test_cloud_cta.py— full-run-safetytests/test_cluster.py— impact, full-run-safetytests/test_cluster_ambiguous_scale.py— full-run-safetytests/test_cluster_exclude_hubs.py— full-run-safetytests/test_cobol_extractor.py— full-run-safetytests/test_codebuddy.py— impact, full-run-safetytests/test_community_hub_labels.py— full-run-safetytests/test_community_labels_skill.py— impact, changed-test, full-run-safetytests/test_confidence.py— impact, full-run-safetytests/test_corrupt_graph_json.py— impact, full-run-safety- … and 318 more
non-code file(s) changed (
graphify/skill-agents.md,graphify/skill-aider.md,graphify/skill-amp.md,graphify/skill-claw.md,graphify/skill-codex.md…) → running the full suite for safety (a code graph can't see config/fixture/data deps)
changed code file(s) with no mapped test (
graphify/skill-agents.md,graphify/skill-aider.md,graphify/skill-amp.md,graphify/skill-claw.md,graphify/skill-codex.md…) — a coverage gap or a missing link — running the full suite rather than only the selected tests
Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.
Formal verification
Could not verify: Could not verify \_translate\_bash\_block.
The verifier did not have enough to check \_translate\_bash\_block, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: non-vacuity: domain too small (only 1 distinct inputs exercised, need 3) — 'no divergence' would be near-vacuous
No difference found (not proven): No behavior difference found in monolith\_roundtrip (not a proof).
The verifier ran both versions of monolith\_roundtrip on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.
Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.
Note: An input the sampler did not try could still differ.
· 1 more finding(s) on lines outside this diff (see the check run).
Good catch: a root ending in a space would be trimmed, and if a sibling folder with the trimmed name exists, the wrong folder gets scanned. This PR matches what every existing |
0a04aa4 to
714f132
Compare
714f132 to
319c8b5
Compare
319c8b5 to
325e434
Compare
…DICT (Graphify-Labs#4309) The skill has the agent paste these two values into python -c scripts. A label like `x $(touch PWNED)` then runs in the shell, and `x'}; ...` runs as Python. Step 1 and --watch were fixed earlier; the other steps and the labels were not. The tests render every skill file and check that no script pastes them, that the interpreter path is quoted, and that Step 5 reads labels from JSON. They also pin read_scan_root(), which doesn't exist yet, so they fail until the fix lands.
…aphify-Labs#4309) Skill steps paste INPUT_PATH into python -c scripts, so a folder name such as `proj$(touch X)` can run as shell code. The root is already saved by Step 1 in graphify-out/.graphify_root; this reads it back as plain data. The root may sit outside the cwd, so it only has to be a non-empty path to an existing directory.
…code (Graphify-Labs#4309) Step 5 had the agent paste a Python dict over LABELS_DICT and the scan path over INPUT_PATH inside a double-quoted python -c script. A label such as `x $(touch PWNED)` ran in the shell, and `x'}; ...` ran as Python. The agent now writes the names as JSON through a quoted heredoc and the script loads them with json.loads. The scan root comes from read_scan_root(). The generator turns the heredoc into a PowerShell here-string for Windows, and the monolith audit allows these lines. INPUT_PATH in the other steps and the interpreter quoting follow in separate commits.
…tep (Graphify-Labs#4309) The skill had the agent paste the scan path over INPUT_PATH inside the double-quoted python -c scripts of Steps 2, 3, 4, 4.5 and 9 and the --update runbook. A folder name such as `proj$(touch X)` then ran as shell code. Those scripts now call read_scan_root(). The monolith audit allows the seven lines that changed, and the persisted-scan-options test writes graphify-out/.graphify_root as the skill does. Step 1 still takes the path through a quoted heredoc, which is safe. A step run by hand without Step 1 now fails with FileNotFoundError.
…y-Labs#4309) Step 1 saves the interpreter to graphify-out/.graphify_python and every later step runs it as $(cat graphify-out/.graphify_python). Unquoted, an interpreter under a folder with a space (/Users/First Last/...) splits into two words and the step fails. Every invocation is now "$(cat graphify-out/.graphify_python)", including the guidance that tells the agent how to call Python. The Windows translator recognizes script openers by exact text, so _PY_INVOKE_POSIX changes to match. The monolith round-trip unquotes the rendered side before diffing, so a quote-only change cancels out while any other edit on those lines is still flagged.
Graphify-Labs#4309) Steps B0 and B3 had the agent paste the spec path over SPEC_PATH inside prompt_file='SPEC_PATH' in a double-quoted python -c body, so a path with a quote or $( ran as Python or shell. Step B0 now writes the path to graphify-out/.graphify_spec_path through a quoted heredoc, and both cache calls read it back, so the read and the write still name the same prompt (Graphify-Labs#1939). The Windows translator handled only the labels heredoc; it now takes a table of the known data heredocs, and any other heredoc still raises.
…Labs#4309) A scan path with a line break could end the quoted heredoc (or the PowerShell here-string) early and run the lines after it as shell. The skill now tells the agent to refuse such a path and ask for another one. The POSIX Python side reads all of stdin and exits non-zero on more than one line; the PowerShell block does the same check. The block comments now say only what is true.
…ath is quoted (Graphify-Labs#4309) test_query_fallback_edges.py located the script by the unquoted opener $(cat graphify-out/.graphify_python) -c ". This branch quotes the interpreter path, so the lookup failed. It now matches on -c " plus the import lines that follow, which only the fallback block has.
… seed .graphify_root in the code-only update test (Graphify-Labs#4309) The aider and devin code-only blocks that landed with Graphify-Labs#4447 still called $(cat graphify-out/.graphify_python) unquoted. The code-only update test pasted INPUT_PATH itself and never wrote the marker Step 1 records, which the update blocks now read.
325e434 to
7a9c4c0
Compare
…laceholders # Conflicts: # graphify/skill-agents.md # graphify/skill-amp.md # graphify/skill-claw.md # graphify/skill-codex.md # graphify/skill-copilot.md # graphify/skill-droid.md # graphify/skill-kilo.md # graphify/skill-kiro.md # graphify/skill-opencode.md # graphify/skill-pi.md # graphify/skill-trae.md # graphify/skill-vscode.md # graphify/skill-windows.md # graphify/skill.md # tools/skillgen/expected/graphify__skill-agents.md # tools/skillgen/expected/graphify__skill-amp.md # tools/skillgen/expected/graphify__skill-claw.md # tools/skillgen/expected/graphify__skill-codex.md # tools/skillgen/expected/graphify__skill-copilot.md # tools/skillgen/expected/graphify__skill-droid.md # tools/skillgen/expected/graphify__skill-kilo.md # tools/skillgen/expected/graphify__skill-kiro.md # tools/skillgen/expected/graphify__skill-opencode.md # tools/skillgen/expected/graphify__skill-pi.md # tools/skillgen/expected/graphify__skill-trae.md # tools/skillgen/expected/graphify__skill-vscode.md # tools/skillgen/expected/graphify__skill-windows.md # tools/skillgen/expected/graphify__skill.md # tools/skillgen/fragments/core/core.md
The no-pasted-placeholder fixes (Graphify-Labs#4309) grew the blessed skill.md to 817 lines. 817 is still materially smaller than the old ~1156-line monolith, so the cap tracks that intent instead of an exact number (same fix as 4353: 6a2697d).
Upstream Graphify-Labs#4762 already reads the scan root from .graphify_root into an INPUT_PATH variable in every block, so this branch adopts that and drops its own read_scan_root() rewrites of the skill scripts. What stays here: Step 5 labels read from JSON, the spec path read from a file, the quoted interpreter path, and the Step 1 line-break refusal. The placeholder guard now matches only the quoted 'INPUT_PATH' literal, and the Graphify-Labs#4777 force test writes the labels file instead of pasting LABELS_DICT.
What does this PR do?
Fixes #4309.
The skill told the agent to paste three values into the Python scripts it runs:
INPUT_PATH, the folder to scanLABELS_DICT, the community namesSPEC_PATH, the path to the extraction specA pasted value becomes code. A folder named
proj$(touch PWNED)runstouch PWNEDbefore Python starts, and a label likex'}; ...; #ends the Python string early.Now the agent writes each value to a file through a quoted heredoc (the shell copies it as plain text), and the script reads the file:
Step 1 + save the scan folder to graphify-out/.graphify_root later steps - detect(Path('INPUT_PATH')) + detect(read_scan_root()) Step B0/B3 - prompt_file='SPEC_PATH' + prompt_file=<read from graphify-out/.graphify_spec_path> Step 5 - labels = LABELS_DICT + labels = json.loads(<graphify-out/.graphify_labels_in.json>)It also quotes the interpreter path,
"$(cat graphify-out/.graphify_python)", so an interpreter under/Users/First Last/no longer splits in two.How to review
Read these, in this order:
tools/skillgen/fragments/core/core.mdtools/skillgen/fragments/references/shared/update.md,references/query/default.md, and three smallreferences/shared/*.mdtools/skillgen/fragments/core/aider.md,core/devin.mdgraphify/paths.pyread_scan_root()(20 lines)tools/skillgen/gen.pytests/test_skillgen_no_pasted_placeholders.pySkip
graphify/skill*.md,graphify/skills/**andtools/skillgen/expected/**. They're generated.Evidence: before and after
The real Step 2 script from
graphify/skill.md, run on a folder namedproj$(touch PWNED):On
v8the folder name runs as a command and the wrong folder gets scanned.Reproduce it
From a checkout, with graphify installed in
.venv:Commits
Type of change
Verification & Invariants
The rule: a value the agent supplies never becomes part of a script. Scripts read it from a file in
graphify-out/.Enforced by
tests/test_skillgen_no_pasted_placeholders.py: it renders every skill and fails if a script containsINPUT_PATH,LABELS_DICTorSPEC_PATH, or runs the interpreter unquoted. It fails on the test commit alone (7e36f0c) and passes on the branch. Two more tests run the real heredocs with hostile input (x $(touch PWNED) `touch PWNED2` $HOME) and check that nothing runs.Limitations:
Not tested on Windows PowerShell 5.1. The Windows blocks ran under PowerShell 7.4.6 on Linux.
Step 1 leaving empty files on a full disk is a separate bug, [Bug]: /graphify skill "Step 1 - Ensure graphify is installed" exits 0 and leaves empty graphify-out files when a write fails; .graphify_root readers trim folder names #4346, fixed in fix: Step 1 fails loudly instead of leaving empty marker files; readers keep .graphify_root exactly (#4346) #4353.
Read the CONTRIBUTING.md guide.
Reproduced the issue and identified the invariant.
Made the smallest fix necessary.
Added a regression test (if bug fix) or isolated boundary test.
Kept the PR description synchronized with the final implementation.
Documented any limitations / unsupported cases explicitly.
How was this tested?
Linux, Python 3.13, rebased on v8 fe085ce (0.9.90).
Rebased on v8 fe085ce. One new commit: v8 added tests/test_query_fallback_edges.py, which found the query fallback by the unquoted opener. This branch quotes the interpreter path, so the test now matches on -c " and the import lines after it.
The changed test files also passed on Python 3.10 and 3.13. The Windows blocks from
skill-windows.mdran under PowerShell 7.4.6, and the semantic cache still hits on a second run.Merge Danger
Door: two-way. A revert restores the old skill text. No data is migrated.
Blast Radius: every skill. The library gains only
read_scan_root().graphify-out/.graphify_root not found; run Step 1 first.graphify-out/gets two small new files:.graphify_spec_pathand.graphify_labels_in.json.graphify/paths.pyandtools/skillgen/gen.py. I'll rebase whichever lands second.Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments.AI disclosure: I made these changes with Claude Code (Claude Opus 5.5). Claude Code ran the tests and commands listed above in my local checkout, and I reviewed every change and the results.
Update: rebased on 0.9.89
One new commit,
fix(skill): refuse a scan path with a line break in Step 1, answers the comment on #4309. A path line could end the heredoc early (or the here-string on PowerShell), and anything after it would run as shell. The agent is now told to refuse such a path, and the Python side rejects input of more than one line.The agent instruction is the real guard. The shell ends the heredoc before Python runs, so the Python check only catches multi-line input that reaches it.
#4353 is stacked on this PR.