feat(code-review): integrate fallow structural pre-pass for /gsd-code-review (#3424)
* feat(code-review): add optional fallow structural pre-pass * fix(ci): sync lockfile for fallow optional binaries * fix(test): make fallow integration tests cross-platform * fix(review): require executable fallow binary paths * docs(review): clarify structural findings usage and size guard * fix(fallow): preserve line:0, prefer node_modules/.bin, sync SDK twin (H1, M2, N1 from #3424 review) * fix(workflow): harden fallow pre-pass — exit check, timeout, atomic write, size-guard order (B1, H2-H4, M1, M3 from #3424 review) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(deps): pin fallow floor to ^2.70.0 matching lockfile (H7 from #3424 review) * fix(config): enum-validate fallow.scope/profile + group code_quality.* contiguously (H5, N3 from #3424 review) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * docs(fallow): label mcp gate reserved, version-pin install, expand context schema (B3, H8, M4, M8, L1 from #3424 review) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * test(fallow): replace source-grep with behavioral tests, expand fixtures, fail-loud tmpdir (B4, H6, L2, L3, M5, M6, N2 from #3424 review) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(workflow): escape closing structural_findings tag in JSON payload (CR #3424 inline finding) --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -43,6 +43,10 @@ const VALID_CONFIG_KEYS = new Set([
|
||||
'workflow.security_block_on',
|
||||
'workflow.drift_threshold',
|
||||
'workflow.drift_action',
|
||||
'code_quality.fallow.enabled',
|
||||
'code_quality.fallow.scope',
|
||||
'code_quality.fallow.profile',
|
||||
'code_quality.fallow.mcp',
|
||||
'ship.pr_body_sections',
|
||||
'git.branching_strategy', 'git.base_branch', 'git.phase_branch_template', 'git.milestone_branch_template', 'git.quick_branch_template',
|
||||
'planning.commit_docs', 'planning.search_gitignored', 'planning.sub_repos',
|
||||
|
||||
@@ -442,6 +442,16 @@ function cmdConfigSet(cwd, keyPath, value, raw) {
|
||||
error(`Invalid workflow.human_verify_mode '${value}'. Valid values: ${VALID_HUMAN_VERIFY_MODES.join(', ')}`);
|
||||
}
|
||||
|
||||
// Fallow scope + profile enum validation (#3424)
|
||||
const VALID_FALLOW_SCOPES = ['phase', 'repo'];
|
||||
if (keyPath === 'code_quality.fallow.scope' && !VALID_FALLOW_SCOPES.includes(String(parsedValue))) {
|
||||
error(`Invalid code_quality.fallow.scope '${value}'. Valid values: ${VALID_FALLOW_SCOPES.join(', ')}`);
|
||||
}
|
||||
const VALID_FALLOW_PROFILES = ['minimal', 'standard', 'strict'];
|
||||
if (keyPath === 'code_quality.fallow.profile' && !VALID_FALLOW_PROFILES.includes(String(parsedValue))) {
|
||||
error(`Invalid code_quality.fallow.profile '${value}'. Valid values: ${VALID_FALLOW_PROFILES.join(', ')}`);
|
||||
}
|
||||
|
||||
if (keyPath === 'review.default_reviewers') {
|
||||
const normalized = normalizeConfiguredDefaultReviewers(parsedValue);
|
||||
if (normalized.errors.length > 0) {
|
||||
|
||||
109
get-shit-done/bin/lib/fallow-runner.cjs
Normal file
109
get-shit-done/bin/lib/fallow-runner.cjs
Normal file
@@ -0,0 +1,109 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
function candidateNames() {
|
||||
return process.platform === 'win32'
|
||||
? ['fallow.exe', 'fallow.cmd', 'fallow.bat', 'fallow']
|
||||
: ['fallow'];
|
||||
}
|
||||
|
||||
function isExecutableFile(filePath) {
|
||||
try {
|
||||
const stat = fs.statSync(filePath);
|
||||
if (!stat.isFile()) return false;
|
||||
if (process.platform === 'win32') return true;
|
||||
fs.accessSync(filePath, fs.constants.X_OK);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function findInPath(envPath) {
|
||||
if (!envPath) return null;
|
||||
const names = candidateNames();
|
||||
const segments = envPath.split(path.delimiter).filter(Boolean);
|
||||
for (const segment of segments) {
|
||||
for (const name of names) {
|
||||
const candidate = path.join(segment, name);
|
||||
if (isExecutableFile(candidate)) return candidate;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function findInNodeModules(cwd) {
|
||||
const names = candidateNames();
|
||||
const binDir = path.join(cwd, 'node_modules', '.bin');
|
||||
for (const name of names) {
|
||||
const candidate = path.join(binDir, name);
|
||||
if (isExecutableFile(candidate)) return candidate;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function resolveFallowBinary({ cwd, envPath = process.env.PATH || '' }) {
|
||||
return findInNodeModules(cwd) || findInPath(envPath) || null;
|
||||
}
|
||||
|
||||
function requireFallowBinary({ cwd, envPath = process.env.PATH || '' }) {
|
||||
const binary = resolveFallowBinary({ cwd, envPath });
|
||||
if (binary) return binary;
|
||||
throw new Error(
|
||||
'Fallow is enabled but no binary was found. Please install fallow via `npm install -D fallow` or `cargo install fallow`.',
|
||||
);
|
||||
}
|
||||
|
||||
function normalizeFallowReport(report) {
|
||||
const unused = Array.isArray(report?.unusedExports) ? report.unusedExports : [];
|
||||
const duplicates = Array.isArray(report?.duplicates) ? report.duplicates : [];
|
||||
const circular = Array.isArray(report?.circularDependencies) ? report.circularDependencies : [];
|
||||
|
||||
const findings = [];
|
||||
|
||||
for (const item of unused) {
|
||||
findings.push({
|
||||
type: 'unused_export',
|
||||
message: `Unused export ${item.symbol || '<unknown>'}`,
|
||||
file: item.file || '',
|
||||
line: item.line ?? null,
|
||||
});
|
||||
}
|
||||
|
||||
for (const item of duplicates) {
|
||||
findings.push({
|
||||
type: 'duplicate_block',
|
||||
message: `Duplicate block (${Math.round((item.similarity || 0) * 100)}% similarity)`,
|
||||
file: item.left?.file || '',
|
||||
line: item.left?.start ?? null,
|
||||
related_file: item.right?.file || '',
|
||||
});
|
||||
}
|
||||
|
||||
for (const item of circular) {
|
||||
findings.push({
|
||||
type: 'circular_dependency',
|
||||
message: `Circular dependency: ${(item.cycle || []).join(' -> ')}`,
|
||||
file: Array.isArray(item.cycle) && item.cycle.length > 0 ? item.cycle[0] : '',
|
||||
line: null,
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
summary: {
|
||||
unused_exports: unused.length,
|
||||
duplicates: duplicates.length,
|
||||
circular_dependencies: circular.length,
|
||||
total: findings.length,
|
||||
},
|
||||
findings,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
normalizeFallowReport,
|
||||
requireFallowBinary,
|
||||
resolveFallowBinary,
|
||||
};
|
||||
@@ -16,6 +16,7 @@ Agent output guidance for review mode. Loaded when `context: review` is set in c
|
||||
- Performance — unnecessary allocations, O(n^2) patterns, missing caching
|
||||
- Style and consistency — naming, formatting, import order
|
||||
- Test coverage — untested branches, missing assertions, flaky patterns
|
||||
- Structural Findings (fallow) — machine-derived cross-module facts injected as `<structural_findings>{ findings: [...], summary: { total, unusedExports, duplicates, circularDependencies } }</structural_findings>`. Render in REVIEW.md under `## Structural Findings (fallow)` as a separate section from narrative findings. Treat as ground truth for cross-module facts; do not re-derive.
|
||||
|
||||
## Verbosity
|
||||
|
||||
|
||||
@@ -318,6 +318,78 @@ No source files changed in phase ${PHASE_ARG}. Skipping review.
|
||||
Exit workflow. Do NOT spawn agent or create REVIEW.md.
|
||||
</step>
|
||||
|
||||
<step name="structural_pre_pass">
|
||||
Optional structural cross-module pass powered by fallow.
|
||||
|
||||
Read fallow config gates:
|
||||
```bash
|
||||
FALLOW_ENABLED=$(gsd-sdk query config-get code_quality.fallow.enabled 2>/dev/null || echo "false")
|
||||
FALLOW_SCOPE=$(gsd-sdk query config-get code_quality.fallow.scope 2>/dev/null || echo "phase")
|
||||
FALLOW_PROFILE=$(gsd-sdk query config-get code_quality.fallow.profile 2>/dev/null || echo "standard")
|
||||
FALLOW_MCP=$(gsd-sdk query config-get code_quality.fallow.mcp 2>/dev/null || echo "false")
|
||||
```
|
||||
|
||||
Defaults are fail-closed and opt-in:
|
||||
- `enabled=false` (skip entirely)
|
||||
- `scope=phase`
|
||||
- `profile=standard`
|
||||
- `mcp=false`
|
||||
|
||||
When `FALLOW_ENABLED=true`:
|
||||
|
||||
1) Resolve binary via PATH first, then `node_modules/.bin/fallow`.
|
||||
```bash
|
||||
FALLOW_BIN=$(FALLOW_CWD="$(pwd)" node -e "
|
||||
const { resolveFallowBinary } = require('./get-shit-done/bin/lib/fallow-runner.cjs');
|
||||
const resolved = resolveFallowBinary({ cwd: process.env.FALLOW_CWD });
|
||||
if (resolved) process.stdout.write(resolved);
|
||||
")
|
||||
```
|
||||
|
||||
2) If binary is missing, fail with actionable message:
|
||||
```bash
|
||||
if [ -z \"$FALLOW_BIN\" ]; then
|
||||
echo \"Error: fallow is enabled but no binary was found.\"
|
||||
echo \"Install fallow via \`npm install -D fallow\` or \`cargo install fallow\`.\"
|
||||
# Exit workflow
|
||||
fi
|
||||
```
|
||||
|
||||
3) Execute structural pass and persist JSON (bounded at 120s; on timeout, behaves as a fallow crash):
|
||||
```bash
|
||||
FALLOW_JSON_PATH="${PHASE_DIR}/FALLOW.json"
|
||||
FALLOW_STDERR_TMP=$(mktemp)
|
||||
if [ \"$FALLOW_SCOPE\" = \"repo\" ]; then
|
||||
timeout 120 \"$FALLOW_BIN\" audit --json --profile \"$FALLOW_PROFILE\" > \"${FALLOW_JSON_PATH}.tmp\" 2>\"$FALLOW_STDERR_TMP\"
|
||||
FALLOW_EXIT=$?
|
||||
else
|
||||
# phase scope: pass the already-computed review file set
|
||||
printf '%s\n' \"${REVIEW_FILES[@]}\" | timeout 120 \"$FALLOW_BIN\" audit --json --profile \"$FALLOW_PROFILE\" --stdin-files > \"${FALLOW_JSON_PATH}.tmp\" 2>\"$FALLOW_STDERR_TMP\"
|
||||
FALLOW_EXIT=$?
|
||||
fi
|
||||
if [ $FALLOW_EXIT -ne 0 ]; then
|
||||
FALLOW_STDERR_SUMMARY=$(head -5 \"$FALLOW_STDERR_TMP\")
|
||||
rm -f \"${FALLOW_JSON_PATH}.tmp\" \"$FALLOW_STDERR_TMP\"
|
||||
echo \"WARNING: fallow structural pre-pass failed: ${FALLOW_STDERR_SUMMARY}\"
|
||||
FALLOW_JSON_PATH=""
|
||||
else
|
||||
mv \"${FALLOW_JSON_PATH}.tmp\" \"$FALLOW_JSON_PATH\"
|
||||
rm -f \"$FALLOW_STDERR_TMP\"
|
||||
fi
|
||||
```
|
||||
|
||||
On any failure of the structural pre-pass (binary missing, non-zero exit, timeout, or JSON parse error), the workflow continues with no `<structural_findings>` injection; the reviewer agent receives a normal review request.
|
||||
|
||||
4) Optional MCP bridge path (runtime-dependent):
|
||||
- If `FALLOW_MCP=true`, set reviewer input mode to MCP-backed structural findings.
|
||||
- Otherwise pass static JSON findings from `FALLOW.json`.
|
||||
|
||||
When disabled, set:
|
||||
```bash
|
||||
FALLOW_JSON_PATH=""
|
||||
```
|
||||
</step>
|
||||
|
||||
<step name="spawn_reviewer">
|
||||
Compute the review output path:
|
||||
```bash
|
||||
@@ -350,6 +422,22 @@ for file in "${REVIEW_FILES[@]}"; do
|
||||
done
|
||||
```
|
||||
|
||||
Build structural findings block for agent:
|
||||
```bash
|
||||
STRUCTURAL_FINDINGS_BLOCK=""
|
||||
MAX_FINDINGS_SIZE=50000
|
||||
if [ -n "$FALLOW_JSON_PATH" ] && [ -f "$FALLOW_JSON_PATH" ]; then
|
||||
FALLOW_JSON_SIZE=$(wc -c < "$FALLOW_JSON_PATH" | tr -d '[:space:]')
|
||||
if [ "$FALLOW_JSON_SIZE" -le "$MAX_FINDINGS_SIZE" ]; then
|
||||
# Escape any literal closing tag before embedding; the closing tag literal is escaped to prevent prompt-structure breakage if a fallow finding's file path or message contains the sequence.
|
||||
SAFE_FALLOW_JSON=$(sed 's#</structural_findings>#<\/structural_findings>#g' "$FALLOW_JSON_PATH")
|
||||
STRUCTURAL_FINDINGS_BLOCK=$(printf '<structural_findings>\n%s\n</structural_findings>\n' "$SAFE_FALLOW_JSON")
|
||||
else
|
||||
echo "Warning: skipping structural findings embed (${FALLOW_JSON_SIZE} bytes > ${MAX_FINDINGS_SIZE} bytes). Re-run with narrower scope/profile if needed."
|
||||
fi
|
||||
fi
|
||||
```
|
||||
|
||||
Spawn the gsd-code-reviewer agent:
|
||||
|
||||
```
|
||||
@@ -358,6 +446,8 @@ Agent(subagent_type="gsd-code-reviewer", prompt="
|
||||
${FILES_TO_READ}
|
||||
</files_to_read>
|
||||
|
||||
${STRUCTURAL_FINDINGS_BLOCK}
|
||||
|
||||
<config>
|
||||
depth: ${REVIEW_DEPTH}
|
||||
phase_dir: ${PHASE_DIR}
|
||||
|
||||
Reference in New Issue
Block a user