Skip to main content

parse_instruction_component_paths

Function parse_instruction_component_paths 

Source
fn parse_instruction_component_paths(
    arr: &[Value],
    label: &str,
    by_path: &HashMap<String, &str>,
    context_files: &mut Vec<ImportedContextFile>,
    divert_context_files: bool,
    seen_instruction_paths: &mut HashSet<String>,
    duplicate_instruction_refs: &mut u32,
    warnings: &mut WarningSink,
) -> String
Expand description

Parse one components.instructions-shaped path array (either the v0.1 flat array itself, or one key’s array within the v0.2 keyed-object shape) into its joined instructions text. label is used only for warning messages ("instructions" for the flat/default case, "instructions.<provider>" for a variant) so every caller’s warnings are traceable to the specific key that produced them.

seen_instruction_paths/duplicate_instruction_refs are threaded through BY THE CALLER, shared across every invocation within one parse_bundle_import_with_budget call (default + every provider variant) — reagent P1, PR #2523: a HashSet local to each call only dedupes within its own component array, so the same instructions/ context/* path referenced from both "default" and a provider variant was pushed into context_files twice, and — worse — a manifest repeating one path across many provider keys (up to MAX_INSTRUCTION_PROVIDER_VARIANTS) re-opened the exact content-cloning amplification vector the original per-array dedup existed to close (Codex P1, PR #2379 round 2, cited below).

divert_context_files: only true for the flat/default case. reagent P1, PR #2523: diverting any instructions/context/*-prefixed path applies to the raw file path unconditionally, regardless of which provider variant is being parsed — so a provider literally named "context" (whose exported path is instructions/context/AGENTS.md, per bundle_export.rs’s instructions/<provider>/AGENTS.md convention) would have its own content silently misrouted into context_files on a later re-import, a reserved-word collision with no validation guarding it. Context files are shared, not provider-scoped, by design (§1’s naming note) — a provider variant’s array never needs the diversion at all, so disabling it there closes the collision structurally rather than special-casing the “context” name.