@chrono-meta/fh-gate 3.30.0 → 3.31.0
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.
- package/.claude-plugin/marketplace.json +4 -4
- package/CLAUDE.md +1 -1
- package/README.ja.md +6 -5
- package/README.ko.md +6 -5
- package/README.md +15 -5
- package/README.zh.md +6 -5
- package/docs/REFERENCE.md +6 -5
- package/docs/USER_GUIDE.md +3 -0
- package/knowledge/shared/harness-core/dispatch_conditional_prohibition.md +42 -0
- package/knowledge/shared/harness-core/sonnet_floor_doctrine.md +7 -0
- package/knowledge/shared/learnings/subagent_invocations_log.yaml +56 -0
- package/package.json +5 -1
- package/plugins/fh-commons/.claude-plugin/plugin.json +1 -1
- package/plugins/fh-meta/.claude-plugin/plugin.json +1 -1
- package/plugins/fh-meta/CHANGELOG.md +16 -0
- package/plugins/fh-meta/skills/install-wizard/SKILL.md +25 -0
- package/plugins/fh-meta/skills/install-wizard/SKILL_detail.md +24 -6
- package/plugins/fh-preprep/.claude-plugin/plugin.json +1 -1
- package/plugins/fh-qp/.claude-plugin/plugin.json +1 -1
- package/scripts/abstract_consult_check.py +573 -0
- package/scripts/fh_detach.py +444 -0
- package/scripts/selfcheck.sh +83 -6
- package/scripts/test_abstract_consult_check_lanes.sh +201 -0
- package/scripts/test_fh_detach_lanes.sh +252 -0
- package/scripts/test_mutation_probe_lanes.sh +68 -8
- package/scripts/test_ollama_panel_lanes.sh +107 -11
- package/scripts/test_selfcheck_state_lanes.sh +73 -1
- package/templates/CLAUDE.md +16 -0
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""fh_detach.py — undo what /install-wizard wrote, and nothing else.
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
python3 scripts/fh_detach.py [--project DIR] [--fh-dir DIR] [--home DIR] [--apply] [--plugin]
|
|
6
|
+
|
|
7
|
+
Default is a dry run: it prints the plan and changes nothing. `--apply` carries it out.
|
|
8
|
+
|
|
9
|
+
What counts as FH's (each is removed only on an EXACT match with what the wizard writes today):
|
|
10
|
+
① ~/.zshrc the wizard's block (marked `# >>> forge-harness >>>` … or the older unmarked 4 lines)
|
|
11
|
+
② <dir>/.claude/settings.json · settings.local.json
|
|
12
|
+
hook entries equal in every field (key order ignored) to an entry in a shipped
|
|
13
|
+
templates/settings.*.snippet.json, or to the Mode-D companion hook form. A file the wizard created is deleted when
|
|
14
|
+
nothing else is left in it; if a .prewizard backup equals the stripped file, its bytes are
|
|
15
|
+
put back (so the user's own formatting returns).
|
|
16
|
+
③ <dir>/CLAUDE.local.md the «Companion-store session-start read» section the wizard appended
|
|
17
|
+
④ git core.hooksPath only when it is `templates/.git-hooks` (the wizard's value) in the FH clone
|
|
18
|
+
⑤ ~/.cc_sentinels/<project>_wizard_* (and the folder, when that leaves it empty)
|
|
19
|
+
⑥ .claude/rules/local_fh_context.md · fh_env_context.jsonc only when byte-equal to the shipped template,
|
|
20
|
+
plus their exact lines in .git/info/exclude
|
|
21
|
+
⑦ --plugin also runs `claude plugin uninstall` / `marketplace remove` for fh-meta@forge-harness
|
|
22
|
+
|
|
23
|
+
What it never does: delete a user's own hook (even one sharing a group or a script name with FH — a hook identical
|
|
24
|
+
to FH's shipped entry cannot be told apart and is treated as FH's), edit a line it did not write, or touch a file
|
|
25
|
+
it cannot parse (that is exit 10, file untouched). Scope: ① and ④ are machine/clone-wide, so this takes FH off the
|
|
26
|
+
whole setup, not one project.
|
|
27
|
+
|
|
28
|
+
Exit: 0 = no recognised FH trace left · 1 = something FH-like is left that needs a human look (listed) ·
|
|
29
|
+
10 = could not read something it needed (nothing changed past that point) · 11 = bad arguments.
|
|
30
|
+
"""
|
|
31
|
+
import argparse
|
|
32
|
+
import glob
|
|
33
|
+
import json
|
|
34
|
+
import os
|
|
35
|
+
import re
|
|
36
|
+
import shutil
|
|
37
|
+
import subprocess
|
|
38
|
+
import sys
|
|
39
|
+
|
|
40
|
+
ZSH_BEGIN = "# >>> forge-harness (install-wizard) >>>"
|
|
41
|
+
ZSH_END = "# <<< forge-harness (install-wizard) <<<"
|
|
42
|
+
LEGACY_ZSH = [
|
|
43
|
+
re.compile(r'^export FH_DIR=".*"$'),
|
|
44
|
+
re.compile(r'^export CC_HUB_DIR=".*"$'),
|
|
45
|
+
re.compile(r'^export CC_SENTINELS_DIR="\$HOME/\.cc_sentinels"$'),
|
|
46
|
+
re.compile(r'^source "\$FH_DIR/templates/fh_audit_check\.zsh"$'),
|
|
47
|
+
]
|
|
48
|
+
COMPANION_HEAD = "## Companion-store session-start read"
|
|
49
|
+
COMPANION_WIRING = ("At session start: read $BE_DIR/INDEX.md first; then ls -t paper-signals/ handoff/ digests/ and "
|
|
50
|
+
"open anything newer than the session card (card=pointer, store commit=truth) — not only handoffs.")
|
|
51
|
+
# Mode-D companion hooks (install-wizard SKILL_detail §Mode-D-Companion-Setup): BE_DIR is baked in at write time.
|
|
52
|
+
MODE_D_CMD = re.compile(r'^BE_DIR="[^"]*" bash "\$CLAUDE_PROJECT_DIR/scripts/(fh_session_load|fh_env_delta_scan)\.sh"$')
|
|
53
|
+
COPIED_TEMPLATES = (("local_fh_context.md", ".claude/rules/local_fh_context.md"),
|
|
54
|
+
("fh_env_context.jsonc", ".claude/rules/fh_env_context.jsonc"))
|
|
55
|
+
SCRIPT_KEY = re.compile(r'scripts/([A-Za-z0-9_\-]+\.sh)')
|
|
56
|
+
FH_HINT = re.compile(r'CLAUDE_PROJECT_DIR|forge-harness|FH_DIR')
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class HarnessError(Exception):
|
|
60
|
+
pass
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def read(p):
|
|
64
|
+
with open(p, encoding="utf-8") as f:
|
|
65
|
+
return f.read()
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def read_bytes(p):
|
|
69
|
+
with open(p, "rb") as f:
|
|
70
|
+
return f.read()
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def canon(h):
|
|
74
|
+
return json.dumps(h, sort_keys=True, ensure_ascii=False)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def snippet_commands(fh_dir):
|
|
78
|
+
"""Every hook entry the shipped snippets register — the exact objects the wizard writes (command AND every other
|
|
79
|
+
field: a hook whose timeout or message the user changed is theirs now, codex R1)."""
|
|
80
|
+
cmds, keys = set(), set()
|
|
81
|
+
snippets = sorted(glob.glob(os.path.join(fh_dir, "templates", "settings.*.snippet.json")))
|
|
82
|
+
if not snippets:
|
|
83
|
+
raise HarnessError("no templates/settings.*.snippet.json under %s — cannot tell FH hooks from yours" % fh_dir)
|
|
84
|
+
for s in snippets:
|
|
85
|
+
try:
|
|
86
|
+
blob = json.loads(read(s))
|
|
87
|
+
except (OSError, ValueError) as e:
|
|
88
|
+
raise HarnessError("unreadable snippet %s: %s" % (s, e))
|
|
89
|
+
for groups in ((blob.get("project_settings_json") or {}).get("hooks") or {}).values():
|
|
90
|
+
for g in groups if isinstance(groups, list) else []:
|
|
91
|
+
for h in g.get("hooks", []) if isinstance(g, dict) else []:
|
|
92
|
+
c = h.get("command") if isinstance(h, dict) else None
|
|
93
|
+
if isinstance(c, str):
|
|
94
|
+
cmds.add(canon(h))
|
|
95
|
+
keys.update(SCRIPT_KEY.findall(c))
|
|
96
|
+
keys.update({"fh_session_load.sh", "fh_env_delta_scan.sh"})
|
|
97
|
+
keys.update(os.path.basename(x) for x in glob.glob(os.path.join(fh_dir, "scripts", "*.sh")))
|
|
98
|
+
return cmds, keys
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def is_fh_hook(h, cmds):
|
|
102
|
+
if canon(h) in cmds:
|
|
103
|
+
return True
|
|
104
|
+
# Mode-D companion form: exactly {type, command, timeout 20} as the wizard writes it
|
|
105
|
+
return (set(h) == {"type", "command", "timeout"} and h.get("type") == "command" and h.get("timeout") == 20
|
|
106
|
+
and bool(MODE_D_CMD.match(h.get("command", ""))))
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def looks_fh(cmd, keys):
|
|
110
|
+
"""FH-like but not byte-equal (an older snippet version, a hand edit): reported, never removed."""
|
|
111
|
+
return bool(FH_HINT.search(cmd)) and any(k in SCRIPT_KEY.findall(cmd) for k in keys)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def strip_settings(d, cmds):
|
|
115
|
+
"""Return (stripped copy, removed commands). Keeps every non-FH hook, in order."""
|
|
116
|
+
out = json.loads(json.dumps(d))
|
|
117
|
+
removed = []
|
|
118
|
+
hooks = out.get("hooks")
|
|
119
|
+
if not isinstance(hooks, dict):
|
|
120
|
+
return out, removed
|
|
121
|
+
for ev in list(hooks):
|
|
122
|
+
groups = hooks[ev]
|
|
123
|
+
if not isinstance(groups, list):
|
|
124
|
+
continue
|
|
125
|
+
kept = []
|
|
126
|
+
for g in groups:
|
|
127
|
+
if not isinstance(g, dict) or not isinstance(g.get("hooks"), list):
|
|
128
|
+
kept.append(g)
|
|
129
|
+
continue
|
|
130
|
+
hs, took = [], False
|
|
131
|
+
for h in g["hooks"]:
|
|
132
|
+
c = h.get("command") if isinstance(h, dict) else None
|
|
133
|
+
if isinstance(c, str) and is_fh_hook(h, cmds):
|
|
134
|
+
removed.append(c)
|
|
135
|
+
took = True
|
|
136
|
+
else:
|
|
137
|
+
hs.append(h)
|
|
138
|
+
if hs or not took: # a group that was empty before is the user's — kept (codex R2)
|
|
139
|
+
g = dict(g)
|
|
140
|
+
g["hooks"] = hs
|
|
141
|
+
kept.append(g)
|
|
142
|
+
if kept:
|
|
143
|
+
hooks[ev] = kept
|
|
144
|
+
else:
|
|
145
|
+
del hooks[ev]
|
|
146
|
+
if not hooks:
|
|
147
|
+
del out["hooks"]
|
|
148
|
+
return out, removed
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def suspects_in(d, keys):
|
|
152
|
+
out = []
|
|
153
|
+
for groups in (d.get("hooks") or {}).values() if isinstance(d.get("hooks"), dict) else []:
|
|
154
|
+
for g in groups if isinstance(groups, list) else []:
|
|
155
|
+
for h in g.get("hooks", []) if isinstance(g, dict) else []:
|
|
156
|
+
c = h.get("command") if isinstance(h, dict) else None
|
|
157
|
+
if isinstance(c, str) and looks_fh(c, keys):
|
|
158
|
+
out.append(c)
|
|
159
|
+
return out
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
class Plan:
|
|
163
|
+
def __init__(self, apply):
|
|
164
|
+
self.apply = apply
|
|
165
|
+
self.actions = [] # (label, fn)
|
|
166
|
+
self.left = [] # FH-like traces left for a human
|
|
167
|
+
self.notes = []
|
|
168
|
+
|
|
169
|
+
def act(self, label, fn):
|
|
170
|
+
self.actions.append((label, fn))
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def plan_zshrc(plan, home):
|
|
174
|
+
p = os.path.join(home, ".zshrc")
|
|
175
|
+
if not os.path.isfile(p):
|
|
176
|
+
return
|
|
177
|
+
lines = read(p).split("\n")
|
|
178
|
+
out, i, hit = [], 0, 0
|
|
179
|
+
while i < len(lines):
|
|
180
|
+
if (lines[i] == ZSH_BEGIN and i + 5 < len(lines) and lines[i + 5] == ZSH_END
|
|
181
|
+
and all(LEGACY_ZSH[k].match(lines[i + 1 + k]) for k in range(4))):
|
|
182
|
+
i += 6 # markers bind only the wizard's exact four lines — anything added inside is the user's (codex R1)
|
|
183
|
+
hit += 1
|
|
184
|
+
continue
|
|
185
|
+
if lines[i] == ZSH_BEGIN and ZSH_END in lines[i:]:
|
|
186
|
+
j = lines.index(ZSH_END, i) + 1 # an edited block is the user's now — copied verbatim, never mined for
|
|
187
|
+
out.extend(lines[i:j]) # the four legacy lines (codex R2: that deleted them from inside the block)
|
|
188
|
+
i = j
|
|
189
|
+
continue
|
|
190
|
+
if i + 4 <= len(lines) and all(LEGACY_ZSH[k].match(lines[i + k]) for k in range(4)):
|
|
191
|
+
i += 4
|
|
192
|
+
hit += 1
|
|
193
|
+
continue
|
|
194
|
+
out.append(lines[i])
|
|
195
|
+
i += 1
|
|
196
|
+
if hit:
|
|
197
|
+
new = "\n".join(out)
|
|
198
|
+
seen = "\n".join(lines)
|
|
199
|
+
|
|
200
|
+
def do():
|
|
201
|
+
if read(p) != seen:
|
|
202
|
+
plan.left.append("~/.zshrc changed after the plan was made — not written; run detach again")
|
|
203
|
+
return
|
|
204
|
+
with open(p, "w", encoding="utf-8") as f:
|
|
205
|
+
f.write(new)
|
|
206
|
+
plan.act("~/.zshrc: remove the wizard block (%d)" % hit, do)
|
|
207
|
+
if any("fh_audit_check.zsh" in l or l in (ZSH_BEGIN, ZSH_END) for l in out):
|
|
208
|
+
plan.left.append("~/.zshrc: a line still sources fh_audit_check.zsh but is not the wizard's exact block")
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def plan_settings(plan, path, cmds, keys):
|
|
212
|
+
if not os.path.isfile(path):
|
|
213
|
+
return
|
|
214
|
+
try:
|
|
215
|
+
cur = json.loads(read(path))
|
|
216
|
+
except ValueError as e:
|
|
217
|
+
raise HarnessError("cannot parse %s (%s) — left untouched" % (path, e))
|
|
218
|
+
if not isinstance(cur, dict):
|
|
219
|
+
raise HarnessError("%s is not a JSON object — left untouched" % path)
|
|
220
|
+
stripped, removed = strip_settings(cur, cmds)
|
|
221
|
+
for c in suspects_in(stripped, keys):
|
|
222
|
+
plan.left.append("%s: FH-like hook that is not byte-equal to a shipped snippet (older version?) — %s"
|
|
223
|
+
% (path, c[:120]))
|
|
224
|
+
bak = path + ".prewizard"
|
|
225
|
+
restore = drop_bak = None
|
|
226
|
+
if os.path.isfile(bak):
|
|
227
|
+
try:
|
|
228
|
+
prev_stripped, prev_fh = strip_settings(json.loads(read(bak)), cmds)
|
|
229
|
+
if prev_stripped == stripped:
|
|
230
|
+
if prev_fh:
|
|
231
|
+
drop_bak = bak # a re-run's backup: it holds only FH hooks beyond what stays (codex R2)
|
|
232
|
+
else:
|
|
233
|
+
restore = bak
|
|
234
|
+
except ValueError:
|
|
235
|
+
pass
|
|
236
|
+
seen = read(path)
|
|
237
|
+
if not removed and restore is None and drop_bak is None:
|
|
238
|
+
if os.path.isfile(bak):
|
|
239
|
+
plan.notes.append("%s: kept (it differs from your current settings — open it, delete it when done)" % bak)
|
|
240
|
+
return
|
|
241
|
+
|
|
242
|
+
def do():
|
|
243
|
+
if read(path) != seen: # another session wrote it after the plan (codex R2) — never overwrite their change
|
|
244
|
+
plan.left.append("%s changed after the plan was made — not written; run detach again" % path)
|
|
245
|
+
return
|
|
246
|
+
if drop_bak:
|
|
247
|
+
os.remove(drop_bak)
|
|
248
|
+
if restore:
|
|
249
|
+
shutil.copy2(restore, path)
|
|
250
|
+
os.remove(restore)
|
|
251
|
+
elif not stripped:
|
|
252
|
+
os.remove(path)
|
|
253
|
+
else:
|
|
254
|
+
with open(path, "w", encoding="utf-8") as f:
|
|
255
|
+
json.dump(stripped, f, indent=2, ensure_ascii=False)
|
|
256
|
+
f.write("\n")
|
|
257
|
+
how = ("restore your pre-wizard bytes from .prewizard" if restore
|
|
258
|
+
else "delete the file (only FH hooks were in it)" if not stripped
|
|
259
|
+
else "remove %d FH hook(s), keep the rest" % len(removed))
|
|
260
|
+
plan.act("%s: %s" % (path, how), do)
|
|
261
|
+
if os.path.isfile(bak) and not restore and not drop_bak:
|
|
262
|
+
plan.notes.append("%s: kept (it differs from your current settings — open it, delete it when done)" % bak)
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def plan_claude_local(plan, d):
|
|
266
|
+
p = os.path.join(d, "CLAUDE.local.md")
|
|
267
|
+
if not os.path.isfile(p):
|
|
268
|
+
return
|
|
269
|
+
s = read(p)
|
|
270
|
+
block = "\n%s\n%s\n" % (COMPANION_HEAD, COMPANION_WIRING)
|
|
271
|
+
if block in s:
|
|
272
|
+
new = s.replace(block, "", 1)
|
|
273
|
+
|
|
274
|
+
def do():
|
|
275
|
+
if new:
|
|
276
|
+
with open(p, "w", encoding="utf-8") as f:
|
|
277
|
+
f.write(new)
|
|
278
|
+
else:
|
|
279
|
+
os.remove(p)
|
|
280
|
+
plan.act("%s: remove the wizard's companion-store section" % p, do)
|
|
281
|
+
elif COMPANION_HEAD in s:
|
|
282
|
+
plan.left.append("%s: a «%s» section that is not the wizard's exact text" % (p, COMPANION_HEAD))
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
def plan_hookspath(plan, fh_dir):
|
|
286
|
+
if not os.path.isdir(os.path.join(fh_dir, ".git")) and not os.path.isfile(os.path.join(fh_dir, ".git")):
|
|
287
|
+
return
|
|
288
|
+
r = subprocess.run(["git", "-C", fh_dir, "config", "--local", "--get", "core.hooksPath"],
|
|
289
|
+
capture_output=True, text=True)
|
|
290
|
+
v = r.stdout.strip()
|
|
291
|
+
if r.returncode not in (0, 1):
|
|
292
|
+
raise HarnessError("git config read failed in %s: %s" % (fh_dir, r.stderr.strip()))
|
|
293
|
+
if v == "templates/.git-hooks":
|
|
294
|
+
plan.act("%s: unset core.hooksPath (templates/.git-hooks)" % fh_dir,
|
|
295
|
+
lambda: subprocess.run(["git", "-C", fh_dir, "config", "--local", "--unset", "core.hooksPath"],
|
|
296
|
+
check=True))
|
|
297
|
+
elif v and "templates/.git-hooks" in v:
|
|
298
|
+
plan.left.append("%s: core.hooksPath=%s (not the wizard's value — left alone)" % (fh_dir, v))
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
def plan_sentinels(plan, home, project):
|
|
302
|
+
d = os.path.join(home, ".cc_sentinels")
|
|
303
|
+
if not os.path.isdir(d):
|
|
304
|
+
return
|
|
305
|
+
mine = sorted(glob.glob(os.path.join(d, glob.escape(project) + "_wizard_*")))
|
|
306
|
+
rest = sorted(set(os.listdir(d)) - {os.path.basename(m) for m in mine})
|
|
307
|
+
|
|
308
|
+
def do():
|
|
309
|
+
for m in mine:
|
|
310
|
+
os.remove(m)
|
|
311
|
+
if not os.listdir(d):
|
|
312
|
+
os.rmdir(d)
|
|
313
|
+
if mine:
|
|
314
|
+
plan.act("~/.cc_sentinels: remove %s" % ", ".join(os.path.basename(m) for m in mine), do)
|
|
315
|
+
if rest:
|
|
316
|
+
plan.notes.append("~/.cc_sentinels: %d other file(s) kept (other projects or audit stamps): %s"
|
|
317
|
+
% (len(rest), ", ".join(rest[:6])))
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def _exclude_path(proj):
|
|
321
|
+
""".git/info/exclude through git itself — in a worktree .git is a file and the exclude lives in the common dir."""
|
|
322
|
+
r = subprocess.run(["git", "-C", proj, "rev-parse", "--path-format=absolute", "--git-path", "info/exclude"],
|
|
323
|
+
capture_output=True, text=True)
|
|
324
|
+
return r.stdout.strip() if r.returncode == 0 and r.stdout.strip() else None
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
def plan_copies(plan, fh_dir, proj):
|
|
328
|
+
excl = _exclude_path(proj)
|
|
329
|
+
removed = set()
|
|
330
|
+
for src, rel in COPIED_TEMPLATES:
|
|
331
|
+
dst = os.path.join(proj, rel)
|
|
332
|
+
tpl = os.path.join(fh_dir, "templates", src)
|
|
333
|
+
if os.path.isfile(dst):
|
|
334
|
+
# bytes, not text: universal-newline reading called a CRLF-converted copy «unchanged» (codex R1)
|
|
335
|
+
if os.path.isfile(tpl) and read_bytes(dst) == read_bytes(tpl):
|
|
336
|
+
plan.act("%s: remove (unchanged copy of templates/%s)" % (dst, src),
|
|
337
|
+
lambda dst=dst: os.remove(dst))
|
|
338
|
+
removed.add(rel)
|
|
339
|
+
else:
|
|
340
|
+
plan.left.append("%s: you edited this copy of templates/%s — kept" % (dst, src))
|
|
341
|
+
elif not os.path.lexists(dst):
|
|
342
|
+
removed.add(rel) # copy already gone (a rerun after a partial apply, codex R2) — its exclude goes too
|
|
343
|
+
if excl and os.path.isfile(excl) and removed:
|
|
344
|
+
lines = read(excl).split("\n")
|
|
345
|
+
# only the lines of copies removed above — a kept copy keeps its exclude, or git would start staging it (codex R1)
|
|
346
|
+
drop = removed | {"/" + rel for rel in removed}
|
|
347
|
+
new = [l for l in lines if l.strip() not in drop]
|
|
348
|
+
if new != lines:
|
|
349
|
+
def do():
|
|
350
|
+
with open(excl, "w", encoding="utf-8") as f:
|
|
351
|
+
f.write("\n".join(new))
|
|
352
|
+
plan.act("%s: remove the wizard's exclude line(s)" % excl, do)
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
def plan_rules_dir(plan, proj):
|
|
356
|
+
"""Remove .claude/rules and .claude when the steps above leave them empty (checked at apply time)."""
|
|
357
|
+
def do():
|
|
358
|
+
for d in (os.path.join(proj, ".claude", "rules"), os.path.join(proj, ".claude")):
|
|
359
|
+
if os.path.isdir(d) and not os.listdir(d):
|
|
360
|
+
os.rmdir(d)
|
|
361
|
+
plan.actions.append((None, do))
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
def plan_plugin(plan):
|
|
365
|
+
def do():
|
|
366
|
+
for argv in (["claude", "plugin", "uninstall", "fh-meta@forge-harness"],
|
|
367
|
+
["claude", "plugin", "marketplace", "remove", "forge-harness"]):
|
|
368
|
+
try:
|
|
369
|
+
r = subprocess.run(argv, capture_output=True, text=True)
|
|
370
|
+
rc, msg = r.returncode, (r.stdout + r.stderr).strip()
|
|
371
|
+
except OSError as e:
|
|
372
|
+
rc, msg = 127, str(e)
|
|
373
|
+
print(" $ %s → rc=%d %s" % (" ".join(argv), rc, msg[:160]))
|
|
374
|
+
if rc != 0: # a failed uninstall is a trace left, not a success (codex R1)
|
|
375
|
+
plan.left.append("plugin: `%s` failed (rc=%d) — run it yourself" % (" ".join(argv), rc))
|
|
376
|
+
plan.act("claude plugin: uninstall fh-meta@forge-harness · remove the forge-harness marketplace", do)
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
def main(argv=None):
|
|
380
|
+
ap = argparse.ArgumentParser(
|
|
381
|
+
description="Undo what /install-wizard wrote (dry run unless --apply). Machine-wide: the ~/.zshrc block and "
|
|
382
|
+
"the FH clone's hooks and core.hooksPath go too, not only --project.",
|
|
383
|
+
epilog="exit: 0 no recognised FH trace left · 1 something FH-like is LEFT (listed) for a human look · "
|
|
384
|
+
"10 could not read something it needed · 11 bad arguments")
|
|
385
|
+
ap.add_argument("--project", default=os.getcwd(), help="project the wizard ran in (default: cwd)")
|
|
386
|
+
ap.add_argument("--fh-dir", default=os.environ.get("FH_DIR") or os.path.dirname(os.path.dirname(
|
|
387
|
+
os.path.abspath(__file__))), help="FH clone/package (default: $FH_DIR, else this script's repo)")
|
|
388
|
+
ap.add_argument("--home", default=os.path.expanduser("~"), help="home directory to clean (default: ~)")
|
|
389
|
+
ap.add_argument("--apply", action="store_true", help="carry out the plan (default: print it, change nothing)")
|
|
390
|
+
ap.add_argument("--plugin", action="store_true",
|
|
391
|
+
help="also uninstall fh-meta@forge-harness and remove the forge-harness marketplace entry")
|
|
392
|
+
try:
|
|
393
|
+
a = ap.parse_args(argv)
|
|
394
|
+
except SystemExit as e:
|
|
395
|
+
return 11 if e.code else 0
|
|
396
|
+
proj = os.path.abspath(a.project)
|
|
397
|
+
fh = os.path.abspath(a.fh_dir)
|
|
398
|
+
plan = Plan(a.apply)
|
|
399
|
+
try:
|
|
400
|
+
cmds, keys = snippet_commands(fh)
|
|
401
|
+
plan_zshrc(plan, a.home)
|
|
402
|
+
seen = set()
|
|
403
|
+
for d in (proj, fh):
|
|
404
|
+
if d in seen:
|
|
405
|
+
continue
|
|
406
|
+
seen.add(d)
|
|
407
|
+
for name in ("settings.json", "settings.local.json"):
|
|
408
|
+
plan_settings(plan, os.path.join(d, ".claude", name), cmds, keys)
|
|
409
|
+
plan_claude_local(plan, d)
|
|
410
|
+
plan_hookspath(plan, fh)
|
|
411
|
+
plan_sentinels(plan, a.home, os.path.basename(proj))
|
|
412
|
+
plan_copies(plan, fh, proj)
|
|
413
|
+
plan_rules_dir(plan, proj)
|
|
414
|
+
if a.plugin:
|
|
415
|
+
plan_plugin(plan)
|
|
416
|
+
except HarnessError as e:
|
|
417
|
+
print("fh-detach: HARNESS-ERROR — %s" % e, file=sys.stderr)
|
|
418
|
+
return 10
|
|
419
|
+
steps = [l for l, _ in plan.actions if l]
|
|
420
|
+
print("fh-detach %s — %d step(s)" % ("APPLY" if a.apply else "DRY RUN (nothing changed; add --apply)", len(steps)))
|
|
421
|
+
for l in steps:
|
|
422
|
+
print(" - " + l)
|
|
423
|
+
if a.apply:
|
|
424
|
+
for label, fn in plan.actions:
|
|
425
|
+
try:
|
|
426
|
+
fn()
|
|
427
|
+
except (OSError, subprocess.CalledProcessError) as e:
|
|
428
|
+
print("fh-detach: HARNESS-ERROR at «%s»: %s" % (label, e), file=sys.stderr)
|
|
429
|
+
return 10
|
|
430
|
+
for n in plan.notes:
|
|
431
|
+
print(" note: " + n)
|
|
432
|
+
for l in plan.left:
|
|
433
|
+
print(" LEFT (look at it): " + l)
|
|
434
|
+
if not a.plugin:
|
|
435
|
+
print(" plugin: if you installed it, run `claude plugin uninstall fh-meta@forge-harness` (or pass --plugin)")
|
|
436
|
+
if plan.left:
|
|
437
|
+
return 1
|
|
438
|
+
if not a.apply and steps:
|
|
439
|
+
return 0
|
|
440
|
+
return 0
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
if __name__ == "__main__":
|
|
444
|
+
sys.exit(main())
|
package/scripts/selfcheck.sh
CHANGED
|
@@ -970,8 +970,12 @@ fi
|
|
|
970
970
|
# `SELFCHECK: FAIL` with no FAIL line in 6,236 lines — the killed suite fell into a bare `*)`
|
|
971
971
|
# that set fail and printed nothing (fh_signal_2026-10-18_selfcheck-timeout-unlabelled). The
|
|
972
972
|
# catch-all now names the suite and its rc, so no exit code can fail without a line.
|
|
973
|
-
_pair_rc_verdict() { # $1=label $2=subject $3=rc · return 1 = counts as a failure
|
|
974
|
-
|
|
973
|
+
_pair_rc_verdict() { # $1=label $2=subject $3=rc $4=budget seconds (optional) · return 1 = counts as a failure
|
|
974
|
+
# $4 defaults to the table's default rather than being required: the lane suite lifts this
|
|
975
|
+
# function and calls it with three arguments, and so does any future caller that has no budget
|
|
976
|
+
# of its own. A hardcoded "300" in the message below was wrong the moment budgets stopped being
|
|
977
|
+
# one number — a verdict line that names a limit the run did not use is a confident wrong fact.
|
|
978
|
+
local _lbl="$1" _subj="$2" _rc="$3" _bud="${4:-${_LANE_BUDGET_DEFAULT:-300}}"
|
|
975
979
|
case "$_rc" in
|
|
976
980
|
0) ;;
|
|
977
981
|
# The suite could not MEASURE. Distinguished from "the lane failed" because the two send a
|
|
@@ -990,9 +994,11 @@ _pair_rc_verdict() { # $1=label $2=subject $3=rc · return 1 = counts as a failu
|
|
|
990
994
|
echo " prove nothing about $_subj. Not a lane failure, and not a pass either."
|
|
991
995
|
return 1 ;;
|
|
992
996
|
124)
|
|
993
|
-
echo "TIMEOUT $_lbl: exited 124, the code \`timeout\` uses when it kills a suite (
|
|
997
|
+
echo "TIMEOUT $_lbl: exited 124, the code \`timeout\` uses when it kills a suite (budget ${_bud} s) —"
|
|
994
998
|
echo " not measured, not a pass. A suite that itself exits 124 lands here too."
|
|
995
999
|
echo " Re-run that suite alone to see whether it hangs or is only slow under load."
|
|
1000
|
+
echo " If it needs longer than ${_bud} s on a healthy host, raise ITS budget in"
|
|
1001
|
+
echo " _lane_budget() with the measurement that set the number — do not raise the default."
|
|
996
1002
|
return 1 ;;
|
|
997
1003
|
*)
|
|
998
1004
|
echo "FAIL $_lbl (rc=$_rc) — see that suite's output above; subject: $_subj"
|
|
@@ -1000,7 +1006,44 @@ _pair_rc_verdict() { # $1=label $2=subject $3=rc · return 1 = counts as a failu
|
|
|
1000
1006
|
esac
|
|
1001
1007
|
return 0
|
|
1002
1008
|
}
|
|
1003
|
-
|
|
1009
|
+
# Per-suite lane budget (2026-10-26). Until today every suite in the loop below ran under one
|
|
1010
|
+
# global `timeout 300`, and that number was invisible: nothing printed how long a suite took, so
|
|
1011
|
+
# the only way to learn a suite was near the limit was for it to cross it.
|
|
1012
|
+
#
|
|
1013
|
+
# MEASURED, in a clean cloud container on 2026-10-26: test_mutation_probe_lanes.sh takes 318–322 s
|
|
1014
|
+
# standalone (3 reps, 122 lanes, all green) and selfcheck killed it at 300. Neither the suite nor
|
|
1015
|
+
# its subject (scripts/mutation_probe.py) had changed since the run where it last passed — the host
|
|
1016
|
+
# got slower, the margin was never managed, and the result was one TIMEOUT line standing in for 122
|
|
1017
|
+
# known-pair lanes that went UNMEASURED. Timestamping the suite showed the cost is spread across it
|
|
1018
|
+
# (largest single block +40 s), so "make it faster" is not a small fix and would not be this one.
|
|
1019
|
+
#
|
|
1020
|
+
# So: the budget is per suite, declared next to the measurement that set it, and the loop prints an
|
|
1021
|
+
# advisory line BEFORE the kill when a run eats most of its budget. The default stays 300 — a suite
|
|
1022
|
+
# that needs more says so by name, which is the record a reader can argue with.
|
|
1023
|
+
_LANE_BUDGET_DEFAULT=300
|
|
1024
|
+
_LANE_BUDGET_WARN_PCT=80 # advisory at ≥80% of budget; advisory only, never a verdict
|
|
1025
|
+
_lane_budget() { # $1=label → budget in seconds
|
|
1026
|
+
case "$1" in
|
|
1027
|
+
# 318–322 s measured standalone (above). 600 is ~1.9× the measured cost: enough head-room for a
|
|
1028
|
+
# host slower than this one, and still a bound — not "no timeout", which is how the suite that
|
|
1029
|
+
# detects a broken watchdog would inherit a hang (see the loop's own comment below).
|
|
1030
|
+
test_mutation_probe_lanes.sh) echo 600 ;;
|
|
1031
|
+
*) echo "${_LANE_BUDGET_DEFAULT}" ;;
|
|
1032
|
+
esac
|
|
1033
|
+
}
|
|
1034
|
+
# A run that finished INSIDE its budget but close to it is the state nobody saw last week. It is an
|
|
1035
|
+
# advisory, printed and not counted: a suite at 85% of budget has measured everything it claims to,
|
|
1036
|
+
# and folding "nearly ran out" into FAIL would be the same untyped-verdict defect in the other
|
|
1037
|
+
# direction. `date` only — /usr/bin/time is absent in some containers (measured rc=127 here).
|
|
1038
|
+
_lane_margin_note() { # $1=label $2=elapsed s $3=budget s
|
|
1039
|
+
local _lbl="$1" _el="$2" _bud="$3" _pct
|
|
1040
|
+
[ "$_bud" -gt 0 ] 2>/dev/null || return 0
|
|
1041
|
+
_pct=$(( _el * 100 / _bud ))
|
|
1042
|
+
[ "$_pct" -ge "${_LANE_BUDGET_WARN_PCT:-80}" ] || return 0
|
|
1043
|
+
echo "NOTE $_lbl took ${_el} s of its ${_bud} s budget (${_pct}%) — it PASSED; this is margin,"
|
|
1044
|
+
echo " not a failure. A slower host crosses the limit and the suite's lanes go UNMEASURED."
|
|
1045
|
+
}
|
|
1046
|
+
_LANE_TO=""; command -v timeout >/dev/null 2>&1 && _LANE_TO="timeout ${_LANE_BUDGET_DEFAULT}"
|
|
1004
1047
|
for _pair in \
|
|
1005
1048
|
`# 사용 원장 (2026-09-13 신설). SUBJECT 를 원장 모듈로 잡는다 — 배선이 끊기는 자리는 preprep.py 의 __main__ 한 줄이 아니라 모듈이 사라지는 쪽이고, import 가 try/except 라 모듈이 없으면 조용히 무동작으로 돌아간다. 그 무음이 이 레인이 잡을 것이다.` \
|
|
1006
1049
|
"plugins/fh-preprep/skills/preprep/usage_ledger.py|scripts/test_usage_ledger_lanes.sh" \
|
|
@@ -1153,8 +1196,16 @@ do
|
|
|
1153
1196
|
# --self-test loop below, because `timeout` is GNU coreutils and stock macOS has neither it nor
|
|
1154
1197
|
# a substitute; without it `< /dev/null` is the whole defence and a suite that reads stdin ends
|
|
1155
1198
|
# immediately instead of waiting forever.
|
|
1156
|
-
|
|
1157
|
-
|
|
1199
|
+
# The budget is resolved per suite into a LOCAL variable; `$_LANE_TO` keeps the default and is
|
|
1200
|
+
# read again by two blocks far below this loop (relay_channel, directional_diff_gate), so
|
|
1201
|
+
# reassigning it here would silently hand one suite's budget to unrelated dispatches.
|
|
1202
|
+
_bud="$(_lane_budget "$_lbl")"
|
|
1203
|
+
_lane_to=""; command -v timeout >/dev/null 2>&1 && _lane_to="timeout $_bud"
|
|
1204
|
+
_t0=$(date +%s 2>/dev/null || echo 0)
|
|
1205
|
+
$_lane_to bash "$_anc" < /dev/null; _rc=$?
|
|
1206
|
+
_t1=$(date +%s 2>/dev/null || echo 0)
|
|
1207
|
+
[ "$_t0" -gt 0 ] 2>/dev/null && _lane_margin_note "$_lbl" "$(( _t1 - _t0 ))" "$_bud"
|
|
1208
|
+
_pair_rc_verdict "$_lbl" "$_subj" "$_rc" "$_bud" || fail=1
|
|
1158
1209
|
elif _pkg_accepted_absent "$_anc"; then
|
|
1159
1210
|
# DECLARED legitimately unshipped — the single source for that answer, not a guess from the
|
|
1160
1211
|
# environment. The first draft printed "this package predates it", which is a WRONG DIAGNOSIS
|
|
@@ -2261,6 +2312,32 @@ else
|
|
|
2261
2312
|
fail=1
|
|
2262
2313
|
fi
|
|
2263
2314
|
|
|
2315
|
+
# 가린 질문 송신 전 검사(거주 원칙 세 번째 길, D1) — 레포 식별자 · 작성자 · 원문 조각 · 운영자 리터럴(위 가드 재사용).
|
|
2316
|
+
# 레인이 걸림/통과 아는 쌍과 미측정 6갈래(사전 · 가드 · 레포 · 빈 목록 · 빈 질문 · 공개 말뭉치)를 같이 잰다. 호출자 0 — 기본 꺼짐.
|
|
2317
|
+
if [ ! -f scripts/abstract_consult_check.py ]; then
|
|
2318
|
+
_absent_subject_verdict "test_abstract_consult_check_lanes.sh" "scripts/abstract_consult_check.py" || fail=1
|
|
2319
|
+
elif [ -f scripts/test_abstract_consult_check_lanes.sh ]; then
|
|
2320
|
+
if ! bash scripts/test_abstract_consult_check_lanes.sh; then
|
|
2321
|
+
fail=1
|
|
2322
|
+
fi
|
|
2323
|
+
else
|
|
2324
|
+
echo "FAIL test_abstract_consult_check_lanes.sh: abstract_consult_check.py present but its anchor is missing"
|
|
2325
|
+
fail=1
|
|
2326
|
+
fi
|
|
2327
|
+
|
|
2328
|
+
# 떼기 — install-wizard 가 쓴 흔적만 되돌린다. 레인은 마법사 문서의 설치 블록을 그대로 뽑아 임시 HOME 에서 돌리고,
|
|
2329
|
+
# 떼기 뒤 트리가 설치 전과 바이트까지 같은지 본다(사용자 자기 훅 · 고친 복사본 · 옛 판 훅은 남기고 LEFT).
|
|
2330
|
+
if [ ! -f scripts/fh_detach.py ]; then
|
|
2331
|
+
_absent_subject_verdict "test_fh_detach_lanes.sh" "scripts/fh_detach.py" || fail=1
|
|
2332
|
+
elif [ -f scripts/test_fh_detach_lanes.sh ]; then
|
|
2333
|
+
if ! bash scripts/test_fh_detach_lanes.sh; then
|
|
2334
|
+
fail=1
|
|
2335
|
+
fi
|
|
2336
|
+
else
|
|
2337
|
+
echo "FAIL test_fh_detach_lanes.sh: fh_detach.py present but its anchor is missing"
|
|
2338
|
+
fail=1
|
|
2339
|
+
fi
|
|
2340
|
+
|
|
2264
2341
|
# outbound-query PreToolUse 훅 — 위 CLI 가드의 **배선**(WebSearch|WebFetch). 레인이 두 층 판정
|
|
2265
2342
|
# (override→deny · defaults→advisory), 미측정 4가지→deny, N/A 무음, 그리고 🟥 «출력에 토큰 값이
|
|
2266
2343
|
# 없다»(H10)를 각각 짝으로 잡는다. 마지막 것이 이 훅의 존재 이유를 지키는 레인이다.
|