This repository was archived by the owner on Nov 4, 2026. It is now read-only.
Repository navigation
Commit 1aa8851
fix(hooks): port subst_end() into guard-main-checkout-bash (objectstack 7e40e8a03 and 338297e46) (#13320)
Fixes #13260.
## What this ports
A file port of two objectstack commits into the objectui copies of the
Bash-guard hook family, as the card's memo 6308641120 amends its
Done-when. Six files under `.claude/hooks/`:
- `guard-main-checkout-bash.sh` and its self-test: objectstack
`7e40e8a03` (PR 24886, the shared `subst_end()` for a `$(…)` or backtick
inside a double-quoted word, called from `strip_line_comment`,
`split_segments` and `tokenize`) and `338297e46` (PR 25025, a `${…}` arm
and the rule for a `'` run inside a quoted `${…}`).
- `guard-shared-stash.sh` and its self-test: `338297e46` only. It
carries a byte-identical `subst_end()` and delegates to it from
`split_segments()`; the self-test pins that copy against the canonical.
- `guard-tree-enum.sh` and its self-test: `338297e46` only. Same copy
and delegation, plus the in-quote backslash branch (an escaped quote
inside a double-quoted word leaves the region open) that its two
siblings already had and this copy lacked. Its self-test pins
`subst_end()` against the canonical and `split_segments()` against the
stash guard's.
- `guard-process-kill.sh` of `338297e46` has no twin in this repo and is
not ported.
Applied as the exact objectstack diff of each file, then localised by
hand where a hunk's context differed: foreign issue references carry the
`objectstack#` prefix, the provenance stamp on line 2 of all six files
names `338297e46018ae96256262590a308c8be735f825`, and the stash guard's
header case count was re-derived (62 = 57 `expect ` lines + 2 inline
specials + 2 hatch-message assertions + 1 identity pin; the self-test
run prints the same total). One cleanup beyond the diff: the stash
guard's `split_segments()` carried five extra comment lines inside the
function body that objectstack's copy does not, which made the new
byte-identity pin between the stash and tree-enum copies fail, so they
are removed to match objectstack's function text.
The `subst_end()` block is byte-identical across all three hooks and
equal to objectstack's copies (the same md5 for the function text,
measured on all three here and on objectstack's four). The comment above
it in `guard-main-checkout-bash.sh` names the two hooks here that carry
the copy and says `guard-process-kill.sh` carries one in objectstack
only.
Not copied: any of PR 25025's description. The card's memo says one
sentence of it, about `echo "${x:-'}'}" ; sed -i s/a/b/ pkg/x.ts`, is
wrong about what the pre-fix hook did. This PR copies code, headers and
pins only; the declared fail-open for that shape is pinned as
objectstack pins it.
## Measured
- Premise at `cd14d8e`: `subst_end` occurs 0 times in all three hooks
and their self-tests; in objectstack `origin/main` (`2069b81c2`) it
occurs 7 times in the main-checkout hook and 3 times each in the stash
and tree-enum hooks.
- Self-tests on head `8a0c369`, via `os-verify-lock.sh`: main-checkout
`157 passed, 0 failed`; shared-stash `62 passed, 0 failed`; tree-enum
`50 passed, 0 failed`; all exit 0, identity pins included. Before: 130,
50 and 38 cases, all passing.
- Reverse validation, run after the commits, with the base-blob hook and
the ported self-test copied to a scratch dir (tree not mutated):
main-checkout `143 passed, 14 failed`; shared-stash `56 passed, 6
failed` (three false blocks, two fail-open reads, the identity pin);
tree-enum `43 passed, 7 failed` (three false blocks, one fail-open read,
both identity pins, plus the escaped-quote false block). All red, as
predicted.
- The four commands measured on the first head now answer as
objectstack's copies do (same cwd, exit codes): `echo "say \"; ls *.yml;
git show origin/main:x\" ok"` through the tree-enum guard 0 (was 2);
`echo "he said \"x\"" ; for f in *.yml; do git show "origin/main:$f";
done` 2 (was 0); `echo "$(printf '"')" ; git stash pop` through the
stash guard 2 (was 0); `echo "$(printf '"')" ; for f in *.yml; do git
show "origin/main:$f"; done` through the tree-enum guard 2 (was 0). The
card's two curl forms exit 0 and `echo hi > out.txt` exits 2 through the
main-checkout guard.
- Every pre-existing real-write, real-stash and tree-sweep case still
passes unchanged.
## Remaining differences from objectstack (none is hook logic)
Compared against objectstack `338297e46` with comment lines removed: the
main-checkout hook differs only in the worktree-recipe help text's issue
reference and the selftest's example strings. The tree-enum hook differs
in one help-text word and example strings. The stash guard differs more,
in text that comes from other objectstack changes, not these two
commits: its printed help message (a shorter list of alternatives) and a
handful of self-test cases (objectstack has extra `echo \" ; git stash
...` cases that this repo's matrix words differently). Left as they are;
the escaped-quote logic itself is present and pinned here. Also
comment-only: stamps, header wording, the arrow-versus-banner glyph
prose, and one objectstack-only comment block above the main-checkout
hook's printed worktree recipe (the recipe command is already the same
here).
## Gates
Derived by hand from this repo's `package.json` and workflows
(objectstack's `dispatch-gates.mjs` refuses to derive this repo's
families). Local, exit codes captured before any pipe, on head
`8a0c369`: the three hook self-tests 0; `check-bash32-floor --self-test`
0 and the scan 0; `check-control-bytes` 0; `check:new-line-citations` 0
(0 new citations); `check-shell-escape-residue` 0;
`check-changeset-presence` 0 (no changeset owed, the files are not
package source); control-byte grep of the hooks clean.
`check-governed-queue-guard --test` on the six files answers 3
(governed), as expected. CI check-runs read on `8a0c369`: Hook
Self-Tests, Governed Surface Queue Guard, Lint, Type Check, Repo Gates,
Build & E2E, Build Docs, Test (dist pins), Line Citation Gate and the
three Changeset checks success; Test shards 1-16 were still in progress
when read.
## Governed surface
The diff is under `.claude/**`. The PR stays draft until an authorised
approver's APPROVED review exists; landing is the claiming seat's after
that.
## 维护者速读(草稿)
**改了什么**:把 objectstack 仓里对三个 Bash 守卫钩子的两次修复搬进本仓:拦住 agent 在共享主检出里用 shell
写文件的钩子(`guard-main-checkout-bash.sh`)、拦住共享 stash
栈操作的钩子(`guard-shared-stash.sh`)、拦住"用工作区通配符去枚举
origin/main"的钩子(`guard-tree-enum.sh`),连同各自的自测,共六个文件。三个钩子共用的"引号里的
`$(…)`、反引号、`${…}`
该怎么切分"的那段函数现在逐字节一致,自测里有一条专门比对,谁改漂了就红。`guard-tree-enum.sh`
还补上了它缺的一个分支:引号里的转义引号。
**为什么改**:这三个钩子原先把引号里命令替换里的引号误读为外层字符串的结束,于是出现两类问题。误拦:只读命令被当成写入、stash
或树枚举而被拦,agent 被拦几次就会用 `OS_ALLOW_MAIN_EDITS=1`、`OS_ALLOW_STASH=1`
这类开关把整个守卫关掉。漏拦:同样的误读让真正的写入、stash、树枚举从缝里过去(实测:本仓的 stash 钩子对 `echo
"$(printf '"')" ; git stash pop` 放行,objectstack
拦截)。两仓钩子本应逐例一致,objectstack 修了之后本仓落后了。
**风险与代价(含回滚)**:纯 shell 解析逻辑。三个自测由 130、50、38 条增至 157、62、50
条且全绿,新增用例在旧钩子上确实变红(逐钩子实测),原有的"必须拦住"用例没有变化,bash 3.2 下限门禁通过。已知并被
objectstack 明确接受的代价:引号内 `${…}`
里出现某些单引号写法时,钩子宁可放行(失败时开放),自测里有明文用例钉住。回滚就是整个 PR 一次
revert,钩子回到现状,不影响任何别的东西。
**席位意见**:(留空,由席位定稿)
**你要做的**:这是受管面(`.claude/**`),需要获授权的批准者给一条 APPROVED 的 review,席位才能转 ready
入队。没有别的待办;`guard-process-kill.sh` 本仓没有对应的钩子,不在范围内。
---
_Generated by [Claude
Code](https://claude.ai/code/session_019Bd3muSBdHUFdJiKqnsM2W)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 4c212b9 commit 1aa8851
6 files changed
Lines changed: 361 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
307 | 353 | | |
308 | 354 | | |
309 | 355 | | |
310 | 356 | | |
311 | 357 | | |
312 | 358 | | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
313 | 367 | | |
314 | 368 | | |
315 | 369 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
40 | 44 | | |
41 | 45 | | |
42 | 46 | | |
| |||
45 | 49 | | |
46 | 50 | | |
47 | 51 | | |
| 52 | + | |
| 53 | + | |
48 | 54 | | |
49 | 55 | | |
50 | 56 | | |
| |||
114 | 120 | | |
115 | 121 | | |
116 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
117 | 198 | | |
118 | 199 | | |
119 | 200 | | |
| |||
144 | 225 | | |
145 | 226 | | |
146 | 227 | | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
147 | 231 | | |
148 | 232 | | |
149 | 233 | | |
| |||
213 | 297 | | |
214 | 298 | | |
215 | 299 | | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
216 | 303 | | |
217 | 304 | | |
218 | 305 | | |
| |||
271 | 358 | | |
272 | 359 | | |
273 | 360 | | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
274 | 364 | | |
275 | 365 | | |
276 | 366 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
151 | 188 | | |
152 | 189 | | |
153 | 190 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| |||
98 | 99 | | |
99 | 100 | | |
100 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
101 | 159 | | |
102 | 160 | | |
103 | 161 | | |
| |||
110 | 168 | | |
111 | 169 | | |
112 | 170 | | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
113 | 174 | | |
114 | 175 | | |
115 | 176 | | |
116 | 177 | | |
117 | 178 | | |
118 | 179 | | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | 180 | | |
125 | 181 | | |
126 | 182 | | |
| |||
0 commit comments