fix: parse_chained_command must isolate the failing sub-command, not parts[0] #24
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem Statement
learnings/capture.rs::parse_chained_commandalways returnsparts[0]as the failing sub-command, regardless of which sub-command actually failed. The current implementation has an explicit TODO marker:This contradicts the learning-capture interview spec (
docs/specifications/learning-capture-specification-interview.mdlines 25-26 and 162-180), which mandates: "Splitcmd1 && cmd2into separate learning documents whencmd2fails. Each sub-command gets its own capture." The spec example shows that fordocker compose up -d && npm run migratefailing onnpm run migrate, the captured learning must recordcommand: npm run migrate, notdocker compose up -d.Today's behaviour produces wrong KG entity annotations and wrong correction suggestions for any chained command that fails after the first step -- the most common case for build-test-deploy chains.
Acceptance Criteria
parse_chained_command(command, exit_code)accepts the exit code AND optional position/stderr-line hints, and isolates the actual failing sub-command:&&chains: failing sub-command is the last one that ran (inferred from stderr line context where available, otherwise documented as "best-effort: last sub-command in chain")||chains: failing sub-command is the last one that ran (whole chain failed only if all failed);chains: failing sub-command is whichever the captured stderr most strongly references; fall back to lastfailing_subcommand_index: Option<usize>to the return type so the markdown writer can emitfailed_at: position Ncapture_failed_commandcallsite to use the richer return type and emitfailed_atin the markdown frontmatterparse_chained_commanddoc comment with the "best-effort" caveatcmd1 && cmd2(cmd2 fails),cmd1 || cmd2(cmd1 fails, cmd2 also fails),cmd1; cmd2; cmd3(cmd3 fails), pipe-split commands ignored (pipes are not chains for this purpose), single-command (no chain) still returns(command, None)cargo test -p terraphim_agent --features learn capture::parse_chained_commandpasses (no env vars; pure function)cargo clippy -p terraphim_agent --features learn -- -D warningspassesProposed Approach
terraphim_agent(learnings/capture.rsonly)find_failing_subcommand(parts, error_output) -> Option<usize>that scores each sub-command by stderr-substring overlap (use.split_whitespace().next()to pick the program name, thenerror_output.contains(prog))Dependencies
None. Self-contained pure-function refactor with tests.
Verification
Scope
Single PR, ~120-180 lines (helper ~50, callsite update ~10, tests ~80, doc ~10). Pure correctness fix; no public API churn beyond the function's own return type.