@chrono-meta/fh-gate 1.4.16 → 1.4.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,249 @@
1
+ ---
2
+ name: goal-quench-detail
3
+ description: Detail reference for goal-quench — one-time setup blocks, Phase 1 formats, queue format, Phase 3 verification bash, calibration record format. Load when executing a specific phase.
4
+ load: on-demand
5
+ ---
6
+
7
+ # goal-quench — Detail Reference
8
+
9
+ > Load when executing a specific phase. SKILL.md contains the mode ladder, triggers, phase-by-phase behavioral rules, verdict mapping tables, simplification guards, chains, and Done When.
10
+
11
+ ---
12
+
13
+ ## §Setup — One-Time Setup Blocks
14
+
15
+ ### Claude Code Runtime
16
+
17
+ Copy the hook snippet from `templates/goal-quench-hook-setup.md` and merge into your `.claude/settings.json`.
18
+
19
+ Add to `.gitignore`:
20
+ ```
21
+ .claude/goal-quench.active
22
+ .claude/goal-quench.pending
23
+ ```
24
+
25
+ **Hook failure fallback**: The Stop hook may fire silently without triggering verification (hook failure, session reset, or CC version differences). If Phase 3 verification has not run after /goal completes, manually trigger it:
26
+ > `/goal-quench --verify` — skips Phase 1+2, runs pipeline-conductor --quick using current session scope.
27
+
28
+ **Interrupted /goal recovery**: If /goal is interrupted (error, user abort, CC crash), the Stop hook may not fire — leaving `.claude/goal-quench.active` without a `.pending`. Detect and recover:
29
+ ```bash
30
+ [ -f .claude/goal-quench.active ] && ! [ -f .claude/goal-quench.pending ] && echo "Interrupted — run /goal-quench --recover"
31
+ ```
32
+ > `/goal-quench --recover` — promotes `.active` → `.pending` and runs Phase 3 verification on partially-completed work.
33
+
34
+ ### Codex Runtime
35
+
36
+ Codex has its own goal/session capability. Do not replace it with goal-quench state files. In Codex-primary sessions:
37
+
38
+ 1. Use Codex's native goal/session feature for goal control.
39
+ 2. Use `fh-run` for any FH skill/agent sub-step that would otherwise require Claude Code `Agent(...)`.
40
+ 3. After the Codex goal completes, run FH governance on changed files:
41
+
42
+ ```bash
43
+ FH_BACKEND=codex npx @chrono-meta/fh-gate "{changed-files}" quick codex-goal
44
+ ```
45
+
46
+ For non-interactive one-shot runs only, `fh-goal` can run a backend task and then invoke `fh-gate` automatically:
47
+
48
+ ```bash
49
+ FH_BACKEND=codex npx --package @chrono-meta/fh-gate fh-goal \
50
+ --prompt "{task}" \
51
+ --gate quick
52
+ ```
53
+
54
+ `fh-goal` is not a Codex goal replacement; it is a post-run governance wrapper.
55
+
56
+ ---
57
+
58
+ ## §Phase1-Blocks
59
+
60
+ ### Pre-flight check bash (pro/max mode only)
61
+
62
+ ```bash
63
+ for skill in context-doctor agent-composer; do
64
+ [ -f ".claude/plugins/cache/forge-harness/fh-meta/"*"/skills/${skill}/SKILL.md" ] 2>/dev/null \
65
+ || find ~/.claude/plugins -name "${skill}" -type d 2>/dev/null | grep -q . \
66
+ || echo "WARNING: ${skill} not found — pro/max mode requires it. Falling back to core."
67
+ done
68
+ ```
69
+
70
+ ### token-budget-gate invocation contract
71
+
72
+ ```
73
+ Input: task description (one paragraph), target file count (approximate)
74
+ Trigger phrase: "estimate token budget for: {task description}"
75
+ Expected output fields:
76
+ - estimated_tokens: N
77
+ - verdict: GREEN | YELLOW | ORANGE | RED
78
+ - reasoning: one-line basis for estimate
79
+ ```
80
+
81
+ ### State file format (`.claude/goal-quench.active`)
82
+
83
+ ```
84
+ scope: {task description — one line}
85
+ mode: core | pro | max
86
+ target_files: {comma-separated file paths or directory; "inferred from git diff" if not known}
87
+ budget_estimate: {N} tokens
88
+ budget_source: token-budget-gate | fallback-heuristic
89
+ budget_verdict: {GREEN/YELLOW/ORANGE/RED}
90
+ pipeline_mode: {--quick for core/pro · --full for max}
91
+ composed_plan: {sub-goal list from Phase 1.5 agent-composer; "n/a" in core mode}
92
+ timestamp: {YYYY-MM-DD HH:MM}
93
+ session_pid: {$$}
94
+ start_commit: {git rev-parse HEAD}
95
+ ```
96
+
97
+ ### Mid-run budget threshold injection block (Phase 1 Step 4)
98
+
99
+ ```
100
+ ─── goal-quench budget thresholds (active for this /goal run) ───
101
+ 50% of estimated budget consumed:
102
+ → Output a one-line progress summary. No action required.
103
+
104
+ 70% consumed:
105
+ → YELLOW: re-prioritize remaining tasks. Drop lowest-priority items
106
+ if the goal can still be met without them.
107
+
108
+ 85% consumed:
109
+ → ORANGE: stop current task, commit completed work, surface to user:
110
+ "Budget at 85%. Completed: [X]. Remaining: [Y]. Continue / stop?"
111
+
112
+ 95% consumed:
113
+ → RED: stop immediately. Commit everything completed so far.
114
+ Output: "Budget exhausted. Completed tasks: [list]. Incomplete: [list]."
115
+ ─────────────────────────────────────────────────────────────────
116
+ ```
117
+
118
+ ### Hand-off output (Phase 1 Step 5)
119
+
120
+ > "goal-quench ready. Budget: {verdict} (~{N} tokens). Now run: `/goal {your condition}`
121
+ > When /goal finishes, the Stop hook will trigger pipeline-conductor --quick automatically."
122
+
123
+ ---
124
+
125
+ ## §Queue-Format
126
+
127
+ Sub-goal queue format (`.claude/goal-quench.queue`):
128
+ ```
129
+ remaining:
130
+ - sub-goal-1: {description}
131
+ - sub-goal-2: {description}
132
+ completed: []
133
+ ```
134
+
135
+ Output after agent-composer produces the Wave plan:
136
+
137
+ > "Sub-goal plan ready. Run each sub-goal in order by invoking `/goal-quench` again with the next sub-goal description. goal-quench will gate each sub-goal independently."
138
+
139
+ Sidecar fields written to `.active` (Phase 1.5 Step D):
140
+ ```
141
+ sidecar: none | steel-quench-crossprovider | agent-composer-panel | sim-conductor | {cli-name}
142
+ sidecar_rationale: {one-line reason — which scope signal triggered this}
143
+ ```
144
+
145
+ ---
146
+
147
+ ## §Phase3-Bash
148
+
149
+ ### Freshness guard (next-response `.pending` check)
150
+
151
+ ```bash
152
+ if [ -f .claude/goal-quench.pending ]; then
153
+ PENDING_TIME=$(grep "^timestamp:" .claude/goal-quench.pending | sed 's/^timestamp: //')
154
+ NOW=$(date +%s)
155
+ PENDING_EPOCH=$(date -d "$PENDING_TIME" +%s 2>/dev/null || date -j -f "%Y-%m-%d %H:%M" "$PENDING_TIME" +%s 2>/dev/null)
156
+ AGE_HOURS=$(( (NOW - PENDING_EPOCH) / 3600 ))
157
+ if [ "$AGE_HOURS" -lt 4 ]; then
158
+ echo "goal-quench verification pending (created: $PENDING_TIME — ${AGE_HOURS}h ago)"
159
+ else
160
+ echo "STALE: goal-quench.pending is ${AGE_HOURS}h old. Run /goal-quench --verify to re-evaluate or delete to clear."
161
+ exit 0
162
+ fi
163
+ fi
164
+ ```
165
+
166
+ ### Verification flow (artifact resolution)
167
+
168
+ ```bash
169
+ # Read scope and target from pending file
170
+ SCOPE=$(grep "^scope:" .claude/goal-quench.pending | sed 's/^scope: //')
171
+ TARGET=$(grep "^target_files:" .claude/goal-quench.pending | sed 's/^target_files: //')
172
+
173
+ # Resolve artifact: explicit target or git diff
174
+ # Use git diff against the commit recorded at Phase 1 start, NOT HEAD,
175
+ # to capture files changed during the entire /goal session including interim commits.
176
+ GOAL_START_COMMIT=$(grep "^start_commit:" .claude/goal-quench.pending | sed 's/^start_commit: //')
177
+ if [ "$TARGET" = "inferred from git diff" ] || [ -z "$TARGET" ]; then
178
+ if [ -n "$GOAL_START_COMMIT" ]; then
179
+ TARGET=$(git diff "$GOAL_START_COMMIT"..HEAD --name-only 2>/dev/null | tr '\n' ' ')
180
+ else
181
+ # Fallback: staged + unstaged changes (does not capture interim commits)
182
+ TARGET=$(git status --short 2>/dev/null | awk '{print $2}' | tr '\n' ' ')
183
+ fi
184
+ fi
185
+ # Guard: reject empty target
186
+ [ -z "$TARGET" ] && echo "ERROR: cannot resolve verification artifact — no files changed or start_commit missing" && exit 1
187
+ ```
188
+
189
+ ### Codex path
190
+
191
+ No Stop hook is required. After the Codex goal/session completes, resolve changed files with git and run:
192
+
193
+ ```bash
194
+ FH_BACKEND=codex npx @chrono-meta/fh-gate "{changed-files}" quick codex-goal
195
+ ```
196
+
197
+ For high-stakes or external-facing work, use `full` instead of `quick`. Treat `BLOCKED` or `ESCALATE` the same as the Claude path: fix and re-run the gate, or surface the decision to the user.
198
+
199
+ ---
200
+
201
+ ## §Calibration-Record
202
+
203
+ After each goal-quench run, append to `tracks/_meta/goal_quench_{YYYY-MM-DD}.md`:
204
+
205
+ ```yaml
206
+ - run_id: GQ-{YYYYMMDD}-{N} # e.g. GQ-20260603-01 — unique per run, links to session JSONL
207
+ session_id: "{first-8-chars-of-jsonl-filename}" # for JSONL back-trace
208
+ date: YYYY-MM-DD
209
+ task: {one-line description}
210
+ scope_hint: "{N files affected, task type}" # e.g. "3 new files, signal doc"
211
+ mode: core | pro | max
212
+ session_type: minor | normal | heavy | continuation # for within-type comparison
213
+ estimated_tokens: N
214
+ budget_source: token-budget-gate | fallback-heuristic
215
+ actual_tokens: N # from ~/.claude/projects/*/conversation*.jsonl or user-reported; "unknown" if unavailable
216
+ estimation_error: over | under | accurate
217
+ estimation_error_pct: "N%" # e.g. "717%" — magnitude of under/over; omit if accurate
218
+ actual_vs_estimate_ratio: N.N # actual / estimated (e.g., 4.7 means actual was 4.7× estimate)
219
+ budget_verdict: GREEN/YELLOW/ORANGE/RED
220
+ pipeline_verdict: CLEAN/PENDING/BLOCKED/ESCALATE
221
+ sidecar: none | steel-quench-crossprovider | agent-composer-panel | sim-conductor | {cli-name}
222
+ sidecar_type: none | cc-subagent | external-cli # cc-subagent = isolated Sonnet context; external-cli = untracked
223
+ sidecar_model: none | sonnet | {model-name} # standard baseline: sonnet; external CLIs vary by tier
224
+ orchestrator_tokens: N | unknown # Opus orchestrator CC tokens (pro/max only; visible in CC)
225
+ sidecar_tokens: N | unknown # Sonnet sub-agent CC tokens if cc-subagent; "untracked" if external-cli
226
+ sidecar_findings_count: N # 0 if sidecar=none
227
+ threshold_triggered: none/50/70/85/95
228
+ notes: {optional — why estimate was off, what scope changed}
229
+ ```
230
+
231
+ **`actual_tokens` collection**: Claude cannot read session token counts directly. Preferred method:
232
+ ```bash
233
+ python3 -c "
234
+ import json, glob
235
+ f = sorted(glob.glob('~/.claude/projects/*/conversation*.jsonl'.replace('~', __import__('os').path.expanduser('~'))))[-1]
236
+ lines = [json.loads(l) for l in open(f)]
237
+ total = sum(m.get('message',{}).get('usage',{}).get('input_tokens',0) + m.get('message',{}).get('usage',{}).get('output_tokens',0) for m in lines)
238
+ print(f'Session tokens: {total:,}')
239
+ "
240
+ ```
241
+ Fallback: turn count × estimated tokens/turn (~2K for short turns, ~8K for long file edits). Write `"unknown"` if no estimate is possible.
242
+
243
+ **Retrospective calibration baseline (N=10, 2026-06-01–06-03, Sonnet)**: mean actual/estimate ratio = 4.7× (range 1.3×–10.5×). Systematic underestimation due to session overhead. Full data held in the private companion store (`paper-signals/`).
244
+
245
+ After 10 additional prospective runs, compute mean estimation error per mode — calibrate the session_overhead_factor if systematic over/under persists.
246
+
247
+ `pipeline_verdict` enum includes `ESCALATE` — record it when Phase 3 required user decision before proceeding.
248
+
249
+ This data calibrates future estimates. Target: 10 prospective runs per mode before treating mode comparison as reliable. Runs with `budget_source: fallback-heuristic` calibrate the fallback tiers; runs with `token-budget-gate` calibrate the skill itself.
@@ -123,7 +123,7 @@ All 5 Steps completed
123
123
 
124
124
  ## References
125
125
 
126
- - Rule body: `memory feedback_command_tower_gate.md` (hub gate accumulated naming baseline) + `memory feedback_qasp_to_hub_sync_protocol.md` (Option C Hybrid sync policy)
126
+ - Rule body: `memory feedback_command_tower_gate.md` (hub gate accumulated naming baseline) + `memory feedback_field_to_hub_sync_protocol.md` (Option C Hybrid sync policy)
127
127
  - Consistency rules: `feedback_simplification_evidence` · `feedback_markdown_edit_discipline` · `feedback_skill_frontmatter_description_plain_text` · `feedback_bidirectional_self_validation` · `feedback_reference_own_hub_assets_first`
128
128
  - Sister skills: `cross-ecosystem-synergy-detection` (sister asset cluster baseline) · `verify-bidirectional` (bidirectional self-validation automation / self-catch auxiliary axis) · `harvest-loop` (weekly audit automation / operation proof accumulation cross-link)
129
129
  - Autonomous commit proposal §2.19 baseline: `memory feedback_autonomous_commit_proposal.md` (① development source automation + PR proposal under human approval)