---
id: T-496
name: "Implement path isolation — fw hook subcommand + portable settings.json + doctor
  validation"
description: >
  From T-495 GO. Build: (1) fw hook subcommand in bin/fw — resolves FRAMEWORK_ROOT
  from symlink, PROJECT_ROOT from cwd, execs agents/context/$1.sh. (2) Update generate_claude_code_config()
  in lib/init.sh — use fw hook instead of hardcoded paths. (3) fw upgrade step 5 detects
  old-style hardcoded paths and regenerates. (4) fw doctor validates hook commands
  resolve to real executables. (5) E2E test phase for path isolation in self-test.

status: work-completed
workflow_type: build
owner: human
horizon:
tags: [portability, enforcement, P0]
components: [bin/fw, C-009, lib/init.sh, lib/upgrade.sh]
related_tasks: []
created: 2026-03-14T22:35:59Z
last_update: '2026-06-11T22:24:23Z'
date_finished: 2026-03-14T22:58:52Z
bvp_scores_proposed:
  - ts: '2026-06-11T22:24:23Z'
    estimator: bvp-estimator-v1-heuristic
    scores:
      D1: 4
      D2: 4
      D3: 0
      D4: 1
      F-RECALL: 2
      F-ORCH: 0
      F3: 0
      F1: 0
      F2: 0
    rationale: D1=4 (body:structural-gate); D2=4 (body:fw-audit-or-doctor); D3=0
      (no-signal); D4=1 (body:hard-coded-removed); F-RECALL=2 
      (body:lightly-promoted); F-ORCH=0 (no-signal); F3=0 (no-signal); F1=0 
      (no-signal); F2=0 (no-signal)
    rubric_sha: e4a00f38e801
---

# T-496: Implement path isolation — fw hook subcommand + portable settings.json + doctor validation

## Context

From T-495 GO (G-021). See `docs/reports/T-495-path-isolation-inception.md`.

## Acceptance Criteria

### Agent
- [x] `fw hook check-active-task` executes the correct gate script and returns proper exit code
- [x] `fw hook` with invalid name returns non-zero exit code (exit 2)
- [x] `generate_claude_code_config()` in lib/init.sh produces settings.json with `fw hook` commands (zero absolute paths)
- [x] `fw doctor` checks that hook commands resolve to real executables (check 6 + hook config)
- [x] `fw upgrade` step [5/8] detects old-style hardcoded paths and regenerates with `fw hook`
- [x] `fw help` shows `hook` subcommand
- [x] Settings.json generated by `fw init` contains zero absolute paths (quoted heredoc)

### Human
- [x] [RUBBER-STAMP] Run `fw upgrade --dry-run` on termlink and verify it detects stale paths
  **Steps:**
  1. Run `fw upgrade --dry-run` in the termlink project
  2. Check step [5/8] output
  **Expected:** Shows "WOULD UPDATE" for hooks with stale paths
  **If not:** Note what step [5/8] reports

## Verification

# fw hook dispatches correctly
grep -q "hook)" bin/fw
# Settings.json has no hardcoded framework paths in hook commands
! grep -q "/agents/context/" .claude/settings.json || echo "FAIL: hardcoded paths remain"
python3 -c "import json; d=json.load(open('.claude/settings.json')); cmds=[h['command'] for hl in d['hooks'].values() for e in hl for h in e.get('hooks',[])]; assert all('fw hook' in c for c in cmds), f'Not all hooks use fw hook: {[c for c in cmds if \"fw hook\" not in c]}'; print(f'OK: {len(cmds)} hooks all use fw hook')"
# fw doctor checks hook resolution
grep -q "hook.*resolv\|hook.*valid\|hook.*path" bin/fw

## Decisions

<!-- Record decisions ONLY when choosing between alternatives.
     Skip for tasks with no meaningful choices.
     Format:
     ### [date] — [topic]
     - **Chose:** [what was decided]
     - **Why:** [rationale]
     - **Rejected:** [alternatives and why not]
-->

## Updates

### 2026-03-14T22:35:59Z — task-created [task-create-agent]
- **Action:** Created task via task-create agent
- **Output:** /opt/999-Agentic-Engineering-Framework/.tasks/active/T-496-implement-path-isolation--fw-hook-subcom.md
- **Context:** Initial task creation

### 2026-03-14T22:58:52Z — status-update [task-update-agent]
- **Change:** status: started-work → work-completed

## Reviewer Verdict (v1.5)

- **Scan ID:** R-8113b56d
- **Timestamp:** 2026-06-02T15:03:11Z
- **Catalogue:** v1.3-seed
- **Overall:** CONCERN
- **Needs Human:** no
- **Findings:** 1

**Per-AC findings:**

- **AC#3 (Agent)** — `generate_claude_code_config()` in lib/init.sh produces settings.json with `fw hook` commands (zero absolute paths)
  - **AC-verify-mismatch** (narrow, heuristic) — `path=lib/init.sh in: `generate_claude_code_config()` in lib/init.sh produces settings.json with `fw hook` commands (zero absolute paths)`
