reconFTW is a tool designed to perform automated recon on a target domain by running the best set of tools to perform scanning and finding out vulnerabilities
id: 01-01 phase: 01 plan: 01 type: execute wave: 1 depends_on: [] requirements: [RESIL-01] files_modified:
- modules/core.sh
- modules/modes.sh
- modules/utils.sh
autonomous: true
must_haves:
truths:
- "D-01: Sentinel file is a plain empty
${called_fn_dir}/.inprogress_<fn>— when start_func runs for function FN, .inprogress_ exists in called_fn_dir; no PID, no timestamp, no JSON metadata inside" - "D-01: When end_func completes for FN, .inprogress_ is removed BEFORE the existing . success checkpoint touch — preserves crash-safety ordering"
- "D-02: Staleness detection uses trap-on-exit cleanup — when the shell exits (normal, INT, TERM, EXIT), the registered traps clear all .inprogress_* files in called_fn_dir; graceful exits leave NO .inprogress_* files"
- "D-03: No PID liveness checks or staleness windows — the single-operator-per-target constraint (PROJECT.md) makes any leftover .inprogress_* a guaranteed crash-leftover from a prior run, so the trap-only design is sufficient"
- "D-04: When a prior run was killed and the next start() invocation sees one or more .inprogress_ files, exactly ONE WARN summary line names the affected functions (
WARN resume: N functions re-running after interruption (fn_a, fn_b)) and a JSONL event records reason=inprogress_leftover; no per-function RESUME badges" - "D-05: When FORCE_RESCAN=true (PRESERVE=false), the orphan-cleanup loop removes any .inprogress_* alongside the existing . wipe so the resume banner does NOT fire"
- "D-06: Function re-execution on leftover is transparent — the existing checkpoint guard ([[ ! -f $called_fn_dir/. ]]) sees no . (end_func never reached on a crash) and re-enters; the .inprogress_* file does NOT drive control flow"
- "D-02: On graceful (non-signal) exit, the new EXIT-only trap clears .inprogress_* sentinels WITHOUT printing an interruption banner and WITHOUT forcing exit 130 — cleanup_on_exit is unchanged and stays bound to INT/TERM only" artifacts:
- path: "modules/core.sh" provides: "start_func touches .inprogress_; end_func removes .inprogress_ before touching ."
- path: "modules/modes.sh" provides: "separate EXIT-only trap calling _cleanup_inprogress + orphan-cleanup line in FORCE_RESCAN block + resume banner emission in start()"
- path: "modules/utils.sh" provides: "_cleanup_inprogress standalone helper (NOT inside cleanup_on_exit); cleanup_on_exit untouched" key_links:
- from: "modules/core.sh:start_func" to: "$called_fn_dir/.inprogress_" via: "touch with called_fn_dir guard" pattern: "touch "\$called_fn_dir/\.inprogress_"
- from: "modules/core.sh:end_func" to: "$called_fn_dir/.inprogress_" via: "rm -f BEFORE existing touch ." pattern: "rm -f "\$called_fn_dir/\.inprogress_"
- from: "modules/modes.sh:start()" to: "_cleanup_inprogress (via separate EXIT-only trap)" via: "trap '_cleanup_inprogress' EXIT installed immediately after the existing INT/TERM trap" pattern: "trap '_cleanup_inprogress' EXIT"
- "D-01: Sentinel file is a plain empty
Add `.inprogress_` sentinel lifecycle so interrupted runs surface a clear resume indicator and only re-execute the function that was killed mid-run. Closes RESIL-01.
Purpose: Today, end_func writes .<fn> only on clean completion (modules/core.sh:1465). An interrupted function (Ctrl-C, OOM, crash) leaves NO marker, so a PRESERVE=true re-run cannot distinguish "function never ran" from "function crashed mid-run". This plan adds a touch-on-start / remove-on-end sentinel plus trap-based cleanup so leftover sentinels on the next invocation become the resume signal.
Output: start_func/end_func write and clear .inprogress_<fn>; start() in modules/modes.sh installs a separate EXIT-only trap that calls a new lightweight _cleanup_inprogress helper (it clears stale sentinels on graceful exit without any banner, kill, or forced exit code). The existing cleanup_on_exit (modules/utils.sh:116-146) stays bound to INT/TERM only and is NOT modified. FORCE_RESCAN=true adds an explicit .inprogress_* orphan clear and start() emits a one-line resume WARN banner when leftover sentinels are detected from a prior crash.
From modules/core.sh:
- function start_func() — lifecycle entry,
:1419-1435. Body: writes LOGFILE start line, sets_start_time_<fn>per-function timestamp, callslog_json "INFO" "${1}" "Function started" "description=${2}". - function end_func() — lifecycle exit,
:1437-1531. Body order today: case-normalize status (:1442-1463) →touch "$called_fn_dir/.${fn}"(:1465) → timing → badge mapping (:1478-1502) →printf "%s\n" "$badge" >"${called_fn_dir}/.status_${fn}"(:1505-1509) →_print_status(:1512) →log_json "SUCCESS"(:1525). - function log_json() —
:680. Signature:log_json "<LEVEL>" "<function_name>" "<human_message>" "key=value" "key2=value2". No-op when STRUCTURED_LOGGING != true.
From modules/modes.sh:
- function start() —
:13-163. Existing INT/TERM trap at:118:trap 'cleanup_on_exit' INT TERM. Existing FORCE_RESCAN wipe at:78-80:if [[ "${FORCE_RESCAN:-false}" == "true" ]]; then rm -f "$called_fn_dir"/.* 2>>"${LOGFILE:-/dev/null}" || true; fi. Existing rescan banner at:154-156:if [[ "${FORCE_RESCAN:-false}" == "true" ]]; then _print_msg WARN "Force rescan enabled: ignoring cached module markers"; fi. Existing tools_installed call at:160.
From modules/utils.sh:
- function cleanup_on_exit() —
:116-146. UNCHANGED in this plan. Currently registered for INT/TERM only. Body unconditionally prints "Interrupted. Cleaning up..." in red, kills tracked PIDs (jobs -p,INTERACTSH_PID), and callsexit "$exit_code"where exit_code defaults to 130. Firing it on EXIT would break every successful scan (red banner + forced exit 130). This plan therefore registers a SEPARATE EXIT-only trap pointing at a new lightweight_cleanup_inprogresshelper, and DOES NOT modify cleanup_on_exit.
From lib/common.sh:
- _print_msg() —
:342. Usage:_print_msg WARN "message". - _print_error() —
:528. Always-visible stderr error.
In end_func (line 1437): insert `if [[ -n "${called_fn_dir:-}" ]]; then rm -f "$called_fn_dir/.inprogress_${fn}" 2>/dev/null || true; fi` IMMEDIATELY BEFORE the existing `touch "$called_fn_dir/.${fn}"` at :1465. The ordering rationale (per D-06 / PATTERNS.md): a crash between the rm and the touch still leaves `.<fn>` absent, so the existing checkpoint guard re-runs the function on next invocation. The sentinel is purely a surface-level indicator; `.<fn>` is the source of truth.
DO NOT introduce a new badge or modify the status/reason files. DO NOT alter the `record_func_timing`, `_print_status`, or `log_json "SUCCESS"` calls. DO NOT add PID-in-sentinel or timestamp-in-sentinel (per D-03 simplicity decision is locked).
Preserve `function name() { ... }` declaration style (CONVENTIONS.md). Preserve all existing trailing logic (timing, badges, JSONL log).
bash -n /Users/six2dez/Tools/reconftw/modules/core.sh && shellcheck -s bash --severity=error /Users/six2dez/Tools/reconftw/modules/core.sh
- `grep -n 'touch "\$called_fn_dir/\.inprogress_' /Users/six2dez/Tools/reconftw/modules/core.sh` returns exactly one match inside start_func (line range 1419-1435 in the original file; line numbers will shift after edit, but the match must be within the start_func body — i.e., between `function start_func()` and the closing `}`).
- `grep -n 'rm -f "\$called_fn_dir/\.inprogress_' /Users/six2dez/Tools/reconftw/modules/core.sh` returns exactly one match inside end_func, on a line BEFORE the `touch "$called_fn_dir/.${fn}"` line.
- Existing `touch "$called_fn_dir/.${fn}"` line still present and unchanged in payload.
- Existing `printf -v "_start_time_${_fn_name//[^a-zA-Z0-9_]/_}"` line still present and unchanged.
- `bash -n modules/core.sh` exits 0.
- `shellcheck -s bash --severity=error modules/core.sh` exits 0 (no new error-level findings introduced; pre-existing warnings allowed).
- Behavior (manual smoke after task 2 lands): running `./reconftw.sh --source-only` does not error; sourcing the file and calling `called_fn_dir=$(mktemp -d); start_func test_fn "desc"; ls "$called_fn_dir/.inprogress_test_fn"` shows the sentinel exists; `end_func "done" test_fn; [[ ! -e "$called_fn_dir/.inprogress_test_fn" ]] && [[ -e "$called_fn_dir/.test_fn" ]]` confirms removal then checkpoint.
start_func writes `.inprogress_` after timestamp setup; end_func removes it immediately before the existing `.` touch; no other behavior modified; shellcheck clean.
Task 2: Separate EXIT-only trap + orphan cleanup + resume banner in start()
modules/modes.sh, modules/utils.sh
- modules/modes.sh (current start() body :13-163 — note INT/TERM trap at :118, FORCE_RESCAN wipe at :78-80, ERR trap at :140, FORCE_RESCAN banner at :154-156, tools_installed call at :160)
- modules/utils.sh (current cleanup_on_exit at :116-146 — DO NOT modify; note that it unconditionally prints an interruption banner and exits with code 130. New _cleanup_inprogress is a sibling helper, placed adjacent but kept independent.)
- .planning/phases/01-resilient-resume-timeout-safety/01-PATTERNS.md (anchor "modules/modes.sh — start() orchestration entry" — D-02/D-04/D-05 insertion notes)
- .planning/phases/01-resilient-resume-timeout-safety/01-CONTEXT.md (D-02 trap-on-exit cleanup; D-04 single WARN banner; D-05 FORCE_RESCAN orphan clear)
- lib/common.sh (review _print_msg signature at :342 and _print_error at :528)
Step A — Add `_cleanup_inprogress` standalone helper to modules/utils.sh as a sibling to `cleanup_on_exit` (insert immediately AFTER cleanup_on_exit closes at :146, before `rotate_logs` at :148). It MUST NOT be invoked from inside cleanup_on_exit and MUST NOT call exit, kill, or print any banner — its only job is to remove the `.inprogress_*` sentinel files. Define:
- `function _cleanup_inprogress() { [[ -n "${called_fn_dir:-}" ]] && rm -f "${called_fn_dir}"/.inprogress_* 2>/dev/null; return 0; }` on its own line range.
- Place a single-line doc comment above it: `# Remove stale .inprogress_ sentinels on EXIT (D-02). Does not call exit/kill/print — safe to fire on every shell exit, including successful runs.`
- Behavioral contract: the helper is idempotent, side-effect-only on `${called_fn_dir}` sentinel files, and explicitly `return 0` so it never propagates a non-zero exit through the EXIT trap chain.
Step B — Register a separate EXIT-only trap in modules/modes.sh start(). DO NOT modify the existing `trap 'cleanup_on_exit' INT TERM` line at :118 (cleanup_on_exit remains bound to INT/TERM only — firing it on EXIT would print "Interrupted. Cleaning up..." and force exit 130 on every successful scan, breaking CI, `--health-check`, axiom-orchestrator, `make test`, etc.). Instead, add the EXIT trap on the line IMMEDIATELY AFTER :118:
- Existing line at :118: `trap 'cleanup_on_exit' INT TERM` (unchanged).
- New line inserted right after :118: `trap '_cleanup_inprogress' EXIT`
- Result: INT/TERM still trigger the loud, exit-130 cleanup_on_exit (correct for actual interruptions). EXIT triggers the lightweight, silent _cleanup_inprogress on every shell termination including normal success (no banner, no kill, no forced exit code — natural `$?` is preserved).
- DO NOT edit cleanup_on_exit (modules/utils.sh:116-146). DO NOT chain `_cleanup_inprogress` into cleanup_on_exit; the two helpers are intentionally separate so that INT/TERM paths emit the existing user-visible interruption banner exactly once while EXIT paths stay silent.
Step C — Add FORCE_RESCAN orphan-clear line in modules/modes.sh. The new line goes inside the existing FORCE_RESCAN block at modes.sh:78-80, immediately after the existing `rm -f "$called_fn_dir"/.*` line (the existing line at :79). Insertion produces:
```
if [[ "${FORCE_RESCAN:-false}" == "true" ]]; then # :78 (unchanged)
rm -f "$called_fn_dir"/.* 2>>"${LOGFILE:-/dev/null}" || true # :79 (unchanged)
rm -f "$called_fn_dir"/.inprogress_* 2>>"${LOGFILE:-/dev/null}" || true # NEW
fi # :80 (unchanged)
```
The block already executes before the trap installs at :118 in natural top-down flow — no reordering needed. Per D-05 / PATTERNS.md: although the existing `rm -f "$called_fn_dir"/.*` SHOULD match `.inprogress_*` via dotglob, we add an explicit second `rm -f` line for defensive clarity so a `--force` run never inherits a fake resume condition regardless of shell glob settings.
Step D — Emit resume banner in modules/modes.sh. Insert a new block AFTER the existing FORCE_RESCAN warning at :154-156 (`if [[ "${FORCE_RESCAN:-false}" == "true" ]]; then _print_msg WARN "Force rescan enabled..."; fi`) and BEFORE the `if [[ "${MONITOR_MODE:-false}" == "true" ]]` block at :157. Defensive guards are mandatory: the block MUST be wrapped so it does NOT enumerate sentinels when `called_fn_dir` is empty (which would scan filesystem root) and MUST be skipped under FORCE_RESCAN (Step C already wiped any orphans). The block must:
1. Outer guard: wrap the entire detection in `if [[ -n "${called_fn_dir:-}" ]] && [[ "${FORCE_RESCAN:-false}" != "true" ]]; then ... fi`. The `[[ -n "${called_fn_dir:-}" ]]` check is mandatory — without it, an unset called_fn_dir would cause `ls -1 /.inprogress_*` to scan filesystem root.
2. Inside the guard: `local -a _leftover; mapfile -t _leftover < <(ls -1 "${called_fn_dir}"/.inprogress_* 2>/dev/null)`. The `2>/dev/null` suppresses the no-match-glob error from `ls`.
3. Test for non-empty results: `if (( ${#_leftover[@]} > 0 )); then ... fi`.
4. Build a comma-separated function-name list by stripping the `${called_fn_dir}/.inprogress_` prefix from each path.
5. Emit exactly ONE banner line via `_print_msg WARN "resume: ${#_leftover[@]} functions re-running after interruption (${joined})"` — matches the FORCE_RESCAN banner idiom at :155 and the locked D-04 phrasing ("WARN resume: N functions re-running after interruption (fn_a, fn_b)"). DO NOT add per-function badges, DO NOT call `notification`.
6. Emit one JSONL event via `log_json "WARN" "resume" "Inprogress sentinels found" "reason=inprogress_leftover" "funcs=${joined}"` — matches the `log_json` shape from start_func at :1428.
DO NOT touch the ERR trap at :140 (composition with EXIT/INT/TERM only). DO NOT introduce a CLI flag for the resume banner (always-on at OUTPUT_VERBOSITY>=1 via WARN level). DO NOT modify cleanup_on_exit in modules/utils.sh (its INT/TERM behavior is intentional and load-bearing — the loud banner + exit 130 is the desired user-facing interruption signal).
bash -n /Users/six2dez/Tools/reconftw/modules/modes.sh && bash -n /Users/six2dez/Tools/reconftw/modules/utils.sh && shellcheck -s bash --severity=error /Users/six2dez/Tools/reconftw/modules/modes.sh /Users/six2dez/Tools/reconftw/modules/utils.sh
- `grep -nE '^function _cleanup_inprogress\(\) \{' /Users/six2dez/Tools/reconftw/modules/utils.sh` returns exactly one match (standalone declaration in the canonical `function name() {` form).
- `grep -n 'rm -f "\${called_fn_dir}"/\.inprogress_\*' /Users/six2dez/Tools/reconftw/modules/utils.sh` returns at least one match inside the _cleanup_inprogress body.
- `_cleanup_inprogress` is NOT called from inside `cleanup_on_exit`: `awk '/^function cleanup_on_exit/,/^}/' /Users/six2dez/Tools/reconftw/modules/utils.sh | grep -c '_cleanup_inprogress'` returns exactly 0.
- `cleanup_on_exit` is UNCHANGED apart from the surrounding file: the body still contains the interruption banner (`grep -c 'Interrupted. Cleaning up' /Users/six2dez/Tools/reconftw/modules/utils.sh` returns >=1) and the `exit "$exit_code"` line (`grep -c 'exit "\$exit_code"' /Users/six2dez/Tools/reconftw/modules/utils.sh` returns >=1).
- `grep -n "^[[:space:]]*trap 'cleanup_on_exit' INT TERM" /Users/six2dez/Tools/reconftw/modules/modes.sh` returns exactly 1 (existing trap UNCHANGED — EXIT must NOT appear on this line).
- `grep -n "^[[:space:]]*trap '_cleanup_inprogress' EXIT" /Users/six2dez/Tools/reconftw/modules/modes.sh` returns exactly 1 (NEW separate EXIT-only trap).
- The EXIT trap line sits immediately after the INT/TERM trap line: `awk '/^[[:space:]]*trap '\''cleanup_on_exit'\'' INT TERM/{getline nxt; print nxt; exit}' /Users/six2dez/Tools/reconftw/modules/modes.sh | grep -c "trap '_cleanup_inprogress' EXIT"` returns 1.
- FORCE_RESCAN orphan-clear line is between `rm -f "$called_fn_dir"/.*` and the closing `fi`: `awk '/if \[\[ "\${FORCE_RESCAN:-false}" == "true" \]\]; then/,/^[[:space:]]*fi/' /Users/six2dez/Tools/reconftw/modules/modes.sh | head -10 | grep -nE 'rm -f "\$called_fn_dir"/\.\*|rm -f "\$called_fn_dir"/\.inprogress_\*|^[[:space:]]*fi'` shows the two `rm -f` lines in order followed by `fi`.
- The new FORCE_RESCAN `rm -f .inprogress_*` line precedes the trap install at :118: `awk '/rm -f "\$called_fn_dir"\/\.inprogress_\*/{print NR; exit}' /Users/six2dez/Tools/reconftw/modules/modes.sh` returns a line number < the line containing `trap '_cleanup_inprogress' EXIT`.
- Banner detection block is guarded against unset called_fn_dir: `grep -nE '\[\[ -n "\$\{called_fn_dir:-\}" \]\]' /Users/six2dez/Tools/reconftw/modules/modes.sh` returns >=1 (specifically wrapping the leftover-detection mapfile/glob).
- Banner detection block is skipped under FORCE_RESCAN: the same guard line also tests `[[ "${FORCE_RESCAN:-false}" != "true" ]]`. `grep -nE '\[\[ "\$\{FORCE_RESCAN:-false\}" != "true" \]\]' /Users/six2dez/Tools/reconftw/modules/modes.sh` returns >=1.
- `grep -n '_print_msg WARN "resume: ' /Users/six2dez/Tools/reconftw/modules/modes.sh` returns exactly one match.
- `grep -n 'reason=inprogress_leftover' /Users/six2dez/Tools/reconftw/modules/modes.sh` returns exactly one match (the log_json call).
- `bash -n modules/modes.sh` and `bash -n modules/utils.sh` both exit 0.
- `shellcheck -s bash --severity=error modules/modes.sh modules/utils.sh` exits 0 (no new error-level findings).
- Behavior smoke (graceful-exit safety — protects against the BLOCKER regression): inside a `--source-only`-loaded shell, run `called_fn_dir=$(mktemp -d); start_func test_fn "desc"; end_func "done" test_fn; exit 0` (a clean round-trip + clean exit). The shell exit MUST NOT print "Interrupted. Cleaning up..." anywhere, and `$?` after the subshell MUST be 0 (the natural exit code) — NOT 130. The `${called_fn_dir}/.inprogress_*` directory listing MUST be empty.
- Behavior smoke (resume banner): simulating a crash via `mkdir -p /tmp/rftw-test/.called_fn && touch /tmp/rftw-test/.called_fn/.inprogress_sub_brute`, then a `--source-only` sourced `start` invocation pointing `called_fn_dir` there, must print exactly one banner line containing `resume: 1 functions re-running after interruption (sub_brute)`. The same setup with `FORCE_RESCAN=true` exported must print the rescan banner only and leave NO `.inprogress_*` files.
- Behavior smoke (INT/TERM unchanged): sending SIGINT to a real `./reconftw.sh -d test.local -p` invocation MUST still print the red "Interrupted. Cleaning up..." banner from cleanup_on_exit and exit with code 130 (unchanged user-facing behavior).
Separate EXIT-only trap registered via `trap '_cleanup_inprogress' EXIT` adjacent to the existing untouched INT/TERM trap; `_cleanup_inprogress` standalone helper added to modules/utils.sh (sibling to but independent from cleanup_on_exit); cleanup_on_exit body NOT modified; FORCE_RESCAN explicitly clears `.inprogress_*` orphans inside the existing block at :78-80; resume banner emits one WARN line and one JSONL event when leftover sentinels are detected (and only when called_fn_dir is set and FORCE_RESCAN is false); no per-function badges added; graceful exits no longer print an interruption banner; shellcheck clean.
- `bash -n modules/core.sh modules/modes.sh modules/utils.sh` → exit 0.
- `shellcheck -s bash --severity=error modules/core.sh modules/modes.sh modules/utils.sh` → exit 0 (no NEW error-level findings vs baseline).
- Manual smoke (no test files in this phase per CONTEXT Deferred):
1. Source the project: `./reconftw.sh --source-only`.
2. Graceful-exit safety: `( source ./reconftw.sh --source-only; called_fn_dir=$(mktemp -d); start_func test_fn "desc"; end_func "done" test_fn; exit 0 )` — outer `$?` is 0, no "Interrupted. Cleaning up..." banner printed, `.inprogress_*` cleared.
3. Simulate crash: `mkdir -p /tmp/rftw-test/.called_fn && touch /tmp/rftw-test/.called_fn/.inprogress_sub_brute /tmp/rftw-test/.called_fn/.sub_other`.
4. Invoke `start` with `called_fn_dir=/tmp/rftw-test/.called_fn dir=/tmp/rftw-test domain=test.local PRESERVE=true FORCE_RESCAN=false`.
5. Expect: console shows `WARN resume: 1 functions re-running after interruption (sub_brute)` line once; `.sub_other` still present (success checkpoint preserved); `.inprogress_sub_brute` cleared by the EXIT trap when start returns.
6. Repeat with `FORCE_RESCAN=true`: expect rescan banner, no resume banner, both `.inprogress_*` and `.sub_other` files absent.
7. Actual SIGINT smoke: kill -INT a running `./reconftw.sh` — cleanup_on_exit fires with its existing red banner and exit code 130 (UNCHANGED user-facing behavior).
- Plan 01-01 success criterion (ROADMAP §"Phase 1" SC#1): Interrupting recon mid-`sub_brute` and re-running with `PRESERVE=true` produces a clear `.inprogress_sub_brute` indicator and re-executes only that function — completed functions retain `.` checkpoints and are skipped.
- All `must_haves.truths` verifiable per the acceptance criteria above.
- No new badge values introduced; existing OK/WARN/FAIL/SKIP/CACHE/INFO/RUN vocabulary preserved.
- No PID, timestamp, or JSON metadata inside `.inprogress_` files (D-01 simplicity locked).
- Single WARN banner line for resume detection; no per-function decoration (D-04 locked).
- cleanup_on_exit (modules/utils.sh:116-146) is NOT modified; its INT/TERM-only registration is preserved so successful exits never print an interruption banner or force exit 130.