@dsh-cc/plugin-cc-grok-bridge 0.8.1

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,5 @@
1
+ {
2
+ "name": "cc-grok-bridge",
3
+ "description": "Official dsh-cc plugin: an approval-free Grok review lane — one canonical, locked-down bash invocation auto-allowed via a PreToolUse hook, with Grok's tool approvals bypassed inside the run while the dsh outer sandbox remains the single write boundary.",
4
+ "version": "0.8.1"
5
+ }
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,6 @@
1
+ # Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
2
+ # side as of the last confirmed-consistent state. Both languages carry equal authority;
3
+ # after editing either side, bring the other along and re-record with:
4
+ # pnpm check:readme --write
5
+ README.md: 4549ad4310a124935f935c90df6de3be6aa99a66
6
+ README.zh.md: d2178a9525fd8fbbf64aa500fc9d683a7cdcc11b
package/README.md ADDED
@@ -0,0 +1,120 @@
1
+ # cc-grok-bridge
2
+
3
+ Official dsh-cc plugin: an **approval-free Grok review lane**. Installing it lets a
4
+ dsh-cc session run exactly one canonical, locked-down Grok review invocation —
5
+ `node <launcher> [--last] <prompt>` — with no human permission checkpoint, by
6
+ auto-allowing that single command form through a PreToolUse hook.
7
+
8
+ The core trade is **state relocation, not sandbox widening**: Grok's tool
9
+ approvals are bypassed inside the run (`--permission-mode bypassPermissions`),
10
+ while the dsh outer sandbox remains the single write boundary — workspace plus
11
+ temp areas only.
12
+
13
+ ## How it works
14
+
15
+ - One canonical invocation form, pinned byte-for-byte: the interpreter and launcher
16
+ paths must be expansion-free literal tokens equal to the plugin's canonical
17
+ anchors — no PATH lookup, no symlink trampoline, no `~`/glob/`$VAR` expansion,
18
+ no compound commands, no command substitution outside single quotes.
19
+ - A PreToolUse hook downgrades the permission verdict for exactly that form; every
20
+ other shape fails closed into the unchanged, approval-requiring flow.
21
+ - Grok's session state lives in a `0700` temp-dir shadow home (`GROK_HOME`),
22
+ swept to a strict allowlist before each run and seeded with `auth.json`;
23
+ the grok CLI itself resolves to a validated absolute path at spawn.
24
+ - Inline prompts must be single-line and must not start with `-`; multi-line or
25
+ dash-leading prompts go through `--prompt-file`.
26
+
27
+ ## Usage
28
+
29
+ 1. **Status at session start.** A SessionStart hook fires on every session
30
+ (startup and resume alike) and injects a `cc-grok-bridge:` block stating
31
+ whether the lane is **ARMED** — including the exact canonical invocation to
32
+ type — or **NOT armed** with the machine reason in plain words.
33
+ 2. **Invoke the review** with the plugin command:
34
+
35
+ ```sh
36
+ /cc-grok-bridge:review review the failing spec
37
+ ```
38
+
39
+ 3. **Multi-line (or dash-leading) prompts** go through `--prompt-file`: write the
40
+ prompt text to a file inside the workspace (or the canonical tmpdir) and use
41
+ the `--prompt-file <path>` form from the SessionStart block.
42
+ 4. **`--last` only on explicit continue**: the resume flag is used only when
43
+ the user explicitly asks to continue the previous review (it resumes the most
44
+ recent review thread for the current workspace).
45
+ 5. **Fail closed.** If the SessionStart block is absent or reports NOT armed,
46
+ the model must not guess or construct the canonical invocation — the review
47
+ falls back to the normal, approval-requiring path.
48
+
49
+ ## Authentication
50
+
51
+ - `grok login --device-code` writes `~/.grok/auth.json`; the bridge seeds that
52
+ file into the shadow home per run (never the reverse — nothing is written
53
+ back to `~/.grok`).
54
+ - Alternatively an ambient `XAI_API_KEY` passes through to the child; when it
55
+ is set, a missing `auth.json` source no longer warns.
56
+
57
+ ## Shadow-home semantics
58
+
59
+ The shadow home is per-workspace (keyed on the canonicalized cwd) under the
60
+ canonical tmpdir, mode `0700`, single-flight locked. Before every run the home
61
+ is **swept to an allowlist** — exactly `auth.json`, `sessions/`, and the lock —
62
+ so config, caches, and auto-loaded surfaces from the interactive Grok state
63
+ cannot persist into the lane (cross-run injection control); the credential is
64
+ then re-synced with `O_NOFOLLOW` + atomic-rename semantics. A missing/unreadable
65
+ source deletes the shadow copy (a revoked token must not live on). A previous
66
+ run that outlived its reap budget leaves an `H/.orphaned` poison marker that
67
+ blocks further launches until a human removes it.
68
+
69
+ ## Dev-session degradation
70
+
71
+ In dsh-cc's own repo dev sessions the launcher anchor sits inside the session
72
+ workspace, so arming is refused (`anchor-under-writable-root`) and the lane
73
+ degrades to the normal approval path. Expected and documented. A non-empty
74
+ ambient `BASH_ENV` or `ENV` also disarms the lane (shell-function takeover
75
+ defense) — and note the residual: plugin hooks themselves run through the host
76
+ shell, so an ambient startup-interception vector could in principle forge this
77
+ plugin's own hook verdicts; the lane carries that exposure as accepted-with-
78
+ documentation (no in-plugin closure exists).
79
+
80
+ ## Security model (capability tunnel, stated plainly)
81
+
82
+ Enabling the bridge means explicitly dropping the human checkpoint for this one
83
+ command form. Unattended Grok may run any subprocess the outer sandbox permits —
84
+ including actions the permission classifier would otherwise escalate (git push,
85
+ ssh, cloud CLIs) and unlimited networking. **Only the filesystem write boundary
86
+ holds** (workspace + temp areas); nothing else is claimed. The bridge is opt-in
87
+ by installation; **uninstalling or disabling the plugin is the kill switch**.
88
+
89
+ **Credential exposure, stated plainly:** any run executes as the user with
90
+ networking; a hostile prompt (or hostile repo content under review) can read the
91
+ shadowed `auth.json` (or an ambient `XAI_API_KEY`) and exfiltrate it. Upstream
92
+ token lifetime bounds the shadow's value; the sync never writes back.
93
+
94
+ ## Cost honesty
95
+
96
+ The lane is **unbounded by design**: there is no turn cap. The durable cost
97
+ record is the per-run stderr line `grok-review: session=… cost_usd=… turns=…`
98
+ emitted by the launcher on success (`grok usage <sessionId>` is not usable
99
+ post-hoc, so there is no other record). Keep an eye on the line per run.
100
+
101
+ ## Verified version
102
+
103
+ Probed end-to-end against **grok 1.0.41**. Newer grok releases may drift
104
+ silently (no version gate by design); the standing re-probe recipe lives in the
105
+ design doc (`docs/plans/2026-09-27-grok-review-bridge.md` §2) and should be
106
+ re-run on grok updates.
107
+
108
+ ## Install / uninstall
109
+
110
+ Install from the dsh-cc marketplace, plugin name `cc-grok-bridge`:
111
+
112
+ ```sh
113
+ claude plugin install cc-grok-bridge@dsh-cc
114
+ ```
115
+
116
+ Uninstalling (or disabling) the plugin removes the lane entirely:
117
+
118
+ ```sh
119
+ claude plugin uninstall cc-grok-bridge@dsh-cc
120
+ ```
package/README.zh.md ADDED
@@ -0,0 +1,97 @@
1
+ # cc-grok-bridge
2
+
3
+ dsh-cc 官方插件:一条**免审批的 Grok 评审通道**。安装后,dsh-cc 会话可以运行唯一一种
4
+ 规范、锁死的 Grok 评审调用 —— `node <launcher> [--last] <prompt>` —— 无需人工审批:
5
+ PreToolUse 钩子只对这一种命令形态自动放行。
6
+
7
+ 核心思路是**状态搬迁,而非放宽沙箱**:运行内绕过 Grok 自身的工具审批
8
+ (`--permission-mode bypassPermissions`),同时 dsh 外层沙箱仍是唯一的写入边界 ——
9
+ 仅限工作区与临时目录。
10
+
11
+ ## 工作原理
12
+
13
+ - 唯一的规范调用形态,逐字节锁定:解释器与启动器路径必须是不含展开的字面量,与插件的
14
+ 规范锚点逐字节相等 —— 不走 PATH 查找、不允许符号链接跳板、禁止 `~`/glob/`$VAR` 展开、
15
+ 禁止复合命令、单引号之外禁止命令替换。
16
+ - PreToolUse 钩子只对这一形态降级权限判定;其他一切形态一律失败关闭(fail-closed),
17
+ 回落到原有需审批的流程。
18
+ - Grok 的会话状态位于临时目录中权限为 `0700` 的专属影子 home(`GROK_HOME`),每次运行前
19
+ 按允许清单清扫并以 `auth.json` 播种;grok CLI 本身在启动时解析为经过校验的绝对路径。
20
+ - 内联提示词必须单行且不得以 `-` 开头;多行或短横线开头的提示词走 `--prompt-file`。
21
+
22
+ ## 使用方法
23
+
24
+ 1. **会话开始时的状态块。** SessionStart 钩子在每次会话启动时触发(startup 与 resume
25
+ 均包括),注入一个以 `cc-grok-bridge:` 开头的块:说明通道是否 **已启用(ARMED)** ——
26
+ 并给出可照抄的规范调用 —— 或 **未启用(NOT armed)** 及其白话原因。
27
+ 2. **发起评审**,使用插件命令:
28
+
29
+ ```sh
30
+ /cc-grok-bridge:review review the failing spec
31
+ ```
32
+
33
+ 3. **多行(或短横线开头)的提示词** 走 `--prompt-file`:先用文件工具把提示词写入工作区内
34
+ (或规范临时目录)的文件,再使用 SessionStart 块中的 `--prompt-file <path>` 形态。
35
+ 4. **`--last` 仅在明确要求续聊时使用**:只有当用户明确要求继续上一次评审时才加该标志
36
+ (它恢复当前工作区最近一次评审线程)。
37
+ 5. **失败即关闭。** 若 SessionStart 块缺失或显示未启用,模型不得猜测或自行拼造规范调用
38
+ —— 评审回落到正常的需审批路径。
39
+
40
+ ## 认证
41
+
42
+ - `grok login --device-code` 写入 `~/.grok/auth.json`;桥接每次运行把该文件播种进影子
43
+ home(绝不反向 —— 不会写回 `~/.grok`)。
44
+ - 或者,环境变量 `XAI_API_KEY` 会透传给子进程;设置它之后,`auth.json` 源缺失不再警告。
45
+
46
+ ## 影子 home 语义
47
+
48
+ 影子 home 按工作区(以规范化 cwd 为键)位于规范临时目录下,权限 `0700`,单飞锁。每次
49
+ 运行前,home 会被**按允许清单清扫** —— 恰好保留 `auth.json`、`sessions/` 与锁 —— 交互式
50
+ Grok 状态中的配置、缓存与自动加载面不会带入通道(跨运行注入控制);随后以 `O_NOFOLLOW`
51
+ + 原子重命名语义重新同步凭据。源缺失/不可读时删除影子副本(被吊销的令牌不得存留)。
52
+ 超出收割预算残留的上一轮运行会留下 `H/.orphaned` 毒标记,阻止后续启动,直到人工移除。
53
+
54
+ ## 开发会话降级
55
+
56
+ 在 dsh-cc 自身的仓库开发会话中,启动器锚点位于会话工作区内,启用会被拒绝
57
+ (`anchor-under-writable-root`),通道降级为正常审批路径。预期行为,已有文档。环境变量
58
+ `BASH_ENV` 或 `ENV` 非空时通道同样失效(防御 shell 函数劫持)—— 并请留意残留风险:插件
59
+ 钩子本身经宿主 shell 运行,环境级启动拦截向量原则上可伪造本插件自身的钩子判定;该暴露
60
+ 作为“接受并记录在案”处理(插件内无解)。
61
+
62
+ ## 安全模型(能力隧道,直言不讳)
63
+
64
+ 启用本桥接意味着明确放弃这一种命令形态的人工检查点。无人值守的 Grok 可以运行外层
65
+ 沙箱允许的任何子进程 —— 包括权限分类器本会升级处理的操作(git push、ssh、云 CLI)以及
66
+ 不受限的网络访问。**只有文件系统写入边界仍然成立**(工作区 + 临时目录),除此之外不作
67
+ 任何承诺。本插件通过安装进行选择加入;**卸载或禁用插件即是一键关闭**。
68
+
69
+ **凭据暴露,直言不讳:** 任何一次运行都以用户身份并带网络执行;恶意提示词(或被评审的
70
+ 恶意仓库内容)可以读取影子 `auth.json`(或环境变量 `XAI_API_KEY`)并将其外传。上游令牌
71
+ 的生命周期限制了影子的价值;同步绝不写回。
72
+
73
+ ## 成本诚实
74
+
75
+ 该通道**按设计不设上限**:没有回合上限。持久成本记录是每次运行成功时启动器输出的
76
+ stderr 行 `grok-review: session=… cost_usd=… turns=…`(`grok usage <sessionId>` 事后
77
+ 不可用,此外没有别的记录)。请逐次留意该行。
78
+
79
+ ## 已验证版本
80
+
81
+ 已针对 **grok 1.0.41** 端到端探明。更新的 grok 版本可能静默漂移(按设计不设版本闸门);
82
+ 现行复探配方见设计文档(`docs/plans/2026-09-27-grok-review-bridge.md` §2),grok 更新后
83
+ 应重新执行。
84
+
85
+ ## 安装 / 卸载
86
+
87
+ 从 dsh-cc marketplace 安装,插件名 `cc-grok-bridge`:
88
+
89
+ ```sh
90
+ claude plugin install cc-grok-bridge@dsh-cc
91
+ ```
92
+
93
+ 卸载(或禁用)插件即彻底移除该通道:
94
+
95
+ ```sh
96
+ claude plugin uninstall cc-grok-bridge@dsh-cc
97
+ ```
@@ -0,0 +1,25 @@
1
+ ---
2
+ description: Run a Grok review through the cc-grok-bridge lane
3
+ argument-hint: "[review request]"
4
+ ---
5
+
6
+ You are dispatching a Grok review for this request from the user:
7
+
8
+ $ARGUMENTS
9
+
10
+ The **cc-grok-bridge** plugin's SessionStart hook injected a block at session
11
+ start beginning with `cc-grok-bridge:` that states whether the review lane is
12
+ ARMED and, if so, gives THE exact canonical invocation to type.
13
+
14
+ Rules — follow them exactly:
15
+
16
+ 1. **Use the SessionStart-provided canonical block.** If it reports ARMED, run
17
+ the canonical invocation exactly as given there, passing this request as the
18
+ prompt. If the request text is multi-line (or its first character is `-`,
19
+ which the launcher rejects for inline prompts), write the text to a file
20
+ inside the current workspace (or the canonical tmpdir) with your file-write
21
+ tool, then use the `--prompt-file <path>` form from the block. Never edit,
22
+ abbreviate, or re-derive the anchor paths.
23
+ 2. **`--last` ONLY when the user explicitly asked to continue the previous
24
+ review** (e.g. "continue the last review"). Otherwise omit it.
25
+ 3. **Fail closed when the block is absent or reports NOT armed.** If the SessionStart block is missing or reports NOT armed, STOP: do not guess or construct any invocation; tell the user the Grok review lane is not armed in this session.
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * grok-review-allow.mjs — the §3.2 pre-execute allow listener as a plugin
4
+ * PreToolUse command hook.
5
+ *
6
+ * Contract: on a byte-exact canonical review invocation emit exactly one
7
+ * `hookSpecificOutput` allow verdict (the codec drops a top-level
8
+ * `decision: "allow"` — only `permissionDecision` reaches the waterfall);
9
+ * on EVERYTHING else — parse failure, non-Bash tool, non-match, disarmed
10
+ * state, refusal, containment violation — emit NOTHING and exit 0, so the
11
+ * command falls through to the unchanged existing permission flow. This
12
+ * hook never denies (fail-closed-into-silence; the SessionStart
13
+ * hook surfaces armed/refused state).
14
+ *
15
+ * Canonical anchors are derived per-match inside THIS process via the
16
+ * shared canonical.mjs module: a command hook runs through a PATH-resolved
17
+ * interpreter, so the byte-pinned pair is the realpath of this process's
18
+ * own interpreter executable and the realpath of the plugin's own launcher
19
+ * script (see canonical.mjs for the derivation). Both must sit outside the
20
+ * writable-root refusal set, ambient BASH_ENV/ENV must be empty, and the
21
+ * platform must not be win32, or the bridge is disarmed for this call.
22
+ */
23
+ import { tmpdir } from 'node:os'
24
+ import { isAbsolute, join } from 'node:path'
25
+ import { arming, inside, safeReal } from '../scripts/lib/canonical.mjs'
26
+ import { matchInvocation } from '../scripts/lib/argv.mjs'
27
+
28
+ const REASON = 'cc-grok-bridge: canonical review invocation (byte-pinned anchors, expansion-free)'
29
+
30
+ /** Silent pass: no stdout at all, exit 0 — the unchanged existing flow decides. */
31
+ const silent = () => process.exit(0)
32
+
33
+ let input = ''
34
+ process.stdin.setEncoding('utf8')
35
+ for await (const chunk of process.stdin) input += chunk
36
+
37
+ let payload
38
+ try {
39
+ payload = JSON.parse(input)
40
+ } catch {
41
+ silent()
42
+ }
43
+ if (payload?.tool_name !== 'Bash') silent()
44
+ const command = payload?.tool_input?.command
45
+ if (typeof command !== 'string' || command === '') silent()
46
+
47
+ try {
48
+ const arm = arming(typeof payload.cwd === 'string' ? payload.cwd : process.cwd(), { hookUrl: import.meta.url })
49
+ if (!arm.armed) silent()
50
+ const { node: NODE, launcher: LAUNCHER, cwd } = arm
51
+
52
+ const match = matchInvocation(command, { node: NODE, launcher: LAUNCHER })
53
+ if (!match.ok) silent()
54
+
55
+ if (match.value.prompt.kind === 'prompt-file') {
56
+ const raw = match.value.prompt.path
57
+ const abs = isAbsolute(raw) ? raw : join(cwd ?? payload.cwd, raw)
58
+ // Matcher-side containment: realpath must land inside the session
59
+ // workspace or the canonical tmpdir (a symlink escaping via realpath is
60
+ // refused here; the launcher re-checks on the fd it opens).
61
+ if (!inside(safeReal(abs), [cwd, safeReal(tmpdir())].filter((p) => p !== null))) silent()
62
+ }
63
+
64
+ process.stdout.write(
65
+ JSON.stringify({
66
+ hookSpecificOutput: {
67
+ hookEventName: 'PreToolUse',
68
+ permissionDecision: 'allow',
69
+ permissionDecisionReason: REASON,
70
+ },
71
+ }) + '\n',
72
+ )
73
+ } catch {
74
+ silent()
75
+ }
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * grok-review-context.mjs — the SessionStart context hook.
4
+ *
5
+ * Contract: read the stdin JSON payload; on ANY failure (parse error, bad
6
+ * shape, derivation throw) stay silent and exit 0. On success emit exactly
7
+ * one line `{"hookSpecificOutput":{"hookEventName":"SessionStart",
8
+ * "additionalContext": <text>}}` where the text is the armed block (the
9
+ * exact canonical invocation to type) or the refused block (machine reason
10
+ * in plain words). Arming comes from the shared canonical.mjs — the same
11
+ * derivation the PreToolUse allow hook applies per call.
12
+ */
13
+ import { armedText, arming, refusedText } from '../scripts/lib/canonical.mjs'
14
+
15
+ let input = ''
16
+ process.stdin.setEncoding('utf8')
17
+ for await (const chunk of process.stdin) input += chunk
18
+
19
+ let payload
20
+ try {
21
+ payload = JSON.parse(input)
22
+ } catch {
23
+ process.exit(0)
24
+ }
25
+ const cwd = typeof payload?.cwd === 'string' && payload.cwd !== '' ? payload.cwd : process.cwd()
26
+
27
+ let text
28
+ try {
29
+ const arm = arming(cwd, { hookUrl: import.meta.url })
30
+ text = arm.armed ? armedText(arm) : refusedText(arm.reason)
31
+ } catch {
32
+ process.exit(0)
33
+ }
34
+
35
+ process.stdout.write(
36
+ JSON.stringify({ hookSpecificOutput: { hookEventName: 'SessionStart', additionalContext: text } }) + '\n',
37
+ )
38
+ process.exit(0)
@@ -0,0 +1,27 @@
1
+ {
2
+ "hooks": {
3
+ "PreToolUse": [
4
+ {
5
+ "matcher": "Bash",
6
+ "hooks": [
7
+ {
8
+ "type": "command",
9
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/grok-review-allow.mjs\"",
10
+ "timeout": 5
11
+ }
12
+ ]
13
+ }
14
+ ],
15
+ "SessionStart": [
16
+ {
17
+ "hooks": [
18
+ {
19
+ "type": "command",
20
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/grok-review-context.mjs\"",
21
+ "timeout": 5
22
+ }
23
+ ]
24
+ }
25
+ ]
26
+ }
27
+ }
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@dsh-cc/plugin-cc-grok-bridge",
3
+ "version": "0.8.1",
4
+ "description": "Official dsh-cc plugin: an approval-free Grok review lane — one canonical, locked-down bash invocation auto-allowed via a PreToolUse hook, with Grok's tool approvals bypassed inside the run while the dsh outer sandbox remains the single write boundary.",
5
+ "type": "module",
6
+ "license": "Apache-2.0",
7
+ "files": [
8
+ ".claude-plugin/plugin.json",
9
+ "commands",
10
+ "hooks",
11
+ "scripts",
12
+ "README.md"
13
+ ],
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/dsh-cc/dsh-cc.git",
20
+ "directory": "packages/plugin/cc-grok-bridge"
21
+ }
22
+ }