Skip to content

Commit 6944af4

Browse files
nhortonclaude
andcommitted
feat: improve precomputed traceability script layout
- Move diffs to last section with clear separator title - Restructure test stability cross-reference to per-file blocks - Compress new/changed requirements to just added/removed headings - Rename cross-reference labels for brevity Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c9cc05c commit 6944af4

2 files changed

Lines changed: 116 additions & 85 deletions

File tree

.deepwork/requirements_traceability_info.sh

Lines changed: 115 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -114,62 +114,9 @@ if [ -n "$HINTS" ]; then
114114
echo -e "$HINTS"
115115
fi
116116

117-
# ==== Section 2: Diffs by top-level directory ====
117+
# ==== Section 2: Requirement IDs referenced in changed files ====
118118

119-
echo "## 2. Diffs"
120-
echo ""
121-
echo "### Stat"
122-
echo '```'
123-
git diff "${MERGE_BASE}" --stat || true
124-
echo '```'
125-
echo ""
126-
127-
# Get unique top-level directories from changed files
128-
TOP_DIRS=$(echo "$ALL_FILES" | awk -F/ '{ if (NF == 1) print "(root)"; else print $1 }' | sort -u || true)
129-
130-
if [ -n "$TOP_DIRS" ]; then
131-
while IFS= read -r dir; do
132-
[ -z "$dir" ] && continue
133-
134-
if [ "$dir" = "(root)" ]; then
135-
# Root-level files: match files with no slash
136-
ROOT_FILES=$(echo "$ALL_FILES" | grep -v '/' || true)
137-
[ -z "$ROOT_FILES" ] && continue
138-
echo "### ${dir}"
139-
echo '```diff'
140-
# Committed root-level files
141-
while IFS= read -r f; do
142-
git diff "${MERGE_BASE}" -- "$f" 2>/dev/null || true
143-
done <<< "$ROOT_FILES"
144-
# Staged root-level files
145-
(echo "$STAGED" | grep -v '/' 2>/dev/null || true) | while IFS= read -r f; do
146-
[ -n "$f" ] && git diff --cached -- "$f" 2>/dev/null || true
147-
done
148-
# Untracked root-level files
149-
(echo "$UNTRACKED" | grep -v '/' 2>/dev/null || true) | while IFS= read -r f; do
150-
[ -n "$f" ] && [ -f "$f" ] && git diff --no-index /dev/null "$f" 2>/dev/null || true
151-
done
152-
echo '```'
153-
echo ""
154-
else
155-
echo "### ${dir}/"
156-
echo '```diff'
157-
git diff "${MERGE_BASE}" -- "${dir}/**" 2>/dev/null || true
158-
# Staged files in this dir
159-
git diff --cached -- "${dir}/**" 2>/dev/null || true
160-
# Untracked files in this dir
161-
(echo "$UNTRACKED" | grep "^${dir}/" 2>/dev/null || true) | while IFS= read -r f; do
162-
[ -n "$f" ] && [ -f "$f" ] && git diff --no-index /dev/null "$f" 2>/dev/null || true
163-
done
164-
echo '```'
165-
echo ""
166-
fi
167-
done <<< "$TOP_DIRS"
168-
fi
169-
170-
# ==== Section 3: Requirement IDs referenced in changed files ====
171-
172-
echo "## 3. Requirement IDs Referenced in Changed Files"
119+
echo "## 2. Requirement IDs Referenced in Changed Files"
173120
echo ""
174121
echo '```'
175122
IN_PLAY_REQS=""
@@ -198,9 +145,9 @@ if [ -n "$CHANGED_SPECS" ]; then
198145
IN_PLAY_SECTIONS=$(echo -e "${IN_PLAY_SECTIONS}\n${SPEC_SECTIONS}" | sort -u || true)
199146
fi
200147

201-
# ==== Section 4: Files that reference each in-play requirement ====
148+
# ==== Section 3: Files that reference each in-play requirement ====
202149

203-
echo "## 4. Files That Reference Each In-Play Requirement"
150+
echo "## 3. Files That Reference Each In-Play Requirement"
204151
echo ""
205152
echo "Scoped to requirements referenced by changed files or in changed specs."
206153
echo "Check the full repo if you need coverage for other requirements."
@@ -235,9 +182,9 @@ fi
235182
echo '```'
236183
echo ""
237184

238-
# ==== Section 5: Test stability cross-reference ====
185+
# ==== Section 4: Test stability cross-reference ====
239186

240-
echo "## 5. Test Stability Cross-Reference"
187+
echo "## 4. Test Stability Cross-Reference"
241188
echo ""
242189
echo "For each changed test file: which requirements it validates and whether"
243190
echo "those requirements also changed in this branch."
@@ -249,46 +196,132 @@ if [ -n "$CHANGED_SPECS" ]; then
249196
CHANGED_REQ_IDS=$(grep -ohE '[A-Z]+-REQ-[0-9]+(\.[0-9]+)*' ${CHANGED_SPECS} 2>/dev/null | sort -u || true)
250197
fi
251198

252-
echo '```'
253199
if [ -n "$CHANGED_TESTS" ]; then
254-
echo "CHANGED TEST FILE | REFERENCED REQS | REQ ALSO CHANGED?"
255-
echo "--- | --- | ---"
256200
while IFS= read -r test_file; do
257201
[ -z "$test_file" ] || [ ! -f "$test_file" ] && continue
258202
TEST_REQS=$(grep -oE '[A-Z]+-REQ-[0-9]+(\.[0-9]+)*' "$test_file" 2>/dev/null | sort -u || true)
203+
204+
echo "### ${test_file}"
205+
echo ""
206+
259207
if [ -z "$TEST_REQS" ]; then
260-
echo "${test_file} | (none) | n/a"
261-
else
262-
while IFS= read -r req; do
263-
REQ_SECTION=$(echo "$req" | grep -oE '[A-Z]+-REQ-[0-9]+')
264-
if echo "$CHANGED_REQ_IDS" | grep -q "^${req}$" 2>/dev/null || \
265-
echo "$CHANGED_REQ_IDS" | grep -q "^${REQ_SECTION}\." 2>/dev/null; then
266-
echo "${test_file} | ${req} | YES"
267-
else
268-
echo "${test_file} | ${req} | **NO — POTENTIAL VIOLATION**"
269-
fi
270-
done <<< "$TEST_REQS"
208+
echo "Referenced requirements: (none)"
209+
echo ""
210+
continue
211+
fi
212+
213+
# Split into changed and unchanged requirements
214+
CHANGED_LIST=""
215+
UNCHANGED_LIST=""
216+
while IFS= read -r req; do
217+
REQ_SECTION=$(echo "$req" | grep -oE '[A-Z]+-REQ-[0-9]+')
218+
if echo "$CHANGED_REQ_IDS" | grep -q "^${req}$" 2>/dev/null || \
219+
echo "$CHANGED_REQ_IDS" | grep -q "^${REQ_SECTION}\." 2>/dev/null; then
220+
CHANGED_LIST="${CHANGED_LIST} ${req}"$'\n'
221+
else
222+
UNCHANGED_LIST="${UNCHANGED_LIST} ${req}"$'\n'
223+
fi
224+
done <<< "$TEST_REQS"
225+
226+
if [ -n "$CHANGED_LIST" ]; then
227+
echo "With spec changes:"
228+
echo "$CHANGED_LIST"
271229
fi
230+
if [ -n "$UNCHANGED_LIST" ]; then
231+
UNCHANGED_COUNT=$(echo "$UNCHANGED_LIST" | grep -c '[A-Z]' || true)
232+
echo "WITHOUT spec changes (${UNCHANGED_COUNT}):"
233+
echo "$UNCHANGED_LIST"
234+
fi
235+
echo ""
272236
done <<< "$CHANGED_TESTS"
273237
else
274238
echo "(no test files changed)"
239+
echo ""
275240
fi
276-
echo '```'
277241
echo ""
278242

279-
# ==== Section 6: New or changed requirements in this branch ====
243+
# ==== Section 5: New or changed requirements in this branch ====
280244

281-
echo "## 6. New or Changed Requirements in This Branch"
245+
echo "## 5. New or Changed Requirements in This Branch"
282246
echo ""
283-
echo '```'
284247
if [ -n "$CHANGED_SPECS" ]; then
285-
while IFS= read -r spec_file; do
286-
echo "=== ${spec_file} ==="
287-
git diff "${MERGE_BASE}" -- "$spec_file" 2>/dev/null | grep -E '^\+###|^-###' || echo " (no heading changes)"
288-
git diff "${MERGE_BASE}" -- "$spec_file" 2>/dev/null | grep -E '^\+[0-9]+\.|^-[0-9]+\.' | head -20 || true
248+
ADDED_SECTIONS=$(git diff "${MERGE_BASE}" -- ${CHANGED_SPECS} 2>/dev/null | grep -E '^\+###' | sed 's/^\+### //' | sort -u || true)
249+
REMOVED_SECTIONS=$(git diff "${MERGE_BASE}" -- ${CHANGED_SPECS} 2>/dev/null | grep -E '^-###' | sed 's/^-### //' | sort -u || true)
250+
251+
if [ -n "$ADDED_SECTIONS" ]; then
252+
echo "**Added sections:**"
253+
echo '```'
254+
echo "$ADDED_SECTIONS"
255+
echo '```'
256+
echo ""
257+
fi
258+
if [ -n "$REMOVED_SECTIONS" ]; then
259+
echo "**Removed sections:**"
260+
echo '```'
261+
echo "$REMOVED_SECTIONS"
262+
echo '```'
263+
echo ""
264+
fi
265+
if [ -z "$ADDED_SECTIONS" ] && [ -z "$REMOVED_SECTIONS" ]; then
266+
echo "No section headings added or removed (changes were within existing sections)."
289267
echo ""
290-
done <<< "$CHANGED_SPECS"
268+
echo "Changed spec files: ${CHANGED_SPECS}" | tr '\n' ', '
269+
echo ""
270+
fi
291271
else
292272
echo "(no spec files changed)"
293273
fi
274+
echo ""
275+
276+
# ==== Section 6: Diffs (ALL REMAINING CONTENT IS DIFFS) ====
277+
278+
echo "## 6. Diffs (ALL REMAINING CONTENT IS DIFFS)"
279+
echo ""
280+
echo "### Stat"
294281
echo '```'
282+
git diff "${MERGE_BASE}" --stat || true
283+
echo '```'
284+
echo ""
285+
286+
# Get unique top-level directories from changed files
287+
TOP_DIRS=$(echo "$ALL_FILES" | awk -F/ '{ if (NF == 1) print "(root)"; else print $1 }' | sort -u || true)
288+
289+
if [ -n "$TOP_DIRS" ]; then
290+
while IFS= read -r dir; do
291+
[ -z "$dir" ] && continue
292+
293+
if [ "$dir" = "(root)" ]; then
294+
# Root-level files: match files with no slash
295+
ROOT_FILES=$(echo "$ALL_FILES" | grep -v '/' || true)
296+
[ -z "$ROOT_FILES" ] && continue
297+
echo "### ${dir}"
298+
echo '```diff'
299+
# Committed root-level files
300+
while IFS= read -r f; do
301+
git diff "${MERGE_BASE}" -- "$f" 2>/dev/null || true
302+
done <<< "$ROOT_FILES"
303+
# Staged root-level files
304+
(echo "$STAGED" | grep -v '/' 2>/dev/null || true) | while IFS= read -r f; do
305+
[ -n "$f" ] && git diff --cached -- "$f" 2>/dev/null || true
306+
done
307+
# Untracked root-level files
308+
(echo "$UNTRACKED" | grep -v '/' 2>/dev/null || true) | while IFS= read -r f; do
309+
[ -n "$f" ] && [ -f "$f" ] && git diff --no-index /dev/null "$f" 2>/dev/null || true
310+
done
311+
echo '```'
312+
echo ""
313+
else
314+
echo "### ${dir}/"
315+
echo '```diff'
316+
git diff "${MERGE_BASE}" -- "${dir}/**" 2>/dev/null || true
317+
# Staged files in this dir
318+
git diff --cached -- "${dir}/**" 2>/dev/null || true
319+
# Untracked files in this dir
320+
(echo "$UNTRACKED" | grep "^${dir}/" 2>/dev/null || true) | while IFS= read -r f; do
321+
[ -n "$f" ] && [ -f "$f" ] && git diff --no-index /dev/null "$f" 2>/dev/null || true
322+
done
323+
echo '```'
324+
echo ""
325+
fi
326+
done <<< "$TOP_DIRS"
327+
fi

tests/unit/review/test_instructions.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,7 @@ def test_run_precompute_command_uses_project_root_as_cwd(self, tmp_path: Path) -
448448

449449
# THIS TEST VALIDATES A HARD REQUIREMENT (REVIEW-REQ-001.9.6, REVIEW-REQ-001.9.7).
450450
# YOU MUST NOT MODIFY THIS TEST UNLESS THE REQUIREMENT CHANGES
451-
def test_run_precompute_commands_deduplicates_and_parallelizes(
452-
self, tmp_path: Path
453-
) -> None:
451+
def test_run_precompute_commands_deduplicates_and_parallelizes(self, tmp_path: Path) -> None:
454452
script = tmp_path / "echo.sh"
455453
script.write_text("#!/usr/bin/env bash\necho 'output'")
456454
script.chmod(0o755)

0 commit comments

Comments
 (0)