| name | skill-implementer-hard |
| description | Execute hard-mode implementation with anti-analysis contracts, per-phase dispatch, and territory-aware execution. Invoke for --hard implementation tasks. |
| allowed-tools | Agent, AskUserQuestion, Bash, Edit, Read, Write |
Implementer Hard Skill
Hard-mode wrapper that delegates implementation to general-implementation-hard-agent subagent.
Extends skill-implementer with:
- Single-phase dispatch context (H1): reads handoff JSON to identify next incomplete phase
- Territory parameters (H7): includes territory contract when dispatched from orchestrate-hard
- Anti-analysis contract (H2): passed in delegation context for agent enforcement
Relationship to base skill: Structurally follows skill-implementer postflight pattern.
Key difference: when orchestrator_mode=true, uses per-phase dispatch (H1) rather than
whole-plan dispatch. Maintenance: mirror postflight changes to this skill.
Context References
Reference (do not load eagerly):
- Path:
.claude/context/formats/return-metadata-file.md - Metadata file schema
- Path:
.claude/context/contracts/anti-analysis.md - H2 contract (loaded by agent)
- Path:
.claude/context/contracts/wrap-up.md - H9 contract (loaded by agent)
- Path:
.claude/context/contracts/territory.md - H7 contract (when territory params present)
- Path:
.claude/context/contracts/recovery.md - recovery/fix-forward ladder (loaded by agent)
- Path:
.claude/context/contracts/phase-closure.md - depth-first phase closure: close one phase before opening the next (loaded by agent)
- Path:
.claude/context/contracts/pre-edit-gate.md - per-item evidence before applying a mechanical-list edit (loaded by agent)
- Path:
.claude/context/patterns/postflight-control.md - Marker file protocol
- Path:
.claude/context/patterns/subagent-continuation-loop.md - Continuation loop pattern
Trigger Conditions
This skill activates when:
/implement N --hard is invoked and no extension hard variant exists
- Routed here by
command-route-skill.sh with effort_flag="hard"
skill-orchestrate-hard dispatches an implementation phase
Execution Flow
Stage 1: Input Validation
task_data=$(jq -r --argjson num "$task_number" \
'.active_projects[] | select(.project_number == $num)' \
specs/state.json)
if [ -z "$task_data" ]; then
return error "Task $task_number not found"
fi
task_type=$(echo "$task_data" | jq -r '.task_type // "general"')
status=$(echo "$task_data" | jq -r '.status')
project_name=$(echo "$task_data" | jq -r '.project_name')
description=$(echo "$task_data" | jq -r '.description // ""')
if [ "$status" = "completed" ] || [ "$status" = "abandoned" ] || [ "$status" = "expanded" ]; then
return error "Task is in terminal state [$status]"
fi
Stage 1.5: Hard-Mode Cost Note
session_flag_file="/tmp/.hard-mode-notified-${SESSION_ID:-$$}"
if [ ! -f "$session_flag_file" ]; then
echo "[hard-mode] Hard mode active. Cost: ~3-5x standard. Use --hard for deflection-prone or formally complex tasks." >&2
touch "$session_flag_file"
fi
Stage 2 + Stage 3: Preflight Status Update and Postflight Marker
Source skill-base.sh once, then follow @.claude/context/patterns/skill-preflight-flow.md in
full for Stage 2 (preflight status update) and Stage 3 (marker creation):
source .claude/scripts/skill-base.sh
padded_num=$(printf "%03d" "$task_number")
skill_name="skill-implementer-hard"
operation="implement"
Marker unification note: this skill's marker previously dropped created and
stop_hook_active (Shape C) — a drift, not a hard-mode design decision. Routing through
skill_create_postflight_marker restores both fields as part of this conversion, matching every
other importer's Shape A schema.
Stage 3a: Calculate Artifact Number
next_num=$(jq -r --argjson num "$task_number" \
'.active_projects[] | select(.project_number == $num) | .next_artifact_number // 1' \
specs/state.json)
if [ "$next_num" -le 1 ]; then
artifact_number=1
else
artifact_number=$((next_num - 1))
fi
artifact_padded=$(printf "%02d" "$artifact_number")
Stage 3b: Single-Phase Dispatch Context (H1)
When orchestrator_mode=true, determine the specific phase to dispatch rather than
dispatching the whole plan:
if [ "$orchestrator_mode" = "true" ]; then
task_dir="specs/${padded_num}_${project_name}"
task_dir_abs="${SKILL_REPO_ROOT:-$(pwd)}/specs/${padded_num}_${project_name}"
handoff_path_abs="${task_dir_abs}/.orchestrator-handoff.json"
handoff_file="${task_dir}/.orchestrator-handoff.json"
plan_path=$(ls -1 "${task_dir}/plans/"*.md 2>/dev/null | sort -V | tail -1)
next_phase=""
phase_scan_inconclusive=false
if [ -n "$plan_path" ] && [ -f "$plan_path" ]; then
. .claude/scripts/lib/phase-heading-patterns.sh
if has_nonconforming_phase_headings "$plan_path"; then
warn_nonconforming "$plan_path" "implementer-hard-next-phase" || true
phase_scan_inconclusive=true
else
next_heading=$(grep -E "${PHASE_HEADING_ERE} .*${PHASE_STATUS_OPEN_ERE}" "$plan_path" | head -1)
if [ -n "$next_heading" ]; then
next_phase=$(extract_phase_number "$next_heading") || next_phase=""
if [ -z "$next_phase" ]; then
phase_scan_inconclusive=true
fi
fi
fi
fi
if [ "$phase_scan_inconclusive" = "true" ]; then
echo "[hard-mode] STOP: resume-scan found a non-conforming phase heading -- refusing to guess a resume point. See the named, line-numbered warning above." >&2
exit 1
fi
if [ -n "$next_phase" ]; then
echo "[hard-mode] Per-phase dispatch: targeting phase ${next_phase} (heading-scan)" >&2
elif [ -f "$handoff_file" ] && [ "$(jq -r '.skeleton // false' "$handoff_file" 2>/dev/null)" = "true" ]; then
follow_up_tasks=$(jq -r '.follow_up_tasks // [] | join(", ")' "$handoff_file" 2>/dev/null)
follow_up_count=$(jq -r '.follow_up_tasks // [] | length' "$handoff_file" 2>/dev/null)
echo "[hard-mode] Skeleton plan exhausted -- ${follow_up_count} follow-up tasks pending: {${follow_up_tasks}}" >&2
next_phase=""
else
next_phase=1
echo "[hard-mode] No incomplete phase heading found and no handoff, dispatching phase 1" >&2
fi
fi
Stage 4a: Memory Retrieval (Auto)
if [ "$clean_flag" != "true" ]; then
memory_context=$(bash .claude/scripts/memory-retrieve.sh "$description" "$task_type" "" 2>/dev/null) || memory_context=""
fi
Literature Detection and Injection (Stage 4a, shared block)
Follow @.claude/context/patterns/lit-stage4a-flow.md in full to resolve --lit and set
lit_context: call literature-lit-flag-resolve.sh, branch on all six directives
(LIT_DISABLED, SUBINDEX_PRESENT, GLOBAL_MISSING, PROMPT_NEEDED, AUTONOMOUS_GLOBAL,
SPARSE_PROMPT_NEEDED), issue the real four-option AskUserQuestion for the two interactive
directives (including the "Search online to ingest" option wired to the STABLE-CONTRACT
literature-ingest-online.sh bridge), apply the two-checkpoint sparse re-prompt after "Use
global corpus now", and take the deterministic [lit:auto] autonomous fallback when
orchestrator_mode == "true" (never calling AskUserQuestion in that case). This skill
supplies the shared block's preconditions: lit_flag, description, and orchestrator_mode
(read from the delegation context; default "false" when unset).
Note: lit_flag is independent of clean_flag. Using --clean --lit suppresses memory retrieval but still injects literature briefing. Literature briefing is gated solely on lit_flag == "true".
Stage 4: Prepare Delegation Context
Pass anti-analysis contract reference, recovery contract reference (see
.claude/context/contracts/recovery.md — fix-forward disambiguation and the 3-rung Recovery
Ladder), and territory params (when applicable):
{
"session_id": "{session_id}",
"delegation_depth": 1,
"delegation_path": ["orchestrator", "implement", "skill-implementer-hard"],
"timeout": 7200,
"task_context": {
"task_number": N,
"task_name": "{project_name}",
"description": "{description}",
"task_type": "{task_type}"
},
"artifact_number": "{artifact_number}",
"effort_flag": "hard",
"model_flag": "{model_flag from command}",
"plan_path": "{plan_path}",
"roadmap_path": "specs/ROADMAP.md",
"phase_number": "{next_phase when orchestrator_mode=true, null otherwise}",
"territory": "{territory params from orchestrate-hard dispatch, null if not provided}",
"orchestrator_mode": "{orchestrator_mode}",
"metadata_file_path": "specs/{NNN}_{SLUG}/.return-meta.json",
"task_dir": "{task_dir_abs — ABSOLUTE path to the task directory}",
"handoff_path": "{handoff_path_abs — ABSOLUTE path the agent MUST write its handoff to}",
"dispatch_seq": "{dispatch_seq from this skill's own delegation context, forwarded unchanged; omit if absent}"
}
Forward dispatch_seq unchanged. If this skill's own delegation context (i.e. the context an
orchestrate-hard dispatch passed to it) carries a dispatch_seq field, forward it into the
sub-agent's delegation context above verbatim — the same pass-through treatment already given to
handoff_path and territory. Never invent, increment, or recompute a value at this layer; only
the orchestrator mints one. If absent, omit the field rather than fabricating a value. This is
the orchestrator-minted per-dispatch identity Stage 5 of both orchestrate engines compares
against the value it minted for the current cycle — see