[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6JZVC91A67X4P53V0S3C57H":3,"skill-same:01M6JZVC91A67X4P53V0S3C57H":61},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":32,"linkOnly":33,"markdownContent":34,"markdownBody":35,"frontMatter":36,"refName":38,"commitSha":39,"skillDirectory":40,"forksCount":41,"repositoryHtmlUrl":42,"repositoryHomepageUrl":6,"ownerHtmlUrl":43,"ownerBlogUrl":44,"ownerDescription":45,"updatedAt":46,"install":47,"resources":60},"01M6JZVC91A67X4P53V0S3C57H","audit-papyrus",null,"Deep audit of the Papyrus compiler frontends — .pex reader + 5-phase decompiler (Champollion port, crates\u002Fpex) and the .psc lexer\u002FPratt parser (crates\u002Fpapyrus): untrusted-input bounds, decompiler soundness, depth caps","matiaszanolli\u002FByroRedux","matiaszanolli","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F2379093?v=4","01M6JZJDYMPY01793W4XK157YG","Matias Zanolli","01M6JZJE2KE2BXSDPAYPQC6BSH",40,"MIT","https:\u002F\u002Fgithub.com\u002Fmatiaszanolli\u002FByroRedux\u002Fblob\u002Fmain\u002F.claude\u002Fcommands\u002Faudit-papyrus\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31],"audit","audit papyrus","deep","dimensions","compiler","port","focus","parser","input","reader","phase","depth","decompiler","2026-11-10 10:12:30",false,"---\ndescription: \"Deep audit of the Papyrus compiler frontends — .pex reader + 5-phase decompiler (Champollion port, crates\u002Fpex) and the .psc lexer\u002FPratt parser (crates\u002Fpapyrus): untrusted-input bounds, decompiler soundness, depth caps\"\nargument-hint: \"--focus \u003Cdimensions> --depth shallow|deep\"\n---\n\n# Papyrus Frontend Audit (`crates\u002Fpex` + `crates\u002Fpapyrus`)\n\nRead `.claude\u002Fcommands\u002F_audit-common.md` and `.claude\u002Fcommands\u002F_audit-severity.md` for shared protocol.\n\nAudit the two frontends that turn Papyrus bytes into the shared `byroredux_papyrus::ast::Script`:\nuntrusted `.pex` bytecode → decode (`crates\u002Fpex`) → 5-phase decompiler, and `.psc` source → lexer + Pratt\nparser (`crates\u002Fpapyrus`). Both feed the recognizer chain in `\u002Faudit-scripting` (which owns\n`translate_pex`'s clean-`None` contract and the panic net); this skill owns everything up to the AST.\n**Highest bug-density area of the scripting domain** (untrusted input + five tree-rewriting passes).\nFindings here are *silent wrong-AST* (a recognizer then matches it → wrong ECS behavior on vanilla\ncontent) or *process aborts* (OOM \u002F stack overflow — `catch_unwind` cannot recover either, so a panic net\nis no substitute for a bound).\n\n**Architecture**: Orchestrator; each dimension is a Task agent (max 3 concurrent).\n\n## Scope\n\n- `crates\u002Fpex\u002Fsrc\u002F`: `reader.rs`, `opcode.rs`, `model.rs`, `lib.rs` (`parse`, `PexError`,\n  `string_byte_budget`), `call_sites.rs` (`Pex::call_sites`, the extender-preflight scan — consumed by\n  `\u002Faudit-scripting` Dim 7), `decompile\u002F{mod,cfg,lift,boolean,control_flow,lower,node,event_names}.rs`.\n- `crates\u002Fpapyrus\u002Fsrc\u002F`: `token.rs`, `lexer.rs`, `ast.rs`, `span.rs`, `error.rs`, `lib.rs`,\n  `parser\u002F{mod,expr,stmt,script}.rs`.\n- Instruments: `crates\u002Fpex\u002Fexamples\u002Fpex_corpus_smoke.rs` (decompiles every `.pex` in real archives; the\n  source of the decompile-rate claim), `pex_dump_fn.rs` (raw-bytecode disassembly of one failing function), `pex_list_fns.rs` (a `.pex`'s typed function signatures, e.g. `Quest.pex` `OnStory*` — read-only convenience, not a gate),\n  `pex_find_call.rs` (every call site of one function name across an archive's `.pex`, via `call_sites` — \"who calls `ShowRaceMenu`?\", read-only, not a gate),\n  `pex_corpus_shapes.rs` + `docs\u002Fr5\u002Fcorpus-shape-survey.txt`,\n  `crates\u002Fbsa\u002Fexamples\u002Fr5_extract_pex_ba2.rs` (corpus extractor).\n- Ground truth: crate docstrings (`crates\u002Fpex\u002Fsrc\u002Flib.rs`, `decompile\u002Fmod.rs`), `docs\u002Fengine\u002F{papyrus-parser,\n  m47-2-design}.md` (\"no opcode semantics guessed\"). Reference decompiler: Champollion (`OPCODES`,\n  `PscCoder::writeStates`); UESP Papyrus Assembly spec for operand order.\n- Not here: hkx (`\u002Faudit-parsers`), ESM VMAD decode (`\u002Faudit-esm`), recognizers\u002Fruntime (`\u002Faudit-scripting`).\n\n## Parameters \u002F Extra Fields \u002F Severity\n\n`--focus` default all 4 · `--depth shallow` (bounds + depth-cap contracts) | `deep` (trace each pass's tree\nrewrite). Finding fields: **Dimension**: PEX Reader | Decompiler CFG & Lift | Decompiler Boolean\u002FControl-Flow\u002F\nLower | Papyrus Lexer & Parser · **Untrusted-Input**: Yes | No (Yes for any path consuming raw `.pex`\u002F`.psc`).\nEscalations over `_audit-severity.md`: panic \u002F OOB \u002F unbounded alloc or recursion reachable from untrusted\nbytes → **HIGH** (CRITICAL if memory-unsafe — the `transmute` in `opcode.rs`); decompiler emits a *wrong* AST\nthat a recognizer accepts, or copy-propagation \u002F boolean-collapse folds into the wrong consumer → **HIGH**\n(silent, all-game blast radius); doc rot → LOW.\n\n## Phase 1: Setup\n\n`mkdir -p \u002Ftmp\u002Faudit\u002Fpapyrus`; dedup `gh issue list --repo matiaszanolli\u002FByroRedux --limit 300 --json number,title,state,labels > \u002Ftmp\u002Faudit\u002Fpapyrus\u002Fissues.json`;\nread the newest `docs\u002Faudits\u002FAUDIT_SCRIPTING_*.md` (Dims 1-4 findings; pre-split reports use the old\n8-dimension numbering) and `docs\u002Fengine\u002Fm47-2-design.md` §\"Frontends in detail\"\u002F\"Risks & mitigations\" to\nseparate designed declines from defects. Run `cargo test -p byroredux-pex -p byroredux-papyrus`.\nDelta-first: `git log --since=\u003Clast report> --format='%h %cs %s' -- crates\u002Fpex crates\u002Fpapyrus` — these crates\nare quiet between some passes (and busy in others — M47.2 churned `lower.rs` and the parser's script items);\nif there are none, re-verify the guards below rather than re-reading source.\n\n## Phase 2: Dimensions\n\n### Dimension 1: `.pex` Reader & Opcode Decode (untrusted input — every finding is Untrusted-Input: Yes)\nPaths: `crates\u002Fpex\u002Fsrc\u002F{reader,opcode,model,lib,call_sites}.rs`\nFirst step: `cargo test -p byroredux-pex`  (then re-read any guard named below that did not run)\n- **`take(n)` is the single bounds gate** (`checked_add` + `\u003C= len` → `UnexpectedEof`). No read path may\n  index `self.data[..]` or `try_into().unwrap()` a short slice. Guard: `every_prefix_of_every_wire_valid_\n  sample_is_rejected` (exhaustive-prefix over five builders: Skyrim LE\u002FBE, extender-dependent BE, Starfield\n  guards, and #4474's `build_sample_full_coverage` — FO4 debug-info skips, getter\u002Fsetter bodies, non-empty\n  `struct_infos`, `Value::Float`). A new reader branch no sample reaches is the gap to look for.\n- **Allocation is bounded by something other than a wire count**: var-arg count `n` (up to `i32::MAX`) must\n  not feed `Vec::with_capacity` (grow by `push`; `hostile_vararg_count_errors_instead_of_ooming`); other\n  `with_capacity(count)` sites are `u16`-capped; `u32` flags\u002Fsizes are never capacities. **String copies are\n  charged against `string_byte_budget` = `max(64 × file size, 16 MiB)`** in both `reader.rs` and\n  `call_sites.rs` (`ScanBudget`; #4317 — a ~330 KB wire-valid file once exhausted 8 GB and aborted). Any new\n  owned copy of a table string (a new model field, a new scan) must be charged; guards\n  `string_copies_past_the_budget_are_refused`, `call_site_copies_are_bounded_by_the_string_budget`.\n- **`OpCode::from_u8` `transmute`** (`unsafe`, memory-safety-critical): `MAX_OPCODE == 51` equals last\n  discriminant + 1, enum `#[repr(u8)]` with contiguous `0..=50`, guard is `>=`; a compile-time\n  `const _: () = assert!(OpCode::TryLockGuards as u8 == MAX_OPCODE - 1)` backs it (#4475). Pins:\n  `discriminants_match_on_disk_order`, `from_u8_round_trips_and_rejects_oob`,\n  `metadata_matches_champollion{,_full_table}` (verify they cover every discriminant, not spot values).\n- **`arg_count` table** drives operand consumption: a wrong row desyncs the whole stream silently. Spot-check\n  var-arg opcodes (`callmethod`\u002F`callparent`\u002F`callstatic`\u002Fguard ops) and high-arity rows\n  (`array_findstruct` 5, `array_getallmatchingstructs` 6) against Champollion\u002FUESP.\n- `string_index` → `.get(idx)` \u002F `BadStringIndex` (never `self.strings[idx]`); `value()` accepts tags 0..=5,\n  `Integer` sign-reinterprets; endianness from magic (`0xFA57C0DE` LE \u002F `0xDEC057FA` BE) with the provisional\n  LE in `new()` never leaking into a multibyte read; Skyrim-vs-FO4+ field gating (`is_skyrim()`: `const_flag`,\n  `struct_infos`, property-group\u002Fstruct-order tables; Starfield-only `guards`) reads in FileReader order and\n  the consume-and-discard skips match the writer's byte counts.\n- `read_binary` is all-or-`Err` (no partial `Pex`); `call_sites` stops with a diagnostic when its budget is\n  exhausted rather than truncating silently.\n**Output**: `\u002Ftmp\u002Faudit\u002Fpapyrus\u002Fdim_1.md`\n\n### Dimension 2: Decompiler — CFG & Opcode→Node Lift (copy-propagation is the AST-correctness core)\nPaths: `crates\u002Fpex\u002Fsrc\u002Fdecompile\u002F{cfg,lift,node}.rs`\nFirst step: `cargo test -p byroredux-pex -- decompile::cfg decompile::lift`\n- **Jump targets**: `checked_target` accepts `0 \u003C= ip+offset \u003C= count` (inclusive — `count` is the exit\n  anchor); non-integer offset → `BadJumpOffset`, OOB → `JumpOutOfRange`, non-{ident,bool,int} condition →\n  `BadJumpCondition`. `CodeBlock::split(at)` is never called with `at == 0` (underflow).\n- **`jmpf`\u002F`jmpt` polarity**: `jmpf` jumps when FALSE (true-edge = fall-through); a flip inverts every `If`\n  (`forward_jmpf_builds_an_if_diamond`, `forward_jmpf_with_unconditional_backedge_builds_a_loop`, and\n  `backward_jmpt_builds_a_loop_edge` — a true `JmpT` pin since #4476; it was a misnamed `JmpF` test before).\n- **`rebuild_expression`**: a temp-producing node folds into the *single immediately-next live* consumer\n  (`count_constant_id`: 0 → advance, 1 → inline, >1 → `ExpressionRebuildFailed`); folding into a non-adjacent\n  consumer reorders side effects. It runs over a linked live-index chain, not restart-at-0\u002F`Vec::remove`\n  (O(n²), #2024 — `rebuild_expression_is_linear_up_to_the_wire_format_ceiling`). `is_final` vs `is_temp_var`\n  asymmetry (`::temp` prefix, `_var` suffix) is a deliberate Champollion port — unifying them is a regression.\n  `replace_constant_id`'s `debug_assert!(slot.is_none())` is debug-only: a release >1-match would silently\n  drop the producer.\n- **Depth is memoized on `Node`** (`Node::depth`, `recompute_depth`) and checked at every fold against\n  `MAX_EXPR_DEPTH` (= the papyrus parser constant), so repeated re-folds by the boolean\u002Fcontrol-flow passes\n  cannot reset the ledger (the SIGABRT class); guards `a_temp_chain_past_the_depth_cap_is_declined_not_aborted`\n  \u002F `..._inside_the_depth_cap_still_folds`. Any new in-place tree mutation must call `recompute_depth`.\n- `create_node`: `Cast` downgrades to `Copy` only when source is `None`, same-typed identifiers, or\n  `::nonevar` (case-insensitive) — a wrong downgrade turns a narrowing cast into an identity copy. Operand\n  order for `CallMethod`\u002F`CallStatic`\u002F`CallParent` (result\u002Fobject\u002Fmethod indices) is what recognizers key\n  on (`SetStage`, `GetStageDone`); cross-check UESP. `id_of` on a literal → `ExpectedIdentifier`, never\n  `unwrap()` outside a checked branch. Bodyless\u002Fnative functions decompile to an empty body.\n**Output**: `\u002Ftmp\u002Faudit\u002Fpapyrus\u002Fdim_2.md`\n\n### Dimension 3: Decompiler — Boolean, Control-Flow, Lower & the Corpus Instruments\nPaths: `crates\u002Fpex\u002Fsrc\u002Fdecompile\u002F{boolean,control_flow,lower,event_names,mod}.rs`, `crates\u002Fpex\u002Fexamples\u002Fpex_corpus_smoke.rs`\nFirst step: `cargo test -p byroredux-pex -- decompile::`; with game data: `cargo run --release -p byroredux-pex --example pex_corpus_smoke -- \u003CSkyrim - Misc.bsa> \u003CFallout4 - Misc.ba2>`\n- **Pass order is load-bearing**: `lower::decompile_body` runs cfg → lift → `rebuild_boolean_operators` →\n  `reconstruct` → `lower_body`; the boolean pass precedes control-flow so `&&`\u002F`||` chains collapse first.\n- **`control_flow.rs`**: shape classification (While: `last.next == current`; If: `last.next == exit`; If\u002FElse;\n  jmpt inversion negates + swaps edges). A conditional-predecessor `last` (`||` shape the boolean pass should\n  have collapsed) **fails closed** (`ControlFlowFailed`, #1732; `conditional_predecessor_fails_closed`) —\n  a fix that resumes past the block drops statements. The module doc now says \"declined with an error, not\n  advanced past\" (#4115 `18ce09bff`); wording that drifts back is doc rot.\n- **Bookkept Champollion departures** — `boolean.rs`'s two (plus a third, newer guard below). `lower.rs`'s `is` → object-typed\n  `Cast` departure (#4477) is closed: opcode 36 lowers to `Expr::Is` (#5443 `24f199587`, `an_is_opcode_lowers_to_an_is_expression`).\n  For the **`boolean.rs`** two — adjudicate benign-or-bug, evidence = corpus rate +\n  fidelity gate, not speculation: (1) no debug-line guard (a same-named temp on a fall-through edge could be\n  falsely collapsed into a fabricated `&&`\u002F`||`); (2) termination guard (only re-process on a real merge —\n  infinite loop hangs the decompiler). A declined collapse resumes `rebuild` at the operand range's END, not\n  its first block (#5877 `32352592f` — every nested body was re-walked once per enclosing level, O(2^depth):\n  a 656-byte `.pex` took 6.6 s; `deeply_nested_ifs_are_walked_once_not_exponentially`). `&&` true edge falls through, `||` false edge; operand must recompute\n  the same condition variable; prec `&&`=7\u002F`||`=8; `take_operand` leaves no dangling `None`.\n  **Private-edge guard** (`944d0299e`): a fold deletes the operand block (and a non-exit rejoin), so it\n  declines unless `incoming(operand) == 1` and, for an interior rejoin, `incoming(rejoin) == 2` — a shared\n  `return` epilogue that an early-exit `jmp` also targets left a dangling edge and failed `reconstruct` (the\n  last two corpus decompile failures: FO4 `StimBoxScript`, FO76 `Debug.TraceLog`; corpus now 100% on all four\n  games). The in-edge counts are built once and kept exact by `link`\u002F`unlink` at `collapse`'s three CFG\n  mutations (#5879 `32352592f` — a per-fold whole-CFG scan was O(B²); `in_edge_counts_survive_and_or_and_epilogue_folds`\n  compares them to a recount). Pins `or_whose_rejoin_is_a_shared_epilogue_is_left_uncollapsed`, `and_whose_rejoin_is_a_shared_epilogue_is_left_uncollapsed`. A new\n  fold that deletes a block, or a new CFG mutation that skips `link`\u002F`unlink`, is the regression.\n- **Recursion**: `MAX_REBUILD_DEPTH = 1024` in `control_flow.rs` (`boolean.rs` derives it — not restated);\n  both rebuilds return `RecursionLimit` (`rebuild_rejects_excessive_recursion_depth` exists in *both* files).\n  It and `MAX_EXPR_DEPTH` (256) compose additively (~1,280) and independent edits erode the margin\n  (#4113 still open, verified 2026-11-09) — check any change to either constant.\n- **`lower.rs` totality**: `lower_expr`\u002F`lower_stmt` never panic on any `NodeKind`; intentional lossy lowerings\n  matter only if a recognizer keys on the lost info: statement-shaped node as sub-expression → `NoneLit`\n  (should be unreachable), `is` → `Cast`, `lower_binary_op` default arm →\n  `Eq` (a real unknown op silently becomes `==`). `StructCreate` is no longer lossy: it lowers to\n  `Expr::NewStruct` (FO4 `new S`, the shape the `.psc` parser now emits too).\n  **Locals**: `lower_local_decls` prepends one bare `VarDecl` per non-temp local ahead of the body\n  (`0c6fe4d34` — without it every Champollion fragment prologue read as an assignment to an undeclared name and\n  the #5638 fragment guard declined it; `user_locals_are_declared_ahead_of_the_body_and_temporaries_are_not`).\n  \"Temp\" is Champollion `isTempVar` (`::temp` + a suffix, not ending `_var`, or `::nonevar`) — `lower.rs` now\n  calls `node.rs`'s `is_temp_var` (#6262 `475004d25`; the private case-insensitive copy it replaced left a local the\n  lift keeps as real, `::TEMP1` or a bare `::temp`, undeclared; a second predicate reappearing is the regression;\n  `user_locals_are_declared_ahead_of_the_body_and_temporaries_are_not`) — and is\n  NOT every `::` name: the compiler's `::mangled_\u003Cname>_\u003Cn>` user locals must be declared (#5880 `32352592f`,\n  ~280 vanilla functions declined under the old `::` filter).\n- **Script assembly**: FO4+ `struct_infos` lower to `ScriptItem::Struct` items first (members keep their stored\n  defaults; `pex_corpus_smoke`'s expected-item-count adds `struct_infos.len()`); synthetic `::` variables\n  dropped; variable and auto-property defaults lower to `initial_value` via `default_literal` (the backing\n  variable's stored default); the object's `conditional`\u002F`hidden`\u002F`default` user\n  flags (bit indices named by the file's own user-flag table, resolved ONCE per `Pex` by\n  `UserFlagMasks::from_pex` — #5683 `d8b1d333c`, the old per-variable *has_user_flag* rescan was O(F×V), ~18 s on\n  an 852 KB hostile file, `a_hostile_user_flag_table_decompiles_in_linear_time`; `flag_index \u003C 32` guards the\n  shift on untrusted bytes) lower into the same `ScriptFlags` the `.psc` header parses, a\n  variable's `conditional` into `is_conditional` (#5398 `ce90b481c`, `object_user_flags_lower_into_script_flags`;\n  struct members through the same table, `struct_member_user_flags_lower_into_variable_flags`)\n  and a property's `const`\u002F`mandatory`\u002F`hidden`\u002F`conditional` into `PropertyFlags` (#5685 `f7afb0e07`,\n  `property_user_flags_lower_into_property_flags`) — from the property's user bits OR its auto backing\n  variable's, plus the backing variable's `const_flag` → `CONST` (#5882 `958c26c4e`: vanilla tables never name\n  `const` and `Auto Const`\u002F`Auto Conditional` bits live on the backing variable, Champollion `writeProperty`;\n  ~22.5k FO4 \u002F 24.5k Starfield `Auto Const` once lowered bare). The backing variable is found via one\n  per-object map, not a per-property scan (the hostile linear-time test covers 65,535 auto properties, #5878);\n  **script scope = the empty-named state's functions**;\n  every named state → a `State` item; exactly one (the first case-insensitive `is_auto_state` match against\n  `auto_state_name`) is `is_auto` (#4473, `case_colliding_state_names_mark_exactly_one_auto`) — keying scope on the auto match inverted 983 vanilla scripts (#4319;\n  `named_auto_state_stays_an_auto_state_and_the_empty_state_is_script_scope`). Event iff (`on`-prefixed AND\n  `is_event_name`) OR `::remote_`-prefixed; `EVENT_NAMES` is a sorted lowercase union binary-searched\n  (`list_is_sorted_for_binary_search`); a missing engine event demotes a handler to a function. The list is a\n  documented **superset** of Champollion's frozen `EventNames.hpp`: 12 real engine events it omits\n  (`OnAttach`, `OnStoryClearLocation`, ten Starfield) are hand-added in sorted position from a base-class\n  corpus census (#4471 `0611cd116`; `the_census_engine_events_classify_as_events`, which also keeps vanilla\n  typos like `oncelldetatch` out) — an addition needs the same census evidence, not a guess.\n- **The decompile-rate claim measures robustness, not fidelity.** `pex_corpus_smoke` counts `Err` and\n  panics as failures, tallies after `decompile_script`, and exits non-zero on any decompile `Err`, panic or shape\n  mismatch, not only parse failures (#5883 `958c26c4e`) — verify that gate still holds. Its shape check must not share an\n  implementation rule with the code under test — the #3017 check and `decompile_script` shared the wrong\n  auto-state rule and both agreed on 983 mis-assembled scripts. Fidelity evidence is the `.psc`-vs-`.pex`\n  gate (owned by `\u002Faudit-scripting` Dim 1: `recognizes_da10_and_reproduces_hand_builder` +\n  `da10_pex_reproduces_hand_builder_byte_for_byte`), not the corpus rate.\n**Output**: `\u002Ftmp\u002Faudit\u002Fpapyrus\u002Fdim_3.md`\n\n### Dimension 4: `.psc` Lexer & Pratt Parser (untrusted: `.psc` files and console\u002Fdebug text)\nPaths: `crates\u002Fpapyrus\u002Fsrc\u002F{token,lexer,ast,error,lib}.rs`, `crates\u002Fpapyrus\u002Fsrc\u002Fparser\u002F{mod,expr,stmt,script}.rs`\nFirst step: `cargo test -p byroredux-papyrus -- depth chain the_two_parser_depth_caps_stay_equal`\n- **Depth caps** (stack overflow *and* AST `Drop` recursion): `MAX_EXPR_DEPTH = 256` (`expr.rs`) and\n  `MAX_STMT_DEPTH = 256` (`stmt.rs`), both `pub`, equality pinned by `the_two_parser_depth_caps_stay_equal`;\n  downstream `MAX_CONDITIONAL_DEPTH` and `lift.rs`'s cap alias them. The Pratt loop **charges `expr_depth`\n  for each node a postfix\u002Fbinary chain wraps** (#4320 — the cap once counted only recursive calls, so\n  `a.a.a…` of ~0.4 MB overflowed on Drop) and restores on **every** exit including error paths\n  (`long_postfix_and_binary_chains_hit_the_depth_cap`, `realistic_chains_still_parse_and_release_their_depth`,\n  `depth_resets_between_top_level_calls`). All recursive expression entry funnels through `parse_expr_bp`.\n- **Newline is a terminator in the Pratt loop**: the loop uses `peek_raw()`, not the newline-skipping\n  `peek()` (#4321 — a line opening with `(` was glued to the previous statement, a silent wrong AST). Explicit\n  `\\` continuations are a logos skip rule in `lexer.rs` (#5881 `af4a68ad7` — no pre-pass; the `;` comment callback owns a trailing `\\`); an operator ending a line still continues. Verify\n  every other `peek()` on a statement boundary: #4472 (six sites, via `check_raw`) and #4763 (seven more —\n  `Extends`, variable\u002Ffunction\u002Fgroup flags, property and local initializers) moved construct-continuation\n  decisions to the raw stream, each pinned by an `*_on_the_next_line_*` test in `script.rs` plus\n  `single_line_forms_of_the_4763_sites_still_parse`. Remaining `peek()`\u002F`check()` sites should sit behind an\n  explicit `skip_newlines()` or a bracket-bounded list. `expect()` \u002F `expect_ident()` still skip newlines, so\n  a keyword's **mandatory operand** goes through `expect_same_line` \u002F `expect_raw` \u002F `expect_ident_raw`\n  (`parser\u002Fmod.rs`; #5021, `3b7ffa670`): declaration names, the `Extends` target, the `(` after a function\n  name, `State` after `Auto`, the If\u002FElseIf\u002FWhile condition start, `New`'s type and `[` — #5331 `fd5aa4ead`,\n  `parse_new_expr`; the `[` is optional only for an `Object` type, where a same-line `new S` is FO4's\n  `Expr::NewStruct` — the type operand of `as` \u002F `is` (#5445 `cc3f80e55`, `parse_cast`\u002F`parse_is`; `x as` then `Actor` on the next line once parsed clean), and every segment after a qualified name's `:` (`parse_qualified_ident` → `expect_ident_raw`,\n  #5885 `3081d23f2`: ScriptName\u002FExtends\u002FImport\u002Fevent sender\u002Ftypes; `a_namespaced_parent_on_the_next_line_is_still_not_the_parent`) — pinned by\n  `a_mandatory_operand_on_the_next_line_is_an_error`, `auto_on_its_own_line_does_not_make_an_auto_state`,\n  `extends_with_its_target_on_the_next_line_sets_no_parent`, `single_line_forms_of_the_5021_sites_still_parse`.\n  Only closing keywords may keep the newline-skipping `expect`; a new declaration keyword that uses it is the\n  regression.\n- **Statement termination** (#5322 `a5c3f2428`): `expect_eol` (`parser\u002Fmod.rs`) used to accept ANY token after a\n  statement, so a tail the Pratt loop stopped at re-parsed as a new statement (`If f is Actor` became a\n  truthiness test plus a fabricated `VarDecl`) with zero errors. It now records a recovered `UnexpectedToken` for\n  anything but Newline\u002FEOF\u002FDocComment and skips to line end via `skip_to_line_end`, which leaves block terminators\n  (`EndIf`, `Else*`, `End*`) unconsumed so a glued `x = 1 EndIf` still closes its block\n  (`glued_statement_tail_is_an_error_and_not_a_statement`; `EndStruct` \u002F `EndGroup` stay too, #5444 `3efa1c024`,\n  `glued_struct_and_group_terminators_stay_for_their_container`); `parse_expr` (debug console, offline preflight) ends in\n  `require_input_end` (`parse_expr_rejects_trailing_tokens`). FO4 `is` is a keyword with an `Expr::Is` type-test\n  node at cast precedence (`test_is_type_test`); downstream exhaustive matches treat it as transparent to the operand\n  (the `.pex` side lowers `OpCode::Is` to the same `Expr::Is`, #5443; the VM evaluates it as the operand's truthiness).\n- **Doc comments and FO4 names** (`e96d687ec`): Papyrus puts an item's `{…}` doc on the line AFTER its header, so\n  `take_trailing_doc` (`parser\u002Fmod.rs`) consumes one right after each header's `expect_eol` (script header,\n  property, group, struct + member, function\u002Fevent; #5325 — a bodied function's doc once became its first\n  \"statement\" and the function was dropped). `expect_eol` accepts a `{doc}` terminator only when it ends the\n  line (#5886 `3081d23f2`, `a_same_line_doc_comment_cannot_share_its_line_with_the_next_item`). There is no\n  leading-doc fallback: a top-level `{lead}` is discarded, and inside State\u002FGroup\u002Faccessor containers it is a\n  parse error (#5890 `d148cd27b`, `a_leading_doc_comment_attaches_to_nothing`). Script name, `Extends` target and\n  `Import` are qualified idents (`DLC01:Foo`); a remote event `Event Sender.Event(…)` (#5328) is normalised to\n  the compiler's `Sender_Event` spelling — what the `.pex` frontend yields and the VM's remote matcher binds,\n  while a consumer matching the script's own `OnDeath` does not (#5887 `3081d23f2`,\n  `remote_event_handlers_parse_with_their_sender_in_the_name`). `Parent` is a legal name only as a struct-member\n  declaration or after `.` (#5888, `parent_is_a_legal_member_name`; the F4SE corpus test's `KNOWN_GAPS` is now\n  empty) — via `expect_member_name`, NOT the shared `keyword_as_ident` table: #5888 first put it there and a\n  local\u002Fparameter named `Parent` then declared fine and parsed every use as `ParentAccess` (#6263 `a87650237`,\n  `parent_is_not_a_local_or_parameter_name`; `parse_variable_body(struct_member)` carries the distinction). Pins\n  `a_doc_comment_after_a_bodied_function_header_documents_it`, `namespaced_script_name_parent_and_import_keep_every_segment`.\n- **Precedence\u002Fassociativity**: `BinaryOp::precedence` Or=1, And=2, comparisons=3, Add\u002FSub\u002FStrCat=4,\n  Mul\u002FDiv\u002FMod=5, unary=6, cast=7\u002Fpostfix=8 (`PREC_*` in `expr.rs`); left-assoc hinges on `op_prec \u003C= min_bp →\n  break`. (Bethesda's inverted CTDA OR\u002FAND precedence is a *condition-evaluation* concern in\n  `\u002Faudit-scripting` Dim 3 — `.psc` operators are standard.)\n- **Line continuation** (#5881): a `\\` followed by blanks \u002F a `;` comment \u002F `\\n`, `\\r\\n` or lone `\\r` is one skip rule, so\n  spans index the caller's own text with no offset map (#5884 `af4a68ad7` — *preprocess*\u002F*OffsetMap* are gone;\n  `spans_after_a_continuation_are_original_offsets`, `ast_spans_stay_in_original_coordinates_after_a_continuation`);\n  a trailing `\\` at EOF is emitted, not swallowed. Unterminated `;\u002F` block comments, `{` docs and string literals\n  are `LexError`s, not a silent swallow to EOF (#5889 `af4a68ad7`, `unterminated_block_comment_string_and_doc_are_lex_errors`). Keywords are\n  `ignore(case)` (logos 0.16 dropped *ascii_case*, `15a6b1d2d` — Unicode folding, which differs only for the few\n  non-ASCII letters that fold onto ASCII, e.g. U+017F, U+212A, invalid Papyrus either way) and win over the\n  `Ident` regex. CK flags matched **contextually** stay out of the lexer: `Default` (script header) and\n  `Collapsed` (group) are identifiers checked in their flag position (#5398 `ce90b481c`,\n  `default_and_collapsed_remain_identifiers`) — expressions accept only `Token::Ident`, so promoting either to a\n  keyword breaks every variable of that name. Lone CR is a line terminator and CRLF one `Newline`\n  (`bare_cr_is_a_newline_and_crlf_is_one_newline`, #4479 — a CR-only file once lexed to zero newlines); a `;`\n  line comment likewise stops at the first `\\r` *or* `\\n` (`line_comment_ends_at_a_bare_cr`, #5019 `a75c7dc33` —\n  it once searched only `\\n`, swallowing a CR-only file to EOF with zero errors);\n  `0x` and exponent shapes route through `MalformedNumber` to a `LexError`, not an adjacent token pair.\n- **Recovery**: `parse_script` returns `Ok((Script, Vec\u003CParseError>))` for partial success and `Err` only for\n  fatal; `skip_to_next_line` always consumes ≥1 token (no infinite loop); callers needing strict-fail check\n  `result.1.is_empty()`. No `unwrap()` on `str::parse` of a malformed-but-lexable literal.\n**Output**: `\u002Ftmp\u002Faudit\u002Fpapyrus\u002Fdim_4.md`\n\n## Phase 3: Merge\n\nCombine `\u002Ftmp\u002Faudit\u002Fpapyrus\u002Fdim_*.md` into `docs\u002Faudits\u002FAUDIT_PAPYRUS_\u003CTODAY>.md`: **Executive Summary**\n(findings by severity; **untrusted-input robustness verdict** — can a hostile `.pex`\u002F`.psc` panic, OOB, OOM,\nor stack-overflow the cell loader \u002F console — must be NO; **decompile-rate verdict** — re-measured, and what\nit does and does not prove) · **Decompiler Soundness Matrix** (reader \u002F cfg \u002F lift+copy-prop \u002F boolean \u002F\ncontrol-flow \u002F lower \u002F `.psc` parser × bounds-safe, terminates, total, fidelity-tested; the three Champollion\ndepartures adjudicated) · **Findings** (severity order, deduplicated). Cross-audit: recognizer\u002Fruntime →\n`\u002Faudit-scripting`; `.pex` bytes reaching the extender preflight → `\u002Faudit-scripting` Dim 7.\n\n## Phase 4: Cleanup\n\n`rm -rf \u002Ftmp\u002Faudit\u002Fpapyrus`; tell the user the report is ready; suggest\n`\u002Faudit-publish docs\u002Faudits\u002FAUDIT_PAPYRUS_\u003CTODAY>.md` (domain label `scripting`).\n","# Papyrus Frontend Audit (`crates\u002Fpex` + `crates\u002Fpapyrus`)\n\nRead `.claude\u002Fcommands\u002F_audit-common.md` and `.claude\u002Fcommands\u002F_audit-severity.md` for shared protocol.\n\nAudit the two frontends that turn Papyrus bytes into the shared `byroredux_papyrus::ast::Script`:\nuntrusted `.pex` bytecode → decode (`crates\u002Fpex`) → 5-phase decompiler, and `.psc` source → lexer + Pratt\nparser (`crates\u002Fpapyrus`). Both feed the recognizer chain in `\u002Faudit-scripting` (which owns\n`translate_pex`'s clean-`None` contract and the panic net); this skill owns everything up to the AST.\n**Highest bug-density area of the scripting domain** (untrusted input + five tree-rewriting passes).\nFindings here are *silent wrong-AST* (a recognizer then matches it → wrong ECS behavior on vanilla\ncontent) or *process aborts* (OOM \u002F stack overflow — `catch_unwind` cannot recover either, so a panic net\nis no substitute for a bound).\n\n**Architecture**: Orchestrator; each dimension is a Task agent (max 3 concurrent).\n\n## Scope\n\n- `crates\u002Fpex\u002Fsrc\u002F`: `reader.rs`, `opcode.rs`, `model.rs`, `lib.rs` (`parse`, `PexError`,\n  `string_byte_budget`), `call_sites.rs` (`Pex::call_sites`, the extender-preflight scan — consumed by\n  `\u002Faudit-scripting` Dim 7), `decompile\u002F{mod,cfg,lift,boolean,control_flow,lower,node,event_names}.rs`.\n- `crates\u002Fpapyrus\u002Fsrc\u002F`: `token.rs`, `lexer.rs`, `ast.rs`, `span.rs`, `error.rs`, `lib.rs`,\n  `parser\u002F{mod,expr,stmt,script}.rs`.\n- Instruments: `crates\u002Fpex\u002Fexamples\u002Fpex_corpus_smoke.rs` (decompiles every `.pex` in real archives; the\n  source of the decompile-rate claim), `pex_dump_fn.rs` (raw-bytecode disassembly of one failing function), `pex_list_fns.rs` (a `.pex`'s typed function signatures, e.g. `Quest.pex` `OnStory*` — read-only convenience, not a gate),\n  `pex_find_call.rs` (every call site of one function name across an archive's `.pex`, via `call_sites` — \"who calls `ShowRaceMenu`?\", read-only, not a gate),\n  `pex_corpus_shapes.rs` + `docs\u002Fr5\u002Fcorpus-shape-survey.txt`,\n  `crates\u002Fbsa\u002Fexamples\u002Fr5_extract_pex_ba2.rs` (corpus extractor).\n- Ground truth: crate docstrings (`crates\u002Fpex\u002Fsrc\u002Flib.rs`, `decompile\u002Fmod.rs`), `docs\u002Fengine\u002F{papyrus-parser,\n  m47-2-design}.md` (\"no opcode semantics guessed\"). Reference decompiler: Champollion (`OPCODES`,\n  `PscCoder::writeStates`); UESP Papyrus Assembly spec for operand order.\n- Not here: hkx (`\u002Faudit-parsers`), ESM VMAD decode (`\u002Faudit-esm`), recognizers\u002Fruntime (`\u002Faudit-scripting`).\n\n## Parameters \u002F Extra Fields \u002F Severity\n\n`--focus` default all 4 · `--depth shallow` (bounds + depth-cap contracts) | `deep` (trace each pass's tree\nrewrite). Finding fields: **Dimension**: PEX Reader | Decompiler CFG & Lift | Decompiler Boolean\u002FControl-Flow\u002F\nLower | Papyrus Lexer & Parser · **Untrusted-Input**: Yes | No (Yes for any path consuming raw `.pex`\u002F`.psc`).\nEscalations over `_audit-severity.md`: panic \u002F OOB \u002F unbounded alloc or recursion reachable from untrusted\nbytes → **HIGH** (CRITICAL if memory-unsafe — the `transmute` in `opcode.rs`); decompiler emits a *wrong* AST\nthat a recognizer accepts, or copy-propagation \u002F boolean-collapse folds into the wrong consumer → **HIGH**\n(silent, all-game blast radius); doc rot → LOW.\n\n## Phase 1: Setup\n\n`mkdir -p \u002Ftmp\u002Faudit\u002Fpapyrus`; dedup `gh issue list --repo matiaszanolli\u002FByroRedux --limit 300 --json number,title,state,labels > \u002Ftmp\u002Faudit\u002Fpapyrus\u002Fissues.json`;\nread the newest `docs\u002Faudits\u002FAUDIT_SCRIPTING_*.md` (Dims 1-4 findings; pre-split reports use the old\n8-dimension numbering) and `docs\u002Fengine\u002Fm47-2-design.md` §\"Frontends in detail\"\u002F\"Risks & mitigations\" to\nseparate designed declines from defects. Run `cargo test -p byroredux-pex -p byroredux-papyrus`.\nDelta-first: `git log --since=\u003Clast report> --format='%h %cs %s' -- crates\u002Fpex crates\u002Fpapyrus` — these crates\nare quiet between some passes (and busy in others — M47.2 churned `lower.rs` and the parser's script items);\nif there are none, re-verify the guards below rather than re-reading source.\n\n## Phase 2: Dimensions\n\n### Dimension 1: `.pex` Reader & Opcode Decode (untrusted input — every finding is Untrusted-Input: Yes)\nPaths: `crates\u002Fpex\u002Fsrc\u002F{reader,opcode,model,lib,call_sites}.rs`\nFirst step: `cargo test -p byroredux-pex`  (then re-read any guard named below that did not run)\n- **`take(n)` is the single bounds gate** (`checked_add` + `\u003C= len` → `UnexpectedEof`). No read path may\n  index `self.data[..]` or `try_into().unwrap()` a short slice. Guard: `every_prefix_of_every_wire_valid_\n  sample_is_rejected` (exhaustive-prefix over five builders: Skyrim LE\u002FBE, extender-dependent BE, Starfield\n  guards, and #4474's `build_sample_full_coverage` — FO4 debug-info skips, getter\u002Fsetter bodies, non-empty\n  `struct_infos`, `Value::Float`). A new reader branch no sample reaches is the gap to look for.\n- **Allocation is bounded by something other than a wire count**: var-arg count `n` (up to `i32::MAX`) must\n  not feed `Vec::with_capacity` (grow by `push`; `hostile_vararg_count_errors_instead_of_ooming`); other\n  `with_capacity(count)` sites are `u16`-capped; `u32` flags\u002Fsizes are never capacities. **String copies are\n  charged against `string_byte_budget` = `max(64 × file size, 16 MiB)`** in both `reader.rs` and\n  `call_sites.rs` (`ScanBudget`; #4317 — a ~330 KB wire-valid file once exhausted 8 GB and aborted). Any new\n  owned copy of a table string (a new model field, a new scan) must be charged; guards\n  `string_copies_past_the_budget_are_refused`, `call_site_copies_are_bounded_by_the_string_budget`.\n- **`OpCode::from_u8` `transmute`** (`unsafe`, memory-safety-critical): `MAX_OPCODE == 51` equals last\n  discriminant + 1, enum `#[repr(u8)]` with contiguous `0..=50`, guard is `>=`; a compile-time\n  `const _: () = assert!(OpCode::TryLockGuards as u8 == MAX_OPCODE - 1)` backs it (#4475). Pins:\n  `discriminants_match_on_disk_order`, `from_u8_round_trips_and_rejects_oob`,\n  `metadata_matches_champollion{,_full_table}` (verify they cover every discriminant, not spot values).\n- **`arg_count` table** drives operand consumption: a wrong row desyncs the whole stream silently. Spot-check\n  var-arg opcodes (`callmethod`\u002F`callparent`\u002F`callstatic`\u002Fguard ops) and high-arity rows\n  (`array_findstruct` 5, `array_getallmatchingstructs` 6) against Champollion\u002FUESP.\n- `string_index` → `.get(idx)` \u002F `BadStringIndex` (never `self.strings[idx]`); `value()` accepts tags 0..=5,\n  `Integer` sign-reinterprets; endianness from magic (`0xFA57C0DE` LE \u002F `0xDEC057FA` BE) with the provisional\n  LE in `new()` never leaking into a multibyte read; Skyrim-vs-FO4+ field gating (`is_skyrim()`: `const_flag`,\n  `struct_infos`, property-group\u002Fstruct-order tables; Starfield-only `guards`) reads in FileReader order and\n  the consume-and-discard skips match the writer's byte counts.\n- `read_binary` is all-or-`Err` (no partial `Pex`); `call_sites` stops with a diagnostic when its budget is\n  exhausted rather than truncating silently.\n**Output**: `\u002Ftmp\u002Faudit\u002Fpapyrus\u002Fdim_1.md`\n\n### Dimension 2: Decompiler — CFG & Opcode→Node Lift (copy-propagation is the AST-correctness core)\nPaths: `crates\u002Fpex\u002Fsrc\u002Fdecompile\u002F{cfg,lift,node}.rs`\nFirst step: `cargo test -p byroredux-pex -- decompile::cfg decompile::lift`\n- **Jump targets**: `checked_target` accepts `0 \u003C= ip+offset \u003C= count` (inclusive — `count` is the exit\n  anchor); non-integer offset → `BadJumpOffset`, OOB → `JumpOutOfRange`, non-{ident,bool,int} condition →\n  `BadJumpCondition`. `CodeBlock::split(at)` is never called with `at == 0` (underflow).\n- **`jmpf`\u002F`jmpt` polarity**: `jmpf` jumps when FALSE (true-edge = fall-through); a flip inverts every `If`\n  (`forward_jmpf_builds_an_if_diamond`, `forward_jmpf_with_unconditional_backedge_builds_a_loop`, and\n  `backward_jmpt_builds_a_loop_edge` — a true `JmpT` pin since #4476; it was a misnamed `JmpF` test before).\n- **`rebuild_expression`**: a temp-producing node folds into the *single immediately-next live* consumer\n  (`count_constant_id`: 0 → advance, 1 → inline, >1 → `ExpressionRebuildFailed`); folding into a non-adjacent\n  consumer reorders side effects. It runs over a linked live-index chain, not restart-at-0\u002F`Vec::remove`\n  (O(n²), #2024 — `rebuild_expression_is_linear_up_to_the_wire_format_ceiling`). `is_final` vs `is_temp_var`\n  asymmetry (`::temp` prefix, `_var` suffix) is a deliberate Champollion port — unifying them is a regression.\n  `replace_constant_id`'s `debug_assert!(slot.is_none())` is debug-only: a release >1-match would silently\n  drop the producer.\n- **Depth is memoized on `Node`** (`Node::depth`, `recompute_depth`) and checked at every fold against\n  `MAX_EXPR_DEPTH` (= the papyrus parser constant), so repeated re-folds by the boolean\u002Fcontrol-flow passes\n  cannot reset the ledger (the SIGABRT class); guards `a_temp_chain_past_the_depth_cap_is_declined_not_aborted`\n  \u002F `..._inside_the_depth_cap_still_folds`. Any new in-place tree mutation must call `recompute_depth`.\n- `create_node`: `Cast` downgrades to `Copy` only when source is `None`, same-typed identifiers, or\n  `::nonevar` (case-insensitive) — a wrong downgrade turns a narrowing cast into an identity copy. Operand\n  order for `CallMethod`\u002F`CallStatic`\u002F`CallParent` (result\u002Fobject\u002Fmethod indices) is what recognizers key\n  on (`SetStage`, `GetStageDone`); cross-check UESP. `id_of` on a literal → `ExpectedIdentifier`, never\n  `unwrap()` outside a checked branch. Bodyless\u002Fnative functions decompile to an empty body.\n**Output**: `\u002Ftmp\u002Faudit\u002Fpapyrus\u002Fdim_2.md`\n\n### Dimension 3: Decompiler — Boolean, Control-Flow, Lower & the Corpus Instruments\nPaths: `crates\u002Fpex\u002Fsrc\u002Fdecompile\u002F{boolean,control_flow,lower,event_names,mod}.rs`, `crates\u002Fpex\u002Fexamples\u002Fpex_corpus_smoke.rs`\nFirst step: `cargo test -p byroredux-pex -- decompile::`; with game data: `cargo run --release -p byroredux-pex --example pex_corpus_smoke -- \u003CSkyrim - Misc.bsa> \u003CFallout4 - Misc.ba2>`\n- **Pass order is load-bearing**: `lower::decompile_body` runs cfg → lift → `rebuild_boolean_operators` →\n  `reconstruct` → `lower_body`; the boolean pass precedes control-flow so `&&`\u002F`||` chains collapse first.\n- **`control_flow.rs`**: shape classification (While: `last.next == current`; If: `last.next == exit`; If\u002FElse;\n  jmpt inversion negates + swaps edges). A conditional-predecessor `last` (`||` shape the boolean pass should\n  have collapsed) **fails closed** (`ControlFlowFailed`, #1732; `conditional_predecessor_fails_closed`) —\n  a fix that resumes past the block drops statements. The module doc now says \"declined with an error, not\n  advanced past\" (#4115 `18ce09bff`); wording that drifts back is doc rot.\n- **Bookkept Champollion departures** — `boolean.rs`'s two (plus a third, newer guard below). `lower.rs`'s `is` → object-typed\n  `Cast` departure (#4477) is closed: opcode 36 lowers to `Expr::Is` (#5443 `24f199587`, `an_is_opcode_lowers_to_an_is_expression`).\n  For the **`boolean.rs`** two — adjudicate benign-or-bug, evidence = corpus rate +\n  fidelity gate, not speculation: (1) no debug-line guard (a same-named temp on a fall-through edge could be\n  falsely collapsed into a fabricated `&&`\u002F`||`); (2) termination guard (only re-process on a real merge —\n  infinite loop hangs the decompiler). A declined collapse resumes `rebuild` at the operand range's END, not\n  its first block (#5877 `32352592f` — every nested body was re-walked once per enclosing level, O(2^depth):\n  a 656-byte `.pex` took 6.6 s; `deeply_nested_ifs_are_walked_once_not_exponentially`). `&&` true edge falls through, `||` false edge; operand must recompute\n  the same condition variable; prec `&&`=7\u002F`||`=8; `take_operand` leaves no dangling `None`.\n  **Private-edge guard** (`944d0299e`): a fold deletes the operand block (and a non-exit rejoin), so it\n  declines unless `incoming(operand) == 1` and, for an interior rejoin, `incoming(rejoin) == 2` — a shared\n  `return` epilogue that an early-exit `jmp` also targets left a dangling edge and failed `reconstruct` (the\n  last two corpus decompile failures: FO4 `StimBoxScript`, FO76 `Debug.TraceLog`; corpus now 100% on all four\n  games). The in-edge counts are built once and kept exact by `link`\u002F`unlink` at `collapse`'s three CFG\n  mutations (#5879 `32352592f` — a per-fold whole-CFG scan was O(B²); `in_edge_counts_survive_and_or_and_epilogue_folds`\n  compares them to a recount). Pins `or_whose_rejoin_is_a_shared_epilogue_is_left_uncollapsed`, `and_whose_rejoin_is_a_shared_epilogue_is_left_uncollapsed`. A new\n  fold that deletes a block, or a new CFG mutation that skips `link`\u002F`unlink`, is the regression.\n- **Recursion**: `MAX_REBUILD_DEPTH = 1024` in `control_flow.rs` (`boolean.rs` derives it — not restated);\n  both rebuilds return `RecursionLimit` (`rebuild_rejects_excessive_recursion_depth` exists in *both* files).\n  It and `MAX_EXPR_DEPTH` (256) compose additively (~1,280) and independent edits erode the margin\n  (#4113 still open, verified 2026-11-09) — check any change to either constant.\n- **`lower.rs` totality**: `lower_expr`\u002F`lower_stmt` never panic on any `NodeKind`; intentional lossy lowerings\n  matter only if a recognizer keys on the lost info: statement-shaped node as sub-expression → `NoneLit`\n  (should be unreachable), `is` → `Cast`, `lower_binary_op` default arm →\n  `Eq` (a real unknown op silently becomes `==`). `StructCreate` is no longer lossy: it lowers to\n  `Expr::NewStruct` (FO4 `new S`, the shape the `.psc` parser now emits too).\n  **Locals**: `lower_local_decls` prepends one bare `VarDecl` per non-temp local ahead of the body\n  (`0c6fe4d34` — without it every Champollion fragment prologue read as an assignment to an undeclared name and\n  the #5638 fragment guard declined it; `user_locals_are_declared_ahead_of_the_body_and_temporaries_are_not`).\n  \"Temp\" is Champollion `isTempVar` (`::temp` + a suffix, not ending `_var`, or `::nonevar`) — `lower.rs` now\n  calls `node.rs`'s `is_temp_var` (#6262 `475004d25`; the private case-insensitive copy it replaced left a local the\n  lift keeps as real, `::TEMP1` or a bare `::temp`, undeclared; a second predicate reappearing is the regression;\n  `user_locals_are_declared_ahead_of_the_body_and_temporaries_are_not`) — and is\n  NOT every `::` name: the compiler's `::mangled_\u003Cname>_\u003Cn>` user locals must be declared (#5880 `32352592f`,\n  ~280 vanilla functions declined under the old `::` filter).\n- **Script assembly**: FO4+ `struct_infos` lower to `ScriptItem::Struct` items first (members keep their stored\n  defaults; `pex_corpus_smoke`'s expected-item-count adds `struct_infos.len()`); synthetic `::` variables\n  dropped; variable and auto-property defaults lower to `initial_value` via `default_literal` (the backing\n  variable's stored default); the object's `conditional`\u002F`hidden`\u002F`default` user\n  flags (bit indices named by the file's own user-flag table, resolved ONCE per `Pex` by\n  `UserFlagMasks::from_pex` — #5683 `d8b1d333c`, the old per-variable *has_user_flag* rescan was O(F×V), ~18 s on\n  an 852 KB hostile file, `a_hostile_user_flag_table_decompiles_in_linear_time`; `flag_index \u003C 32` guards the\n  shift on untrusted bytes) lower into the same `ScriptFlags` the `.psc` header parses, a\n  variable's `conditional` into `is_conditional` (#5398 `ce90b481c`, `object_user_flags_lower_into_script_flags`;\n  struct members through the same table, `struct_member_user_flags_lower_into_variable_flags`)\n  and a property's `const`\u002F`mandatory`\u002F`hidden`\u002F`conditional` into `PropertyFlags` (#5685 `f7afb0e07`,\n  `property_user_flags_lower_into_property_flags`) — from the property's user bits OR its auto backing\n  variable's, plus the backing variable's `const_flag` → `CONST` (#5882 `958c26c4e`: vanilla tables never name\n  `const` and `Auto Const`\u002F`Auto Conditional` bits live on the backing variable, Champollion `writeProperty`;\n  ~22.5k FO4 \u002F 24.5k Starfield `Auto Const` once lowered bare). The backing variable is found via one\n  per-object map, not a per-property scan (the hostile linear-time test covers 65,535 auto properties, #5878);\n  **script scope = the empty-named state's functions**;\n  every named state → a `State` item; exactly one (the first case-insensitive `is_auto_state` match against\n  `auto_state_name`) is `is_auto` (#4473, `case_colliding_state_names_mark_exactly_one_auto`) — keying scope on the auto match inverted 983 vanilla scripts (#4319;\n  `named_auto_state_stays_an_auto_state_and_the_empty_state_is_script_scope`). Event iff (`on`-prefixed AND\n  `is_event_name`) OR `::remote_`-prefixed; `EVENT_NAMES` is a sorted lowercase union binary-searched\n  (`list_is_sorted_for_binary_search`); a missing engine event demotes a handler to a function. The list is a\n  documented **superset** of Champollion's frozen `EventNames.hpp`: 12 real engine events it omits\n  (`OnAttach`, `OnStoryClearLocation`, ten Starfield) are hand-added in sorted position from a base-class\n  corpus census (#4471 `0611cd116`; `the_census_engine_events_classify_as_events`, which also keeps vanilla\n  typos like `oncelldetatch` out) — an addition needs the same census evidence, not a guess.\n- **The decompile-rate claim measures robustness, not fidelity.** `pex_corpus_smoke` counts `Err` and\n  panics as failures, tallies after `decompile_script`, and exits non-zero on any decompile `Err`, panic or shape\n  mismatch, not only parse failures (#5883 `958c26c4e`) — verify that gate still holds. Its shape check must not share an\n  implementation rule with the code under test — the #3017 check and `decompile_script` shared the wrong\n  auto-state rule and both agreed on 983 mis-assembled scripts. Fidelity evidence is the `.psc`-vs-`.pex`\n  gate (owned by `\u002Faudit-scripting` Dim 1: `recognizes_da10_and_reproduces_hand_builder` +\n  `da10_pex_reproduces_hand_builder_byte_for_byte`), not the corpus rate.\n**Output**: `\u002Ftmp\u002Faudit\u002Fpapyrus\u002Fdim_3.md`\n\n### Dimension 4: `.psc` Lexer & Pratt Parser (untrusted: `.psc` files and console\u002Fdebug text)\nPaths: `crates\u002Fpapyrus\u002Fsrc\u002F{token,lexer,ast,error,lib}.rs`, `crates\u002Fpapyrus\u002Fsrc\u002Fparser\u002F{mod,expr,stmt,script}.rs`\nFirst step: `cargo test -p byroredux-papyrus -- depth chain the_two_parser_depth_caps_stay_equal`\n- **Depth caps** (stack overflow *and* AST `Drop` recursion): `MAX_EXPR_DEPTH = 256` (`expr.rs`) and\n  `MAX_STMT_DEPTH = 256` (`stmt.rs`), both `pub`, equality pinned by `the_two_parser_depth_caps_stay_equal`;\n  downstream `MAX_CONDITIONAL_DEPTH` and `lift.rs`'s cap alias them. The Pratt loop **charges `expr_depth`\n  for each node a postfix\u002Fbinary chain wraps** (#4320 — the cap once counted only recursive calls, so\n  `a.a.a…` of ~0.4 MB overflowed on Drop) and restores on **every** exit including error paths\n  (`long_postfix_and_binary_chains_hit_the_depth_cap`, `realistic_chains_still_parse_and_release_their_depth`,\n  `depth_resets_between_top_level_calls`). All recursive expression entry funnels through `parse_expr_bp`.\n- **Newline is a terminator in the Pratt loop**: the loop uses `peek_raw()`, not the newline-skipping\n  `peek()` (#4321 — a line opening with `(` was glued to the previous statement, a silent wrong AST). Explicit\n  `\\` continuations are a logos skip rule in `lexer.rs` (#5881 `af4a68ad7` — no pre-pass; the `;` comment callback owns a trailing `\\`); an operator ending a line still continues. Verify\n  every other `peek()` on a statement boundary: #4472 (six sites, via `check_raw`) and #4763 (seven more —\n  `Extends`, variable\u002Ffunction\u002Fgroup flags, property and local initializers) moved construct-continuation\n  decisions to the raw stream, each pinned by an `*_on_the_next_line_*` test in `script.rs` plus\n  `single_line_forms_of_the_4763_sites_still_parse`. Remaining `peek()`\u002F`check()` sites should sit behind an\n  explicit `skip_newlines()` or a bracket-bounded list. `expect()` \u002F `expect_ident()` still skip newlines, so\n  a keyword's **mandatory operand** goes through `expect_same_line` \u002F `expect_raw` \u002F `expect_ident_raw`\n  (`parser\u002Fmod.rs`; #5021, `3b7ffa670`): declaration names, the `Extends` target, the `(` after a function\n  name, `State` after `Auto`, the If\u002FElseIf\u002FWhile condition start, `New`'s type and `[` — #5331 `fd5aa4ead`,\n  `parse_new_expr`; the `[` is optional only for an `Object` type, where a same-line `new S` is FO4's\n  `Expr::NewStruct` — the type operand of `as` \u002F `is` (#5445 `cc3f80e55`, `parse_cast`\u002F`parse_is`; `x as` then `Actor` on the next line once parsed clean), and every segment after a qualified name's `:` (`parse_qualified_ident` → `expect_ident_raw`,\n  #5885 `3081d23f2`: ScriptName\u002FExtends\u002FImport\u002Fevent sender\u002Ftypes; `a_namespaced_parent_on_the_next_line_is_still_not_the_parent`) — pinned by\n  `a_mandatory_operand_on_the_next_line_is_an_error`, `auto_on_its_own_line_does_not_make_an_auto_state`,\n  `extends_with_its_target_on_the_next_line_sets_no_parent`, `single_line_forms_of_the_5021_sites_still_parse`.\n  Only closing keywords may keep the newline-skipping `expect`; a new declaration keyword that uses it is the\n  regression.\n- **Statement termination** (#5322 `a5c3f2428`): `expect_eol` (`parser\u002Fmod.rs`) used to accept ANY token after a\n  statement, so a tail the Pratt loop stopped at re-parsed as a new statement (`If f is Actor` became a\n  truthiness test plus a fabricated `VarDecl`) with zero errors. It now records a recovered `UnexpectedToken` for\n  anything but Newline\u002FEOF\u002FDocComment and skips to line end via `skip_to_line_end`, which leaves block terminators\n  (`EndIf`, `Else*`, `End*`) unconsumed so a glued `x = 1 EndIf` still closes its block\n  (`glued_statement_tail_is_an_error_and_not_a_statement`; `EndStruct` \u002F `EndGroup` stay too, #5444 `3efa1c024`,\n  `glued_struct_and_group_terminators_stay_for_their_container`); `parse_expr` (debug console, offline preflight) ends in\n  `require_input_end` (`parse_expr_rejects_trailing_tokens`). FO4 `is` is a keyword with an `Expr::Is` type-test\n  node at cast precedence (`test_is_type_test`); downstream exhaustive matches treat it as transparent to the operand\n  (the `.pex` side lowers `OpCode::Is` to the same `Expr::Is`, #5443; the VM evaluates it as the operand's truthiness).\n- **Doc comments and FO4 names** (`e96d687ec`): Papyrus puts an item's `{…}` doc on the line AFTER its header, so\n  `take_trailing_doc` (`parser\u002Fmod.rs`) consumes one right after each header's `expect_eol` (script header,\n  property, group, struct + member, function\u002Fevent; #5325 — a bodied function's doc once became its first\n  \"statement\" and the function was dropped). `expect_eol` accepts a `{doc}` terminator only when it ends the\n  line (#5886 `3081d23f2`, `a_same_line_doc_comment_cannot_share_its_line_with_the_next_item`). There is no\n  leading-doc fallback: a top-level `{lead}` is discarded, and inside State\u002FGroup\u002Faccessor containers it is a\n  parse error (#5890 `d148cd27b`, `a_leading_doc_comment_attaches_to_nothing`). Script name, `Extends` target and\n  `Import` are qualified idents (`DLC01:Foo`); a remote event `Event Sender.Event(…)` (#5328) is normalised to\n  the compiler's `Sender_Event` spelling — what the `.pex` frontend yields and the VM's remote matcher binds,\n  while a consumer matching the script's own `OnDeath` does not (#5887 `3081d23f2`,\n  `remote_event_handlers_parse_with_their_sender_in_the_name`). `Parent` is a legal name only as a struct-member\n  declaration or after `.` (#5888, `parent_is_a_legal_member_name`; the F4SE corpus test's `KNOWN_GAPS` is now\n  empty) — via `expect_member_name`, NOT the shared `keyword_as_ident` table: #5888 first put it there and a\n  local\u002Fparameter named `Parent` then declared fine and parsed every use as `ParentAccess` (#6263 `a87650237`,\n  `parent_is_not_a_local_or_parameter_name`; `parse_variable_body(struct_member)` carries the distinction). Pins\n  `a_doc_comment_after_a_bodied_function_header_documents_it`, `namespaced_script_name_parent_and_import_keep_every_segment`.\n- **Precedence\u002Fassociativity**: `BinaryOp::precedence` Or=1, And=2, comparisons=3, Add\u002FSub\u002FStrCat=4,\n  Mul\u002FDiv\u002FMod=5, unary=6, cast=7\u002Fpostfix=8 (`PREC_*` in `expr.rs`); left-assoc hinges on `op_prec \u003C= min_bp →\n  break`. (Bethesda's inverted CTDA OR\u002FAND precedence is a *condition-evaluation* concern in\n  `\u002Faudit-scripting` Dim 3 — `.psc` operators are standard.)\n- **Line continuation** (#5881): a `\\` followed by blanks \u002F a `;` comment \u002F `\\n`, `\\r\\n` or lone `\\r` is one skip rule, so\n  spans index the caller's own text with no offset map (#5884 `af4a68ad7` — *preprocess*\u002F*OffsetMap* are gone;\n  `spans_after_a_continuation_are_original_offsets`, `ast_spans_stay_in_original_coordinates_after_a_continuation`);\n  a trailing `\\` at EOF is emitted, not swallowed. Unterminated `;\u002F` block comments, `{` docs and string literals\n  are `LexError`s, not a silent swallow to EOF (#5889 `af4a68ad7`, `unterminated_block_comment_string_and_doc_are_lex_errors`). Keywords are\n  `ignore(case)` (logos 0.16 dropped *ascii_case*, `15a6b1d2d` — Unicode folding, which differs only for the few\n  non-ASCII letters that fold onto ASCII, e.g. U+017F, U+212A, invalid Papyrus either way) and win over the\n  `Ident` regex. CK flags matched **contextually** stay out of the lexer: `Default` (script header) and\n  `Collapsed` (group) are identifiers checked in their flag position (#5398 `ce90b481c`,\n  `default_and_collapsed_remain_identifiers`) — expressions accept only `Token::Ident`, so promoting either to a\n  keyword breaks every variable of that name. Lone CR is a line terminator and CRLF one `Newline`\n  (`bare_cr_is_a_newline_and_crlf_is_one_newline`, #4479 — a CR-only file once lexed to zero newlines); a `;`\n  line comment likewise stops at the first `\\r` *or* `\\n` (`line_comment_ends_at_a_bare_cr`, #5019 `a75c7dc33` —\n  it once searched only `\\n`, swallowing a CR-only file to EOF with zero errors);\n  `0x` and exponent shapes route through `MalformedNumber` to a `LexError`, not an adjacent token pair.\n- **Recovery**: `parse_script` returns `Ok((Script, Vec\u003CParseError>))` for partial success and `Err` only for\n  fatal; `skip_to_next_line` always consumes ≥1 token (no infinite loop); callers needing strict-fail check\n  `result.1.is_empty()`. No `unwrap()` on `str::parse` of a malformed-but-lexable literal.\n**Output**: `\u002Ftmp\u002Faudit\u002Fpapyrus\u002Fdim_4.md`\n\n## Phase 3: Merge\n\nCombine `\u002Ftmp\u002Faudit\u002Fpapyrus\u002Fdim_*.md` into `docs\u002Faudits\u002FAUDIT_PAPYRUS_\u003CTODAY>.md`: **Executive Summary**\n(findings by severity; **untrusted-input robustness verdict** — can a hostile `.pex`\u002F`.psc` panic, OOB, OOM,\nor stack-overflow the cell loader \u002F console — must be NO; **decompile-rate verdict** — re-measured, and what\nit does and does not prove) · **Decompiler Soundness Matrix** (reader \u002F cfg \u002F lift+copy-prop \u002F boolean \u002F\ncontrol-flow \u002F lower \u002F `.psc` parser × bounds-safe, terminates, total, fidelity-tested; the three Champollion\ndepartures adjudicated) · **Findings** (severity order, deduplicated). Cross-audit: recognizer\u002Fruntime →\n`\u002Faudit-scripting`; `.pex` bytes reaching the extender preflight → `\u002Faudit-scripting` Dim 7.\n\n## Phase 4: Cleanup\n\n`rm -rf \u002Ftmp\u002Faudit\u002Fpapyrus`; tell the user the report is ready; suggest\n`\u002Faudit-publish docs\u002Faudits\u002FAUDIT_PAPYRUS_\u003CTODAY>.md` (domain label `scripting`).\n",{"description":7,"argument-hint":37},"--focus \u003Cdimensions> --depth shallow|deep","main","6afdb791976ed2c24a6c7e61fcbe0cd1f8776061",".claude\u002Fcommands\u002Faudit-papyrus",6,"https:\u002F\u002Fgithub.com\u002Fmatiaszanolli\u002FByroRedux","https:\u002F\u002Fgithub.com\u002Fmatiaszanolli","matiaszanolli.com","15+ years turning mate into code, and just getting started! All things Python and data lover overall. Music addict, always looking to unite music and tech.","2026-11-15 04:03:52",{"source":8,"skillName":5,"commands":48,"prompt":58,"zipAvailable":59},[49,52,55],{"tool":50,"command":51},"npx","npx skills add matiaszanolli\u002FByroRedux --skill audit-papyrus",{"tool":53,"command":54},"bunx","bunx skills add matiaszanolli\u002FByroRedux --skill audit-papyrus",{"tool":56,"command":57},"pnpm","pnpm dlx skills add matiaszanolli\u002FByroRedux --skill audit-papyrus","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fmatiaszanolli\u002FByroRedux\u002Fblob\u002Fmain\u002F.claude\u002Fcommands\u002Faudit-papyrus\u002FSKILL.md",true,[],[62,71,80,89,98,106],{"skillNo":63,"name":64,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":32},"01M6K028GPYDYZ5441BW6YDFNK","trace-flow","https:\u002F\u002Fgithub.com\u002Fmatiaszanolli\u002FByroRedux\u002Fblob\u002Fmain\u002F.zcode\u002Fcommands\u002Ftrace-flow\u002FSKILL.md",[],[68,69,70],"trace flow","trace","flow",{"skillNo":72,"name":73,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":74,"categories":75,"keywords":76,"publishedAt":32},"01M6K026GTTXBBXXCH09SDRNX6","session-close","https:\u002F\u002Fgithub.com\u002Fmatiaszanolli\u002FByroRedux\u002Fblob\u002Fmain\u002F.zcode\u002Fcommands\u002Fsession-close\u002FSKILL.md",[],[77,78,79],"close","session close","session",{"skillNo":81,"name":82,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":32},"01M6K024KA1JFTV7BGYFSZV2VV","legacy-lookup","https:\u002F\u002Fgithub.com\u002Fmatiaszanolli\u002FByroRedux\u002Fblob\u002Fmain\u002F.zcode\u002Fcommands\u002Flegacy-lookup\u002FSKILL.md",[],[86,87,88],"lookup","legacy lookup","Legacy",{"skillNo":90,"name":91,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":92,"categories":93,"keywords":94,"publishedAt":32},"01M6K022H36BJ35KB6MT2NHVH6","fix-issue","https:\u002F\u002Fgithub.com\u002Fmatiaszanolli\u002FByroRedux\u002Fblob\u002Fmain\u002F.zcode\u002Fcommands\u002Ffix-issue\u002FSKILL.md",[],[95,96,97],"issue","fix","fix issue",{"skillNo":99,"name":100,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":101,"categories":102,"keywords":103,"publishedAt":32},"01M6K0208JHG4WDJX143YKFF0W","audit-ui","https:\u002F\u002Fgithub.com\u002Fmatiaszanolli\u002FByroRedux\u002Fblob\u002Fmain\u002F.zcode\u002Fcommands\u002Faudit-ui\u002FSKILL.md",[],[104,105,19],"audit ui","ui",{"skillNo":107,"name":108,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":109,"categories":110,"keywords":111,"publishedAt":32},"01M6K01XPHAPHF9BPS4CG5DDWX","audit-tooling","https:\u002F\u002Fgithub.com\u002Fmatiaszanolli\u002FByroRedux\u002Fblob\u002Fmain\u002F.zcode\u002Fcommands\u002Faudit-tooling\u002FSKILL.md",[],[19,112,113],"audit tooling","tooling"]