@dsh-cc/plugin-cc-codex-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.
- package/.claude-plugin/plugin.json +5 -0
- package/LICENSE +201 -0
- package/README.i18n.yaml +6 -0
- package/README.md +91 -0
- package/README.zh.md +76 -0
- package/commands/rescue.md +30 -0
- package/hooks/codex-rescue-allow.mjs +76 -0
- package/hooks/codex-rescue-context.mjs +38 -0
- package/hooks/hooks.json +27 -0
- package/package.json +22 -0
- package/scripts/codex-rescue-run.mjs +182 -0
- package/scripts/lib/argv.mjs +368 -0
- package/scripts/lib/canonical.mjs +99 -0
- package/scripts/lib/home.mjs +179 -0
- package/scripts/lib/lexer.mjs +145 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cc-codex-bridge",
|
|
3
|
+
"description": "Official dsh-cc plugin: an approval-free Codex rescue lane — one canonical, locked-down bash invocation auto-allowed via a PreToolUse hook, with Codex's internal sandbox off 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.
|
package/README.i18n.yaml
ADDED
|
@@ -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: 6f1df73f6bf0a89788b1cebd8c3947a404cf129e
|
|
6
|
+
README.zh.md: 3bac75d8fd2f05ba660fed173c324de5dc86f860
|
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# cc-codex-bridge
|
|
2
|
+
|
|
3
|
+
Official dsh-cc plugin: an **approval-free Codex rescue lane**. Installing it lets a
|
|
4
|
+
dsh-cc session run exactly one canonical, locked-down Codex rescue 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**: Codex runs with its
|
|
9
|
+
internal sandbox off (nested sandboxes cannot stack), while the dsh outer sandbox
|
|
10
|
+
remains the single write boundary — workspace plus temp areas only.
|
|
11
|
+
|
|
12
|
+
## How it works
|
|
13
|
+
|
|
14
|
+
- One canonical invocation form, pinned byte-for-byte: the interpreter and launcher
|
|
15
|
+
paths must be expansion-free literal tokens equal to the plugin's canonical
|
|
16
|
+
anchors — no PATH lookup, no symlink trampoline, no `~`/glob/`$VAR` expansion,
|
|
17
|
+
no compound commands, no command substitution outside single quotes.
|
|
18
|
+
- A PreToolUse hook downgrades the permission verdict for exactly that form; every
|
|
19
|
+
other shape fails closed into the unchanged, approval-requiring flow.
|
|
20
|
+
- Codex credentials are synced into a `0700` temp-dir home per run; the Codex CLI
|
|
21
|
+
itself resolves to a validated absolute path at spawn.
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
1. **Status at session start.** A SessionStart hook fires on every session
|
|
26
|
+
(startup and resume alike) and injects a `cc-codex-bridge:` block stating
|
|
27
|
+
whether the lane is **ARMED** — including the exact canonical invocation to
|
|
28
|
+
type — or **NOT armed** with the machine reason in plain words.
|
|
29
|
+
2. **Invoke the rescue** with the plugin command:
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
/cc-codex-bridge:rescue review the failing spec
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The bare `rescue` name may collide with the Codex plugin's command, in
|
|
36
|
+
which case the bare registration is skipped — the scoped name above and the
|
|
37
|
+
always-present SessionStart canonical block keep the lane usable regardless.
|
|
38
|
+
3. **Multi-line prompts** go through `--prompt-file`: write the prompt text to
|
|
39
|
+
a file inside the workspace (or the canonical tmpdir) and use the
|
|
40
|
+
`--prompt-file <path>` form from the SessionStart block.
|
|
41
|
+
4. **`--last` only on explicit continue**: the resume flag is used only when
|
|
42
|
+
the user explicitly asks to continue the previous rescue.
|
|
43
|
+
5. **Fail closed.** If the SessionStart block is absent or reports NOT armed,
|
|
44
|
+
the model must not guess or construct the canonical invocation — the rescue
|
|
45
|
+
falls back to the normal, approval-requiring path (stock `/codex:rescue`).
|
|
46
|
+
|
|
47
|
+
## Dev-session degradation
|
|
48
|
+
|
|
49
|
+
In dsh-cc's own repo dev sessions the launcher anchor sits inside the session
|
|
50
|
+
workspace, so arming is refused (`anchor-under-writable-root`) and the lane
|
|
51
|
+
degrades to the normal approval path. Expected and documented.
|
|
52
|
+
|
|
53
|
+
## Security model (capability tunnel, stated plainly)
|
|
54
|
+
|
|
55
|
+
Enabling the bridge means explicitly dropping the human checkpoint for this one
|
|
56
|
+
command form. Unattended Codex may run any subprocess the outer sandbox permits —
|
|
57
|
+
including actions the permission classifier would otherwise escalate (git push,
|
|
58
|
+
ssh, cloud CLIs) and unlimited networking. **Only the filesystem write boundary
|
|
59
|
+
holds** (workspace + temp areas); nothing else is claimed. The bridge is opt-in by
|
|
60
|
+
installation; **uninstalling or disabling the plugin is the kill switch**.
|
|
61
|
+
|
|
62
|
+
## Current status
|
|
63
|
+
|
|
64
|
+
PR-1 shipped the skeleton, PR-2 activated the gate (the PreToolUse hook that
|
|
65
|
+
auto-allows exactly the canonical rescue invocation), and PR-3 completes the
|
|
66
|
+
entry surface: the SessionStart status/canonical-block hook and the final
|
|
67
|
+
`/cc-codex-bridge:rescue` command — the lane is fully usable once the plugin
|
|
68
|
+
is installed.
|
|
69
|
+
|
|
70
|
+
## Install / uninstall
|
|
71
|
+
|
|
72
|
+
Install from the dsh-cc marketplace, plugin name `cc-codex-bridge`:
|
|
73
|
+
|
|
74
|
+
```sh
|
|
75
|
+
claude plugin install cc-codex-bridge@dsh-cc
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Uninstalling (or disabling) the plugin removes the lane entirely:
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
claude plugin uninstall cc-codex-bridge@dsh-cc
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Known limits
|
|
85
|
+
|
|
86
|
+
- In dsh-cc's own repo dev sessions the launcher anchor sits inside the workspace,
|
|
87
|
+
so the bridge refuses to arm and degrades to the manual flow (expected,
|
|
88
|
+
documented).
|
|
89
|
+
- A non-empty ambient `BASH_ENV` or `ENV` disarms the lane (shell-function
|
|
90
|
+
takeover defense).
|
|
91
|
+
- Resume support in v1 is `--last` only.
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# cc-codex-bridge
|
|
2
|
+
|
|
3
|
+
dsh-cc 官方插件:一条**免审批的 Codex 救援通道**。安装后,dsh-cc 会话可以运行唯一一种
|
|
4
|
+
规范、锁死的 Codex 救援调用 —— `node <launcher> [--last] <prompt>` —— 无需人工审批:
|
|
5
|
+
PreToolUse 钩子只对这一种命令形态自动放行。
|
|
6
|
+
|
|
7
|
+
核心思路是**状态搬迁,而非放宽沙箱**:Codex 以关闭内部沙箱的方式运行(嵌套沙箱无法
|
|
8
|
+
叠加),同时 dsh 外层沙箱仍是唯一的写入边界 —— 仅限工作区与临时目录。
|
|
9
|
+
|
|
10
|
+
## 工作原理
|
|
11
|
+
|
|
12
|
+
- 唯一的规范调用形态,逐字节锁定:解释器与启动器路径必须是不含展开的字面量,与插件的
|
|
13
|
+
规范锚点逐字节相等 —— 不走 PATH 查找、不允许符号链接跳板、禁止 `~`/glob/`$VAR` 展开、
|
|
14
|
+
禁止复合命令、单引号之外禁止命令替换。
|
|
15
|
+
- PreToolUse 钩子只对这一形态降级权限判定;其他一切形态一律失败关闭(fail-closed),
|
|
16
|
+
回落到原有需审批的流程。
|
|
17
|
+
- 每次运行前,Codex 凭据会被同步到一个位于临时目录、权限为 `0700` 的专属 home;Codex
|
|
18
|
+
CLI 本身在启动时解析为经过校验的绝对路径。
|
|
19
|
+
|
|
20
|
+
## 使用方法
|
|
21
|
+
|
|
22
|
+
1. **会话开始时的状态块。** SessionStart 钩子在每次会话启动时触发(startup 与 resume
|
|
23
|
+
均包括),注入一个以 `cc-codex-bridge:` 开头的块:说明通道是否 **已启用(ARMED)** ——
|
|
24
|
+
并给出可照抄的规范调用 —— 或 **未启用(NOT armed)** 及其白话原因。
|
|
25
|
+
2. **发起救援**,使用插件命令:
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
/cc-codex-bridge:rescue review the failing spec
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
裸名 `rescue` 可能与 Codex 插件的同名命令冲突;冲突时裸名注册会被跳过 —— 上面的
|
|
32
|
+
带作用域名称加上始终存在的 SessionStart 规范块,保证通道在任何情况下都可用。
|
|
33
|
+
3. **多行提示词** 走 `--prompt-file`:先用文件工具把提示词写入工作区内(或规范临时
|
|
34
|
+
目录)的文件,再使用 SessionStart 块中的 `--prompt-file <path>` 形态。
|
|
35
|
+
4. **`--last` 仅在明确要求续聊时使用**:只有当用户明确要求继续上一次救援时才加该标志。
|
|
36
|
+
5. **失败即关闭。** 若 SessionStart 块缺失或显示未启用,模型不得猜测或自行拼造规范调用
|
|
37
|
+
—— 救援回落到正常的需审批路径(原生 `/codex:rescue`)。
|
|
38
|
+
|
|
39
|
+
## 开发会话降级
|
|
40
|
+
|
|
41
|
+
在 dsh-cc 自身的仓库开发会话中,启动器锚点位于会话工作区内,启用会被拒绝
|
|
42
|
+
(`anchor-under-writable-root`),通道降级为正常审批路径。预期行为,已有文档。
|
|
43
|
+
|
|
44
|
+
## 安全模型(能力隧道,直言不讳)
|
|
45
|
+
|
|
46
|
+
启用本桥接意味着明确放弃这一种命令形态的人工检查点。无人值守的 Codex 可以运行外层
|
|
47
|
+
沙箱允许的任何子进程 —— 包括权限分类器本会升级处理的操作(git push、ssh、云 CLI)以及
|
|
48
|
+
不受限的网络访问。**只有文件系统写入边界仍然成立**(工作区 + 临时目录),除此之外不作
|
|
49
|
+
任何承诺。安装本插件即是选择加入;**卸载或禁用插件即是一键关闭**。
|
|
50
|
+
|
|
51
|
+
## 当前状态
|
|
52
|
+
|
|
53
|
+
PR-1 交付骨架,PR-2 激活闸门(对且仅对规范救援调用自动放行的 PreToolUse 钩子),
|
|
54
|
+
PR-3 补齐入口表面:SessionStart 状态/规范块钩子与最终的 `/cc-codex-bridge:rescue`
|
|
55
|
+
命令 —— 插件一旦安装,通道即完整可用。
|
|
56
|
+
|
|
57
|
+
## 安装 / 卸载
|
|
58
|
+
|
|
59
|
+
从 dsh-cc marketplace 安装,插件名 `cc-codex-bridge`:
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
claude plugin install cc-codex-bridge@dsh-cc
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
卸载(或禁用)插件即彻底移除该通道:
|
|
66
|
+
|
|
67
|
+
```sh
|
|
68
|
+
claude plugin uninstall cc-codex-bridge@dsh-cc
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## 已知限制
|
|
72
|
+
|
|
73
|
+
- 在 dsh-cc 自身的仓库开发会话中,启动器锚点位于工作区内,桥接会拒绝启用并降级为手动
|
|
74
|
+
流程(预期行为,已有文档)。
|
|
75
|
+
- 环境变量 `BASH_ENV` 或 `ENV` 非空时通道自动失效(防御 shell 函数劫持)。
|
|
76
|
+
- v1 的续聊支持仅有 `--last`。
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Run a Codex rescue review through the cc-codex-bridge lane
|
|
3
|
+
argument-hint: "[rescue request]"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
You are dispatching a Codex rescue for this request from the user:
|
|
7
|
+
|
|
8
|
+
$ARGUMENTS
|
|
9
|
+
|
|
10
|
+
The **cc-codex-bridge** plugin's SessionStart hook injected a block at session
|
|
11
|
+
start beginning with `cc-codex-bridge:` that states whether the rescue 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 contains characters that are
|
|
19
|
+
awkward as one shell word), write the text to a file inside the current
|
|
20
|
+
workspace (or the canonical tmpdir) with your file-write tool, then use the
|
|
21
|
+
`--prompt-file <path>` form from the block. Never edit, abbreviate, or
|
|
22
|
+
re-derive the anchor paths.
|
|
23
|
+
2. **`--last` ONLY when the user explicitly asked to continue the previous
|
|
24
|
+
rescue** (e.g. "continue the last rescue"). Otherwise omit it.
|
|
25
|
+
3. **Fail closed when the block is absent or reports NOT armed.** If the
|
|
26
|
+
SessionStart block is missing (e.g. the session resumed without it) or says
|
|
27
|
+
the lane is not armed, you MUST NOT guess or construct the canonical
|
|
28
|
+
invocation — fall back to the normal, approval-requiring Codex rescue path
|
|
29
|
+
(the stock `/codex:rescue` flow, expecting the usual permission checkpoint)
|
|
30
|
+
and tell the user that is what you did.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* codex-rescue-allow.mjs — the §3.2 pre-execute allow listener as a plugin
|
|
4
|
+
* PreToolUse command hook (plan §9 S2/S3).
|
|
5
|
+
*
|
|
6
|
+
* Contract: on a byte-exact canonical rescue 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 (§3.2-f 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 (§5 one-source rule): a command hook runs
|
|
17
|
+
* through a PATH-resolved interpreter, so the byte-pinned pair is the
|
|
18
|
+
* realpath of this process's own interpreter executable and the realpath
|
|
19
|
+
* of the plugin's own launcher script (see canonical.mjs for the
|
|
20
|
+
* derivation). Both must sit outside the writable-root refusal set and
|
|
21
|
+
* ambient BASH_ENV/ENV must be empty, or the bridge is disarmed for this
|
|
22
|
+
* call.
|
|
23
|
+
*/
|
|
24
|
+
import { tmpdir } from 'node:os'
|
|
25
|
+
import { isAbsolute, join } from 'node:path'
|
|
26
|
+
import { arming, inside, safeReal } from '../scripts/lib/canonical.mjs'
|
|
27
|
+
import { matchInvocation } from '../scripts/lib/argv.mjs'
|
|
28
|
+
|
|
29
|
+
const REASON = 'cc-codex-bridge: canonical rescue invocation (byte-pinned anchors, expansion-free)'
|
|
30
|
+
|
|
31
|
+
/** Silent pass: no stdout at all, exit 0 — the unchanged existing flow decides. */
|
|
32
|
+
const silent = () => process.exit(0)
|
|
33
|
+
|
|
34
|
+
let input = ''
|
|
35
|
+
process.stdin.setEncoding('utf8')
|
|
36
|
+
for await (const chunk of process.stdin) input += chunk
|
|
37
|
+
|
|
38
|
+
let payload
|
|
39
|
+
try {
|
|
40
|
+
payload = JSON.parse(input)
|
|
41
|
+
} catch {
|
|
42
|
+
silent()
|
|
43
|
+
}
|
|
44
|
+
if (payload?.tool_name !== 'Bash') silent()
|
|
45
|
+
const command = payload?.tool_input?.command
|
|
46
|
+
if (typeof command !== 'string' || command === '') silent()
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
const arm = arming(typeof payload.cwd === 'string' ? payload.cwd : process.cwd(), { hookUrl: import.meta.url })
|
|
50
|
+
if (!arm.armed) silent()
|
|
51
|
+
const { node: NODE, launcher: LAUNCHER, cwd } = arm
|
|
52
|
+
|
|
53
|
+
const match = matchInvocation(command, { node: NODE, launcher: LAUNCHER })
|
|
54
|
+
if (!match.ok) silent()
|
|
55
|
+
|
|
56
|
+
if (match.value.prompt.kind === 'prompt-file') {
|
|
57
|
+
const raw = match.value.prompt.path
|
|
58
|
+
const abs = isAbsolute(raw) ? raw : join(cwd ?? payload.cwd, raw)
|
|
59
|
+
// §3.2-d matcher-side containment: realpath must land inside the session
|
|
60
|
+
// workspace or the canonical tmpdir (a symlink escaping via realpath is
|
|
61
|
+
// refused here; the launcher re-checks on the fd it opens).
|
|
62
|
+
if (!inside(safeReal(abs), [cwd, safeReal(tmpdir())].filter((p) => p !== null))) silent()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
process.stdout.write(
|
|
66
|
+
JSON.stringify({
|
|
67
|
+
hookSpecificOutput: {
|
|
68
|
+
hookEventName: 'PreToolUse',
|
|
69
|
+
permissionDecision: 'allow',
|
|
70
|
+
permissionDecisionReason: REASON,
|
|
71
|
+
},
|
|
72
|
+
}) + '\n',
|
|
73
|
+
)
|
|
74
|
+
} catch {
|
|
75
|
+
silent()
|
|
76
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* codex-rescue-context.mjs — the SessionStart context hook (plan §9 S4).
|
|
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)
|
package/hooks/hooks.json
ADDED
|
@@ -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/codex-rescue-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/codex-rescue-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-codex-bridge",
|
|
3
|
+
"version": "0.8.1",
|
|
4
|
+
"description": "Official dsh-cc plugin: an approval-free Codex rescue lane — one canonical, locked-down bash invocation auto-allowed via a PreToolUse hook, with Codex's internal sandbox off 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-codex-bridge"
|
|
21
|
+
}
|
|
22
|
+
}
|