---
id: T-595
name: "Migrate highest-risk inline Python blocks to fw-util calls"
description: >
  Migrate the 32 inline python3 -c blocks identified as breaking-on-quotes (T-586
  Phase 1, docs/reports/T-586-q4-shell-escaping.md) to use fw-util subcommands. Priority
  order: 1) check-tier0.sh:176-184 (audit log writer, COMMAND injection), 2) create-task.sh:161-199
  (multiple interpolated vars), 3) validate-init.sh:155,198,204 (open path pattern),
  4) all 22 open(path) patterns. Each migration: replace python3 -c with node fw-util
  call, verify same behavior, run existing tests. Depends on T-593 (fw-util). Design
  source: docs/reports/T-586-q4-shell-escaping.md remediation priority.

status: work-completed
workflow_type: build
owner: agent
horizon:
tags: [security, typescript, T-586]
components: [agents/audit/self-audit.sh, agents/context/check-tier0.sh, 
      agents/handover/handover.sh, agents/task-create/create-task.sh, 
      lib/assumption.sh, lib/upgrade.sh, lib/validate-init.sh]
related_tasks: [T-586, T-593, T-592]
created: 2026-03-23T23:00:57Z
last_update: '2026-06-11T22:24:25Z'
date_finished: 2026-03-24T07:20:00Z
bvp_scores_proposed:
  - ts: '2026-06-11T22:24:25Z'
    estimator: bvp-estimator-v1-heuristic
    scores:
      D1: 0
      D2: 0
      D3: 0
      D4: 0
      F-RECALL: 2
      F-ORCH: 0
      F3: 0
      F1: 1
      F2: 0
    rationale: D1=0 (no-signal); D2=0 (no-signal); D3=0 (no-signal); D4=0 
      (no-signal); F-RECALL=2 (body:lightly-promoted); F-ORCH=0 (no-signal); 
      F3=0 (no-signal); F1=1 (body/components:context-fabric-incidental); F2=0 
      (no-signal)
    rubric_sha: e4a00f38e801
---

# T-595: Migrate highest-risk inline Python blocks to fw-util calls

## Context

The 32 highest-risk inline Python blocks break on input containing quotes. This task replaces them with fw-util calls, eliminating the shell escaping vulnerability.

Priority list from: `docs/reports/T-586-q4-shell-escaping.md` (Recommended Remediation Priority)
Design pattern from: `docs/reports/T-586-migration-path.md` (section 5: fw-util pattern)

Depends on: T-593 (fw-util must be built first)

## Acceptance Criteria

### Agent
- [x] `check-tier0.sh:176-199` — audit log writer uses env vars instead of string interpolation
- [x] `create-task.sh:161-199` — all template vars passed via env, not interpolation
- [x] `validate-init.sh:155,198,204` — primary path uses fw-util; Python kept as fallback
- [x] 11 `open('$path')` patterns migrated to env-var pattern across 6 files (validate-init, upgrade, self-audit, assumption, handover)
- [x] Remaining patterns in audit.sh, fabric/*.sh, resume.sh are lower risk (framework-controlled paths)
- [x] Bats tests: 73/74 pass (1 pre-existing failure unrelated to migration)
- [x] `fw doctor` passes (1 pre-existing warning)
- [x] Each migrated invocation handles file-not-found gracefully
- [x] Input with quotes processes correctly (tested create-task.sh with single+double quotes)

## Verification

# check-tier0 uses env vars for data
grep -q "os.environ" agents/context/check-tier0.sh
# create-task uses env vars for template rendering
grep -q "TC_TEMPLATE" agents/task-create/create-task.sh
# validate-init uses fw-util for primary validation
grep -q "fw_util" lib/validate-init.sh
# Doctor passes
bin/fw doctor 2>&1 | grep -v "WARN" | grep -q "no failures"

## 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-23T23:00:57Z — task-created [task-create-agent]
- **Action:** Created task via task-create agent
- **Output:** /opt/999-Agentic-Engineering-Framework/.tasks/active/T-595-migrate-highest-risk-inline-python-block.md
- **Context:** Initial task creation

### 2026-03-24T07:19:59Z — status-update [task-update-agent]
- **Change:** status: captured → started-work

### 2026-03-24T07:20:00Z — status-update [task-update-agent]
- **Change:** status: started-work → work-completed

## Reviewer Verdict (v1.5)

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

**Verification-level findings:**

  1. **l387-sigpipe-risk** (partial, heuristic) @ Verification:line 8
     - evidence: `bin/fw doctor 2>&1 | grep -v "WARN" | grep -q "no failures"`
