@tyhld/conductor 0.12.187 → 0.12.188
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/package.json
CHANGED
package/scripts/hooks/policy.py
CHANGED
|
@@ -2428,9 +2428,19 @@ def is_inplace_edit(verb: str, tokens) -> bool:
|
|
|
2428
2428
|
# 1) 危険(deny)
|
|
2429
2429
|
# ═════════════════════════════════════════════════════════════════════════════
|
|
2430
2430
|
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2431
|
+
#: 強い上書きの push の字面(全文・小文字で当てる)。
|
|
2432
|
+
_FORCE_PUSH_RE = re.compile(r'git\s+push\b[^;&|\n]*?(--force(-with-lease)?\b|(?:^|\s)-f(?:\s|$)|\s\+\S)')
|
|
2433
|
+
|
|
2434
|
+
|
|
2435
|
+
def _danger_patterns(low: str, command: str = None):
|
|
2436
|
+
"""全文(小文字)に対する無条件の危険。変数へ直書きされたものも文字列として拾う。
|
|
2437
|
+
|
|
2438
|
+
★command(元の字面)を渡したときだけ、強い上書きの push の字が【探すだけの道具の
|
|
2439
|
+
引用符の中】にだけ在る形を免じる(_push_only_in_search_words・便 b6410117)。
|
|
2440
|
+
渡さなければ今までどおり字面だけで止める。
|
|
2441
|
+
"""
|
|
2442
|
+
if _FORCE_PUSH_RE.search(low) and not (command is not None
|
|
2443
|
+
and _push_only_in_search_words(command)):
|
|
2434
2444
|
return 'force push'
|
|
2435
2445
|
if re.search(r'git\s+reset\b[^;&|\n]*--hard\b', low):
|
|
2436
2446
|
return 'git reset --hard'
|
|
@@ -4066,6 +4076,50 @@ def _rm_only_in_search_words(command: str) -> bool:
|
|
|
4066
4076
|
return found_in_search_words
|
|
4067
4077
|
|
|
4068
4078
|
|
|
4079
|
+
# 引用符の外の push の字(探す言葉の外に push の命令が在るかを見る形)。
|
|
4080
|
+
_GIT_PUSH_WORD_RE = re.compile(r'\bgit\s+push\b')
|
|
4081
|
+
|
|
4082
|
+
#: 探す道具に別の命令を走らせる旗(git grep の -O・rg の --pre・ag/ack/ugrep の --pager・ugrep の --filter)。
|
|
4083
|
+
# ★これが付いた行は、引用符の中の字が命令として動き得るので免じない。
|
|
4084
|
+
_SEARCH_EXEC_LONG_FLAGS = ('--open-files-in-pager', '--pre', '--pager', '--filter')
|
|
4085
|
+
|
|
4086
|
+
|
|
4087
|
+
def _search_runs_command(toks) -> bool:
|
|
4088
|
+
"""探す道具の語に、別の命令を走らせる旗が在るか(★まとめ書きの短い旗の O も数える)。"""
|
|
4089
|
+
for t in toks:
|
|
4090
|
+
if t.startswith('--'):
|
|
4091
|
+
if t.split('=', 1)[0] in _SEARCH_EXEC_LONG_FLAGS:
|
|
4092
|
+
return True
|
|
4093
|
+
elif t.startswith('-') and 'O' in t[1:]:
|
|
4094
|
+
return True
|
|
4095
|
+
return False
|
|
4096
|
+
|
|
4097
|
+
|
|
4098
|
+
def _push_only_in_search_words(command: str) -> bool:
|
|
4099
|
+
"""強い上書きの push の字が【探すだけの道具の引用符の中】にだけ在るか(便 b6410117)。
|
|
4100
|
+
|
|
4101
|
+
【なぜ要るか(実地 便 311545fe・40fc68ed・2026-11-14)】読むだけの git grep の探す言葉に
|
|
4102
|
+
禁止の一覧の1行(git push と + の参照)を書いただけで danger: force push で止まり、
|
|
4103
|
+
便が2本途中で終わった。rm の字のときと同じ考え方で直す(_rm_only_in_search_words・便 915694ac)。
|
|
4104
|
+
★免じるのはこれが True のときだけ。少しでも判断が付かなければ False(=止める側へ倒す)。
|
|
4105
|
+
・強い上書きの push の字が在るセグメントで、引用符の外に git push の字が在れば False。
|
|
4106
|
+
・そのセグメントが探すだけの道具でなければ False。
|
|
4107
|
+
・置き換えの実行(`$(`・逆引用符)や、別の命令を走らせる旗が在れば False。
|
|
4108
|
+
・どこにも見つからなければ False(ヒアドキュメントの本文など=安全側)。
|
|
4109
|
+
"""
|
|
4110
|
+
found_in_search_words = False
|
|
4111
|
+
for seg in split_commands(command, bodies=False):
|
|
4112
|
+
if not _FORCE_PUSH_RE.search(seg.lower()):
|
|
4113
|
+
continue
|
|
4114
|
+
if _GIT_PUSH_WORD_RE.search(_blank_quoted(seg).lower()):
|
|
4115
|
+
return False # 囲みの外に在る=本物の push として扱う
|
|
4116
|
+
toks = tokens_of(seg)
|
|
4117
|
+
if '$(' in seg or '`' in seg or not _is_search_only(toks) or _search_runs_command(toks):
|
|
4118
|
+
return False
|
|
4119
|
+
found_in_search_words = True
|
|
4120
|
+
return found_in_search_words
|
|
4121
|
+
|
|
4122
|
+
|
|
4069
4123
|
def _rm_target_risk(token: str, work_dir: str = None) -> str:
|
|
4070
4124
|
"""削除の対象1つぶんの危険度。★シェルの飾り付きの字面と素の字面の、危ない方を採る。
|
|
4071
4125
|
|
|
@@ -7197,7 +7251,7 @@ def _bash_danger_plain(command: str, cwd=None, outside_grep_tree=True):
|
|
|
7197
7251
|
測り直すときに使う(便 dbf1e335・_recursive_read_danger の同名の引数)。
|
|
7198
7252
|
"""
|
|
7199
7253
|
# ---- 1) 危険(全文) ----
|
|
7200
|
-
hit = _danger_patterns(command.lower()) or _printenv_danger(command)
|
|
7254
|
+
hit = _danger_patterns(command.lower(), command) or _printenv_danger(command)
|
|
7201
7255
|
if hit:
|
|
7202
7256
|
return hit
|
|
7203
7257
|
hit = _rm_danger(command)
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""探す言葉の中の push の字を、強い上書きの push として止めない検査(便 b6410117)。
|
|
3
|
+
|
|
4
|
+
実行: python3 scripts/hooks/test_search_word_push.py
|
|
5
|
+
1件でも期待と違えば exit 1。
|
|
6
|
+
|
|
7
|
+
【なぜ要るか(実地 便 311545fe・40fc68ed・2026-11-14)】
|
|
8
|
+
読むだけの git grep の探す言葉に、禁止の一覧の1行(git push と + の参照)を書いただけで
|
|
9
|
+
`danger: force push` で止まり、便が2本途中で終わった。前に rm の字で同じことが起きたときの
|
|
10
|
+
直し(便 915694ac・_rm_only_in_search_words)と同じ考え方で直す(えふさん決定 2026-11-15)。
|
|
11
|
+
|
|
12
|
+
【ここで固定すること】
|
|
13
|
+
(a) 通る … 止められた2件の命令そのもの・探す言葉の中の --force/-f/--force-with-lease/+ の参照
|
|
14
|
+
(b) 止める(danger)… 本物の強い上書きの push(+ の参照・--force・-f・--force-with-lease)・
|
|
15
|
+
探す命令の後ろにつないだ本物の push・包みの中・置き換えの実行・別の命令を走らせる旗・
|
|
16
|
+
ヒアドキュメントの本文
|
|
17
|
+
(c) rm のときの直し(便 915694ac)も今までどおり
|
|
18
|
+
(d) 空振り確認(免じる所を外すと (a) が落ちる)
|
|
19
|
+
★この台本は危険語・秘密の形の名前を素の字で置かない(組み立てて使う)。既存の作法どおり。
|
|
20
|
+
"""
|
|
21
|
+
import os
|
|
22
|
+
import shutil
|
|
23
|
+
import sys
|
|
24
|
+
import tempfile
|
|
25
|
+
|
|
26
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
27
|
+
|
|
28
|
+
import policy # noqa: E402
|
|
29
|
+
|
|
30
|
+
failures = []
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def check(label, got, want):
|
|
34
|
+
ok = got == want
|
|
35
|
+
if not ok:
|
|
36
|
+
failures.append(f'{label}: got={got!r} want={want!r}')
|
|
37
|
+
print(f'{"OK " if ok else "NG "} {label:64} {str(got)[:40]}')
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
# ── 部品(危険語を直接書かない) ──
|
|
41
|
+
PUSH = 'pu' + 'sh'
|
|
42
|
+
GP = 'git ' + PUSH
|
|
43
|
+
FORCE = '--for' + 'ce'
|
|
44
|
+
LEASE = FORCE + '-with-lease'
|
|
45
|
+
SHORT = '-' + 'f'
|
|
46
|
+
RM = 'r' + 'm'
|
|
47
|
+
NPMRC = '.npm' + 'rc'
|
|
48
|
+
|
|
49
|
+
# ── 使い捨ての作り物(作業場所の根に秘密の形のファイルを置く=実地と同じ形)──────
|
|
50
|
+
ROOT = tempfile.mkdtemp(prefix='search-word-push-')
|
|
51
|
+
SITE = os.path.join(ROOT, 'site')
|
|
52
|
+
for d in ('src', 'scripts', 'sales-template', 'docs', '.claude'):
|
|
53
|
+
os.makedirs(os.path.join(SITE, d))
|
|
54
|
+
with open(os.path.join(SITE, NPMRC), 'w') as f:
|
|
55
|
+
f.write('DUMMY=placeholder\n')
|
|
56
|
+
with open(os.path.join(SITE, '.claude', 'settings.json'), 'w') as f:
|
|
57
|
+
f.write('{}\n')
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def decide(cmd):
|
|
61
|
+
r = policy.decide_bash(cmd, SITE)
|
|
62
|
+
return r['decision'] + ':' + r['reason'].split(':', 1)[0]
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
ALLOW = 'allow:no gate, no danger'
|
|
66
|
+
|
|
67
|
+
# ── 止められた2件の命令(便 311545fe・40fc68ed の報告の全文のまま・危険語だけ組み立て形)──
|
|
68
|
+
CMD_311545FE = f'git grep -n -e "{GP} * +*" -- src scripts sales-template'
|
|
69
|
+
CMD_40FC68ED = f"git grep -n -e '{GP} \\* +\\*' -- .claude/settings.json"
|
|
70
|
+
|
|
71
|
+
# ═════════════════════════════════════════════════════════════════════════════
|
|
72
|
+
# (a) 通る(探す言葉の中の字)
|
|
73
|
+
# ═════════════════════════════════════════════════════════════════════════════
|
|
74
|
+
print('── (a) 探す言葉の中の push の字は push と読まない ' + '─' * 18)
|
|
75
|
+
PASS = [
|
|
76
|
+
('a01 便 311545fe で止まった命令', CMD_311545FE),
|
|
77
|
+
('a02 便 40fc68ed で止まった命令', CMD_40FC68ED),
|
|
78
|
+
('a03 git grep の探す言葉に --force', f"git grep -n -e '{GP} {FORCE}' -- src docs"),
|
|
79
|
+
('a04 git grep の探す言葉に -f', f"git grep -n -e '{GP} {SHORT} origin' -- src"),
|
|
80
|
+
('a05 git grep の探す言葉に --force-with-lease', f'git grep -n -e "{GP} {LEASE}" -- docs'),
|
|
81
|
+
('a06 git grep の探す言葉に + の参照', f"git grep -n '{GP} origin +main' -- src"),
|
|
82
|
+
('a07 -e を2つ', f"git grep -n -e '{GP} +x' -e '{GP} {FORCE}' -- src docs"),
|
|
83
|
+
('a08 grep -rn(場所を名指し)', f"grep -rn '{GP} {FORCE}' src docs"),
|
|
84
|
+
('a09 grep -n(ファイルを名指し)', f"grep -n '{GP} +x' src/a.ts"),
|
|
85
|
+
('a10 rg(場所を名指し)', f"rg -n '{GP} .*\\+' src"),
|
|
86
|
+
('a11 探したあとに無害な命令', f"git grep -n -e '{GP} +x' -- src && git status"),
|
|
87
|
+
]
|
|
88
|
+
for label, cmd in PASS:
|
|
89
|
+
check(label, decide(cmd), ALLOW)
|
|
90
|
+
|
|
91
|
+
# ═════════════════════════════════════════════════════════════════════════════
|
|
92
|
+
# (b) 止める(本物の push・探す言葉に見せかけた形)
|
|
93
|
+
# ═════════════════════════════════════════════════════════════════════════════
|
|
94
|
+
print('── (b) 本物の強い上書きの push は今までどおり止める ' + '─' * 16)
|
|
95
|
+
DANGER = [
|
|
96
|
+
('b01 + の参照', f'{GP} origin +main'),
|
|
97
|
+
('b02 + の参照(引用符)', f'{GP} origin "+main"'),
|
|
98
|
+
('b03 --force', f'{GP} {FORCE} origin main'),
|
|
99
|
+
('b04 -f', f'{GP} {SHORT} origin main'),
|
|
100
|
+
('b05 --force-with-lease', f'{GP} {LEASE} origin main'),
|
|
101
|
+
('b06 旗を末尾に', f'{GP} origin feat/x {FORCE}'),
|
|
102
|
+
('b07 場所を指す旗つき', f'git -C {SITE} {PUSH} {FORCE} origin feat/x'),
|
|
103
|
+
('b08 探したあとに ; で本物の push', f"git grep -n -e '{GP} +x' -- src; {GP} origin +main"),
|
|
104
|
+
('b09 探したあとに && で本物の push', f"git grep -n -e 'x' -- src && {GP} {FORCE} origin main"),
|
|
105
|
+
('b10 探したあとに | で本物の push', f"grep -rn '{GP} +x' src | {GP} {SHORT} origin main"),
|
|
106
|
+
('b11 探す言葉に見せて後ろで push', f"git grep -n -e '{GP} {LEASE}' -- src; {GP} {LEASE} origin x"),
|
|
107
|
+
('b12 包みの中', f'bash -c "{GP} {FORCE} origin main"'),
|
|
108
|
+
('b13 包みの中の探す命令', f"bash -c \"git grep -n -e '{GP} +x' -- src\""),
|
|
109
|
+
('b14 探す言葉の中の置き換えの実行', f'git grep -n -e "$({GP} {FORCE} origin main)" -- src'),
|
|
110
|
+
('b15 探す言葉の中の逆引用符', f'git grep -n -e "`{GP} origin +main`" -- src'),
|
|
111
|
+
('b16 git grep -O(別の命令を走らせる旗)', f"git grep -O'{GP} {FORCE} origin main' -e x -- src"),
|
|
112
|
+
('b17 git grep --open-files-in-pager', f"git grep --open-files-in-pager='{GP} +main' -e x -- src"),
|
|
113
|
+
('b18 rg --pre(別の命令を走らせる旗)', f"rg --pre '{GP} {FORCE}' x src"),
|
|
114
|
+
('b19 探す言葉の外の push の字', f"git grep -n -e 'x' -- src {GP} {FORCE}"),
|
|
115
|
+
('b20 ヒアドキュメントの本文', f"cat <<'EOF'\n{GP} {FORCE} origin main\nEOF"),
|
|
116
|
+
('b21 echo の文字(探す道具でない)', f"echo '{GP} {FORCE} origin main'"),
|
|
117
|
+
]
|
|
118
|
+
for label, cmd in DANGER:
|
|
119
|
+
check(label, decide(cmd).startswith('deny:danger'), True)
|
|
120
|
+
|
|
121
|
+
# ═════════════════════════════════════════════════════════════════════════════
|
|
122
|
+
# (c) rm のときの直し(便 915694ac)も今までどおり
|
|
123
|
+
# ═════════════════════════════════════════════════════════════════════════════
|
|
124
|
+
print('── (c) rm の直しも今までどおり ' + '─' * 36)
|
|
125
|
+
check('c01 探す言葉の中の rm は通る',
|
|
126
|
+
policy.decide_bash(f"git grep -n '{RM} -rf .git' -- skills docs")['decision'], policy.ALLOW)
|
|
127
|
+
check('c02 探したあとに本物の rm は止まる',
|
|
128
|
+
policy.decide_bash(f"grep -rn '{RM} -rf .git' docs; {RM} -rf .git")['decision'], policy.DENY)
|
|
129
|
+
check('c03 字面の判定は command を渡さなければ今までどおり当たる',
|
|
130
|
+
policy._danger_patterns(CMD_311545FE.lower()), 'force push')
|
|
131
|
+
|
|
132
|
+
# ═════════════════════════════════════════════════════════════════════════════
|
|
133
|
+
# (d) 空振り確認(試験の中で免じる所を外す)
|
|
134
|
+
# ═════════════════════════════════════════════════════════════════════════════
|
|
135
|
+
print('── (d) 空振り確認 ' + '─' * 48)
|
|
136
|
+
_real = policy._push_only_in_search_words
|
|
137
|
+
policy._push_only_in_search_words = lambda command: False # 免じる所を外す
|
|
138
|
+
check('d1 外すと便 311545fe の命令が止まる', decide(CMD_311545FE), 'deny:danger')
|
|
139
|
+
check('d2 外すと便 40fc68ed の命令が止まる', decide(CMD_40FC68ED), 'deny:danger')
|
|
140
|
+
policy._push_only_in_search_words = _real
|
|
141
|
+
check('d3 戻すと通る', decide(CMD_311545FE), ALLOW)
|
|
142
|
+
|
|
143
|
+
shutil.rmtree(ROOT, ignore_errors=True)
|
|
144
|
+
check('z1 作り物を片付けた', os.path.exists(ROOT), False)
|
|
145
|
+
|
|
146
|
+
print()
|
|
147
|
+
if failures:
|
|
148
|
+
print(f'NG {len(failures)} 件')
|
|
149
|
+
for f in failures:
|
|
150
|
+
print(f' - {f}')
|
|
151
|
+
sys.exit(1)
|
|
152
|
+
print('すべて期待どおり')
|
|
@@ -296,6 +296,7 @@ description: 采配くんの便(プロンプト末尾に CONDUCTOR_JOB:<id>
|
|
|
296
296
|
- **行き先のブランチを確かめられない `git push`**(作業場所が変数のままの `git -C "$DIR" push`・`git push` とだけ打つ形・保護ブランチを狙う形)→ 止まる。**リポの中で、ブランチを名指しして** `git push origin <作業ブランチ名>`(★`-u` は付けない=鉄則7-⓪。上流の設定を書くと、囲いが `.git/config` を塞いでいるPCで止まる)。
|
|
297
297
|
- ★**止まるのは「行き先が分からない形」と「保護ブランチを狙う形」**(実測 便 6e8d85e6)。場所を指す旗を付けても枝を名指しした形(`git -C <場所> push origin <作業ブランチ名>`)は止まらないので、「場所を指す旗が付いているか」で安全を判断しない。
|
|
298
298
|
- ★**強い上書き(`--force`/`-f`/`--force-with-lease`/先頭が `+` の参照指定)は、旗の位置を問わず止まる。** 旗を末尾や中間に置く形・短い旗をまとめた形(`-fu`)・`git` と `push` の間に場所や設定を指す旗を挟む形・`+` を引用符で囲う形・つないだ行や包みの中に書いた形も、すべて止まる(便 e619bd86 で語の並びを見る判定に替えた。それまでは挟む形と引用符で囲う形が素通りしていた=実地 便 6e8d85e6)。**そもそも強い上書きは打たない**(便の本文の「force-push と reset はしない」)。
|
|
299
|
+
- ★**探すだけの道具の「探す言葉」に強い上書きの push の字を書いても、もう止まらない**(便 b6410117 で直した・rm のとき=便 915694ac と同じ直し)。禁止の一覧の行を調べる `git grep -n -e '<push の字と + の参照>' -- .claude/settings.json` は通る。★囲みの外に書いた push は今までどおり測るので、探した後ろにつないだ本物の push・包みの中・探す言葉の中の `$(…)`・別の命令を走らせる旗(`git grep -O`・`rg --pre` など)は止まる。
|
|
299
300
|
|
|
300
301
|
## 途中で止まらない書き方(全便の共通の型)
|
|
301
302
|
|