@tencent-ai/agent-harness-linux-x64-musl 0.1.3

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.
Files changed (53) hide show
  1. package/LICENSE +21 -0
  2. package/bin/agent-harness +0 -0
  3. package/bin/runtime/codebuddy/LICENSE.txt +19 -0
  4. package/bin/runtime/codebuddy/package.json +17 -0
  5. package/bin/runtime/codebuddy/product.cloudhosted.json +825 -0
  6. package/bin/runtime/codebuddy/product.internal.json +832 -0
  7. package/bin/runtime/codebuddy/product.ioa.json +1328 -0
  8. package/bin/runtime/codebuddy/product.json +2197 -0
  9. package/bin/runtime/codebuddy/product.selfhosted.json +362 -0
  10. package/bin/runtime/sandbox-runtime/vendor/seccomp/x64/apply-seccomp +0 -0
  11. package/bin/runtime/sandbox-runtime/vendor/seccomp/x64/unix-block.bpf +0 -0
  12. package/bin/vendor/genie-trash/linux-x64 +0 -0
  13. package/bin/vendor/ripgrep/rg +0 -0
  14. package/bin/vendor/shim/broker-ipc-client.cjs +162 -0
  15. package/bin/vendor/shim/broker-program-policy-check.cjs +68 -0
  16. package/bin/vendor/shim/brokered-bin/cat +641 -0
  17. package/bin/vendor/shim/brokered-bin/chmod +641 -0
  18. package/bin/vendor/shim/brokered-bin/codebuddy-toybox-dispatch +641 -0
  19. package/bin/vendor/shim/brokered-bin/cp +641 -0
  20. package/bin/vendor/shim/brokered-bin/dd +641 -0
  21. package/bin/vendor/shim/brokered-bin/find +641 -0
  22. package/bin/vendor/shim/brokered-bin/grep +641 -0
  23. package/bin/vendor/shim/brokered-bin/head +641 -0
  24. package/bin/vendor/shim/brokered-bin/ln +641 -0
  25. package/bin/vendor/shim/brokered-bin/ls +641 -0
  26. package/bin/vendor/shim/brokered-bin/mkdir +641 -0
  27. package/bin/vendor/shim/brokered-bin/mv +641 -0
  28. package/bin/vendor/shim/brokered-bin/readlink +641 -0
  29. package/bin/vendor/shim/brokered-bin/realpath +641 -0
  30. package/bin/vendor/shim/brokered-bin/rm +641 -0
  31. package/bin/vendor/shim/brokered-bin/rmdir +641 -0
  32. package/bin/vendor/shim/brokered-bin/sed +641 -0
  33. package/bin/vendor/shim/brokered-bin/tail +641 -0
  34. package/bin/vendor/shim/brokered-bin/tee +641 -0
  35. package/bin/vendor/shim/brokered-bin/touch +641 -0
  36. package/bin/vendor/shim/brokered-bin/truncate +641 -0
  37. package/bin/vendor/shim/brokered-bin/unlink +641 -0
  38. package/bin/vendor/shim/brokered-bin/wc +641 -0
  39. package/bin/vendor/shim/brokered-sandbox-bash-env.sh +10 -0
  40. package/bin/vendor/shim/genie-safe-delete.cjs +10 -0
  41. package/bin/vendor/shim/node-brokered-fs-shim.cjs +952 -0
  42. package/bin/vendor/shim/node-language-shim.cjs +35 -0
  43. package/bin/vendor/shim/node-safe-delete-shim.cjs +823 -0
  44. package/bin/vendor/shim/safe-bin/rm +18 -0
  45. package/bin/vendor/shim/safe-bin/rmdir +18 -0
  46. package/bin/vendor/shim/safe-bin/safe-delete-bash-env.sh +8 -0
  47. package/bin/vendor/shim/safe-bin/safe-delete-common.sh +777 -0
  48. package/bin/vendor/shim/safe-bin/unlink +18 -0
  49. package/bin/vendor/shim/safe-delete-broker-delete.cjs +166 -0
  50. package/bin/vendor/shim/safe-delete-bulk-guard.cjs +465 -0
  51. package/bin/vendor/shim/shell-runtime-bash-env.sh +8 -0
  52. package/bin/vendor/shim/sitecustomize.py +1213 -0
  53. package/package.json +56 -0
@@ -0,0 +1,641 @@
1
+ #!/usr/bin/env sh
2
+
3
+ __cb_app="${0##*/}"
4
+ __cb_toybox="${CODEBUDDY_TOYBOX_BIN:-}"
5
+ __cb_brokered_dir="${CODEBUDDY_BROKERED_BIN_DIR:-${0%/*}}"
6
+ __cb_broker_client="${CODEBUDDY_BROKER_IPC_CLIENT:-${__cb_brokered_dir%/brokered-bin}/broker-ipc-client.cjs}"
7
+ __cb_program_policy_helper="${__cb_brokered_dir%/brokered-bin}/broker-program-policy-check.cjs"
8
+
9
+ __cb_run_node() {
10
+ if [ "${CODEBUDDY_NODE_RUN_AS_NODE:-}" = "1" ]; then
11
+ ELECTRON_RUN_AS_NODE=1 NODE_OPTIONS= "${CODEBUDDY_NODE_BIN:-node}" "$@"
12
+ else
13
+ NODE_OPTIONS= "${CODEBUDDY_NODE_BIN:-node}" "$@"
14
+ fi
15
+ }
16
+
17
+ __cb_cleanup() { /bin/rm -f "$__cb_err" 2>/dev/null || true; }
18
+
19
+ __cb_should_fallback() { case "$1" in *"Unknown command "*|*"Unknown option "*|*"unknown option "*|*"unrecognized option "*) return 0 ;; *) return 1 ;; esac; }
20
+
21
+ __cb_check_program_policy() {
22
+ [ -n "${CODEBUDDY_SANDBOX_PROGRAM_POLICY_COMMAND:-}" ] || return 0
23
+ if [ -z "${CODEBUDDY_SANDBOX_BROKER_IPC_ADDRESS:-}" ] \
24
+ || [ -z "${CODEBUDDY_SANDBOX_BROKER_SESSION_ID:-}" ] \
25
+ || [ ! -f "$__cb_broker_client" ] \
26
+ || [ ! -f "$__cb_program_policy_helper" ]; then
27
+ printf '%s' 'Brokered program policy check unavailable' >&2
28
+ return 13
29
+ fi
30
+ __cb_run_node "$__cb_program_policy_helper" "$1" toybox-dispatch "$__cb_broker_client"
31
+ }
32
+
33
+ __cb_check_program_policy "$__cb_app"
34
+ __cb_program_policy_status=$?
35
+ [ "$__cb_program_policy_status" -eq 0 ] || exit "$__cb_program_policy_status"
36
+
37
+ __cb_path_without_brokered_dir() {
38
+ __cb_old_ifs="$IFS"
39
+ IFS=:; __cb_new_path=
40
+ for __cb_dir in ${PATH:-}; do
41
+ [ "$__cb_dir" = "$__cb_brokered_dir" ] && continue
42
+ __cb_new_path="${__cb_new_path:+$__cb_new_path:}$__cb_dir"
43
+ done
44
+ IFS="$__cb_old_ifs"
45
+ printf '%s' "$__cb_new_path"
46
+ }
47
+
48
+ __cb_fallback() {
49
+ case "$__cb_app" in
50
+ rm|rmdir|unlink) [ ! -x "${CODEBUDDY_SAFE_DELETE_BIN_DIR:-}/${__cb_app}" ] || BASH_ENV= exec "${CODEBUDDY_SAFE_DELETE_BIN_DIR}/${__cb_app}" "$@" ;;
51
+ esac
52
+
53
+ __cb_fallback_path="$(__cb_path_without_brokered_dir)"
54
+ [ -z "$__cb_fallback_path" ] && return 127
55
+ PATH="$__cb_fallback_path" exec "$__cb_app" "$@"
56
+ }
57
+
58
+ if [ "${CODEBUDDY_TOYBOX_DISPATCH_ACTIVE:-}" = "$__cb_app" ]; then
59
+ unset CODEBUDDY_TOYBOX_DISPATCH_ACTIVE
60
+ __cb_fallback "$@"
61
+ exit $?
62
+ fi
63
+
64
+ __cb_prebackup_path() {
65
+ [ -n "${1:-}" ] || return 0
66
+ [ "$1" != "-" ] || return 0
67
+ [ -n "${CODEBUDDY_SANDBOX_BROKER_IPC_ADDRESS:-}" ] || return 0
68
+ [ -n "${CODEBUDDY_SANDBOX_BROKER_SESSION_ID:-}" ] || return 0
69
+ [ -n "${CODEBUDDY_SANDBOX_FILE_TOKEN_OPERATION_COMMAND:-}" ] || return 0
70
+ [ -f "$__cb_broker_client" ] || return 0
71
+
72
+ __cb_run_node - "$__cb_broker_client" "$1" <<'NODE'
73
+ const path = require('path');
74
+ const { sendBrokerRequestSync } = require(process.argv[2]);
75
+ const response = sendBrokerRequestSync({
76
+ command: process.env.CODEBUDDY_SANDBOX_FILE_TOKEN_OPERATION_COMMAND,
77
+ operation: 'write',
78
+ path: path.resolve(process.argv[3]),
79
+ sessionId: process.env.CODEBUDDY_SANDBOX_BROKER_SESSION_ID,
80
+ toolCallId: process.env.CODEBUDDY_SANDBOX_BROKER_TOOL_CALL_ID,
81
+ brokerTraceId: process.env.CODEBUDDY_SANDBOX_BROKER_TRACE_ID,
82
+ runtime: 'toybox-dispatch',
83
+ });
84
+ if (response && (response.ok === true || response.decision === 'sandbox')) {
85
+ process.exit(0);
86
+ }
87
+ process.stderr.write(response && response.error ? response.error : 'Brokered write preflight denied');
88
+ process.exit(13);
89
+ NODE
90
+ }
91
+
92
+ __cb_prebackup_tree() {
93
+ [ -n "${1:-}" ] || return 0
94
+ [ -d "$1" ] || return 0
95
+ [ -n "${CODEBUDDY_SANDBOX_BROKER_IPC_ADDRESS:-}" ] || return 0
96
+ [ -n "${CODEBUDDY_SANDBOX_BROKER_SESSION_ID:-}" ] || return 0
97
+ [ -n "${CODEBUDDY_SANDBOX_FILE_TOKEN_OPERATION_COMMAND:-}" ] || return 0
98
+ [ -f "$__cb_broker_client" ] || return 0
99
+
100
+ __cb_run_node - "$__cb_broker_client" "$1" <<'NODE'
101
+ const fs = require('fs');
102
+ const path = require('path');
103
+ const { sendBrokerRequestSync } = require(process.argv[2]);
104
+
105
+ function prebackupFile(filePath) {
106
+ const response = sendBrokerRequestSync({
107
+ command: process.env.CODEBUDDY_SANDBOX_FILE_TOKEN_OPERATION_COMMAND,
108
+ operation: 'write',
109
+ path: path.resolve(filePath),
110
+ sessionId: process.env.CODEBUDDY_SANDBOX_BROKER_SESSION_ID,
111
+ toolCallId: process.env.CODEBUDDY_SANDBOX_BROKER_TOOL_CALL_ID,
112
+ brokerTraceId: process.env.CODEBUDDY_SANDBOX_BROKER_TRACE_ID,
113
+ runtime: 'toybox-dispatch',
114
+ });
115
+ if (response && (response.ok === true || response.decision === 'sandbox')) {
116
+ return;
117
+ }
118
+ process.stderr.write(response && response.error ? response.error : 'Brokered write preflight denied');
119
+ process.exit(13);
120
+ }
121
+
122
+ function walk(dir) {
123
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
124
+ const entryPath = path.join(dir, entry.name);
125
+ if (entry.isDirectory()) {
126
+ walk(entryPath);
127
+ } else if (entry.isFile()) {
128
+ prebackupFile(entryPath);
129
+ }
130
+ }
131
+ }
132
+
133
+ walk(process.argv[3]);
134
+ NODE
135
+ }
136
+
137
+ __cb_prebackup_tree_or_file() {
138
+ if [ -f "$1" ]; then
139
+ __cb_prebackup_path "$1"
140
+ return $?
141
+ fi
142
+ if [ -d "$1" ]; then
143
+ __cb_prebackup_tree "$1"
144
+ return $?
145
+ fi
146
+ __cb_prebackup_path "$1"
147
+ }
148
+
149
+ __cb_prebackup_truncate() {
150
+ __cb_after_options=
151
+ __cb_skip_next=
152
+ for __cb_arg in "$@"; do
153
+ if [ -n "$__cb_skip_next" ]; then __cb_skip_next=; continue; fi
154
+ if [ -n "$__cb_after_options" ]; then __cb_prebackup_path "$__cb_arg" || return $?; continue; fi
155
+ case "$__cb_arg" in
156
+ --) __cb_after_options=1 ;;
157
+ -s|--size) __cb_skip_next=1 ;;
158
+ --size=*) ;;
159
+ -*) ;;
160
+ *) __cb_prebackup_path "$__cb_arg" || return $? ;;
161
+ esac
162
+ done
163
+ }
164
+
165
+ __cb_prebackup_dd() {
166
+ for __cb_arg in "$@"; do
167
+ case "$__cb_arg" in
168
+ of=*) __cb_prebackup_path "${__cb_arg#of=}" || return $? ;;
169
+ esac
170
+ done
171
+ }
172
+
173
+ __cb_prebackup_tee() {
174
+ __cb_after_options=
175
+ for __cb_arg in "$@"; do
176
+ if [ -n "$__cb_after_options" ]; then __cb_prebackup_path "$__cb_arg" || return $?; continue; fi
177
+ case "$__cb_arg" in
178
+ --) __cb_after_options=1 ;;
179
+ -*) ;;
180
+ *) __cb_prebackup_path "$__cb_arg" || return $? ;;
181
+ esac
182
+ done
183
+ }
184
+
185
+ __cb_prebackup_touch() {
186
+ __cb_needs_prebackup=
187
+ __cb_after_options=
188
+ __cb_skip_next=
189
+ for __cb_arg in "$@"; do
190
+ if [ -n "$__cb_skip_next" ]; then __cb_skip_next=; continue; fi
191
+ if [ -n "$__cb_after_options" ]; then continue; fi
192
+ case "$__cb_arg" in
193
+ --) __cb_after_options=1 ;;
194
+ -d|--date|-r|--reference|-t|--time) __cb_skip_next=1; __cb_needs_prebackup=1 ;;
195
+ --date=*|--reference=*|--time=*|-*) __cb_needs_prebackup=1 ;;
196
+ esac
197
+ done
198
+ [ -n "$__cb_needs_prebackup" ] || return 0
199
+
200
+ __cb_after_options=
201
+ __cb_skip_next=
202
+ for __cb_arg in "$@"; do
203
+ if [ -n "$__cb_skip_next" ]; then __cb_skip_next=; continue; fi
204
+ if [ -n "$__cb_after_options" ]; then __cb_prebackup_path "$__cb_arg" || return $?; continue; fi
205
+ case "$__cb_arg" in
206
+ --) __cb_after_options=1 ;;
207
+ -d|--date|-r|--reference|-t|--time) __cb_skip_next=1 ;;
208
+ --date=*|--reference=*|--time=*|-*) ;;
209
+ *) __cb_prebackup_path "$__cb_arg" || return $? ;;
210
+ esac
211
+ done
212
+ }
213
+
214
+ __cb_prebackup_mkdir() {
215
+ __cb_needs_prebackup=
216
+ __cb_operand_count=0
217
+ __cb_after_options=
218
+ __cb_skip_next=
219
+ for __cb_arg in "$@"; do
220
+ if [ -n "$__cb_skip_next" ]; then __cb_skip_next=; continue; fi
221
+ if [ -n "$__cb_after_options" ]; then __cb_operand_count=$((__cb_operand_count + 1)); continue; fi
222
+ case "$__cb_arg" in
223
+ --) __cb_after_options=1 ;;
224
+ -p|--parents) ;;
225
+ -m|--mode) __cb_skip_next=1; __cb_needs_prebackup=1 ;;
226
+ --mode=*|-) __cb_needs_prebackup=1 ;;
227
+ -*) __cb_needs_prebackup=1 ;;
228
+ *) __cb_operand_count=$((__cb_operand_count + 1)) ;;
229
+ esac
230
+ done
231
+ [ "$__cb_operand_count" -gt 1 ] && __cb_needs_prebackup=1
232
+ [ -n "$__cb_needs_prebackup" ] || return 0
233
+
234
+ __cb_after_options=
235
+ __cb_skip_next=
236
+ for __cb_arg in "$@"; do
237
+ if [ -n "$__cb_skip_next" ]; then __cb_skip_next=; continue; fi
238
+ if [ -n "$__cb_after_options" ]; then __cb_prebackup_path "$__cb_arg" || return $?; continue; fi
239
+ case "$__cb_arg" in
240
+ --) __cb_after_options=1 ;;
241
+ -m|--mode) __cb_skip_next=1 ;;
242
+ --mode=*|-p|--parents|-) ;;
243
+ -*) ;;
244
+ *) __cb_prebackup_path "$__cb_arg" || return $? ;;
245
+ esac
246
+ done
247
+ }
248
+
249
+ __cb_prebackup_mv() {
250
+ __cb_needs_prebackup=
251
+ __cb_operand_count=0
252
+ __cb_after_options=
253
+ __cb_skip_next=
254
+ for __cb_arg in "$@"; do
255
+ if [ "$__cb_skip_next" = "target-dir" ]; then __cb_skip_next=; continue; fi
256
+ if [ -n "$__cb_after_options" ]; then __cb_operand_count=$((__cb_operand_count + 1)); continue; fi
257
+ case "$__cb_arg" in
258
+ --) __cb_after_options=1 ;;
259
+ -t|--target-directory) __cb_skip_next=target-dir; __cb_needs_prebackup=1 ;;
260
+ --target-directory=*) __cb_needs_prebackup=1 ;;
261
+ -*) __cb_needs_prebackup=1 ;;
262
+ *) __cb_operand_count=$((__cb_operand_count + 1)) ;;
263
+ esac
264
+ done
265
+ [ "$__cb_operand_count" -gt 2 ] && __cb_needs_prebackup=1
266
+ [ -n "$__cb_needs_prebackup" ] || return 0
267
+
268
+ # Rename mutates both the source entry and the destination entry. Preflight
269
+ # sources separately, then reuse cp's destination resolution for directories.
270
+ __cb_mv_target_dir=
271
+ __cb_after_options=
272
+ __cb_skip_next=
273
+ for __cb_arg in "$@"; do
274
+ if [ "$__cb_skip_next" = "target-dir" ]; then __cb_mv_target_dir="$__cb_arg"; __cb_skip_next=; continue; fi
275
+ if [ -n "$__cb_after_options" ]; then continue; fi
276
+ case "$__cb_arg" in
277
+ --) __cb_after_options=1 ;;
278
+ -t|--target-directory) __cb_skip_next=target-dir ;;
279
+ --target-directory=*) __cb_mv_target_dir="${__cb_arg#*=}" ;;
280
+ esac
281
+ done
282
+
283
+ __cb_mv_index=0
284
+ __cb_after_options=
285
+ __cb_skip_next=
286
+ for __cb_arg in "$@"; do
287
+ if [ "$__cb_skip_next" = "target-dir" ]; then __cb_skip_next=; continue; fi
288
+ if [ -n "$__cb_after_options" ]; then
289
+ __cb_mv_index=$((__cb_mv_index + 1))
290
+ if [ -n "$__cb_mv_target_dir" ] || [ "$__cb_mv_index" -lt "$__cb_operand_count" ]; then
291
+ __cb_prebackup_path "$__cb_arg" || return $?
292
+ fi
293
+ continue
294
+ fi
295
+ case "$__cb_arg" in
296
+ --) __cb_after_options=1 ;;
297
+ -t|--target-directory) __cb_skip_next=target-dir ;;
298
+ --target-directory=*|-*) ;;
299
+ *)
300
+ __cb_mv_index=$((__cb_mv_index + 1))
301
+ if [ -n "$__cb_mv_target_dir" ] || [ "$__cb_mv_index" -lt "$__cb_operand_count" ]; then
302
+ __cb_prebackup_path "$__cb_arg" || return $?
303
+ fi
304
+ ;;
305
+ esac
306
+ done
307
+ __cb_prebackup_cp "$@"
308
+ }
309
+
310
+ __cb_prebackup_last_operand() {
311
+ __cb_after_options=
312
+ __cb_last=
313
+ for __cb_arg in "$@"; do
314
+ if [ -n "$__cb_after_options" ]; then __cb_last="$__cb_arg"; continue; fi
315
+ case "$__cb_arg" in
316
+ --) __cb_after_options=1 ;;
317
+ -*) ;;
318
+ *) __cb_last="$__cb_arg" ;;
319
+ esac
320
+ done
321
+ [ -z "$__cb_last" ] || __cb_prebackup_tree_or_file "$__cb_last"
322
+ }
323
+
324
+ __cb_cp_target_for_source() {
325
+ __cb_src="$1"
326
+ __cb_dest="$2"
327
+ if [ -d "$__cb_dest" ] && [ -z "${__cb_cp_no_target_dir:-}" ]; then
328
+ __cb_base="${__cb_src%/}"
329
+ __cb_base="${__cb_base##*/}"
330
+ [ -z "$__cb_base" ] || __cb_prebackup_tree_or_file "$__cb_dest/$__cb_base"
331
+ return $?
332
+ fi
333
+ __cb_prebackup_tree_or_file "$__cb_dest"
334
+ }
335
+
336
+ __cb_prebackup_cp() {
337
+ __cb_after_options=
338
+ __cb_skip_next=
339
+ __cb_cp_no_target_dir=
340
+ __cb_cp_target_dir=
341
+ __cb_cp_count=0
342
+ __cb_cp_dest=
343
+ for __cb_arg in "$@"; do
344
+ if [ "$__cb_skip_next" = "target-dir" ]; then __cb_cp_target_dir="$__cb_arg"; __cb_skip_next=; continue; fi
345
+ if [ -n "$__cb_after_options" ]; then __cb_cp_count=$((__cb_cp_count + 1)); __cb_cp_dest="$__cb_arg"; continue; fi
346
+ case "$__cb_arg" in
347
+ --) __cb_after_options=1 ;;
348
+ -t|--target-directory) __cb_skip_next=target-dir ;;
349
+ --target-directory=*) __cb_cp_target_dir="${__cb_arg#*=}" ;;
350
+ -T|--no-target-directory) __cb_cp_no_target_dir=1 ;;
351
+ -*) ;;
352
+ *) __cb_cp_count=$((__cb_cp_count + 1)); __cb_cp_dest="$__cb_arg" ;;
353
+ esac
354
+ done
355
+
356
+ if [ -n "$__cb_cp_target_dir" ]; then
357
+ __cb_after_options=
358
+ __cb_skip_next=
359
+ for __cb_arg in "$@"; do
360
+ if [ "$__cb_skip_next" = "target-dir" ]; then __cb_skip_next=; continue; fi
361
+ if [ -n "$__cb_after_options" ]; then __cb_cp_target_for_source "$__cb_arg" "$__cb_cp_target_dir" || return $?; continue; fi
362
+ case "$__cb_arg" in
363
+ --) __cb_after_options=1 ;;
364
+ -t|--target-directory) __cb_skip_next=target-dir ;;
365
+ --target-directory=*|-T|--no-target-directory|-*) ;;
366
+ *) __cb_cp_target_for_source "$__cb_arg" "$__cb_cp_target_dir" || return $? ;;
367
+ esac
368
+ done
369
+ return 0
370
+ fi
371
+
372
+ [ "$__cb_cp_count" -ge 2 ] || return 0
373
+ __cb_after_options=
374
+ __cb_index=0
375
+ for __cb_arg in "$@"; do
376
+ if [ -n "$__cb_after_options" ]; then
377
+ __cb_index=$((__cb_index + 1))
378
+ [ "$__cb_index" -ge "$__cb_cp_count" ] || __cb_cp_target_for_source "$__cb_arg" "$__cb_cp_dest" || return $?
379
+ continue
380
+ fi
381
+ case "$__cb_arg" in
382
+ --) __cb_after_options=1 ;;
383
+ -t|--target-directory) __cb_skip_next=target-dir ;;
384
+ --target-directory=*|-T|--no-target-directory|-*) ;;
385
+ *)
386
+ __cb_index=$((__cb_index + 1))
387
+ [ "$__cb_index" -ge "$__cb_cp_count" ] || __cb_cp_target_for_source "$__cb_arg" "$__cb_cp_dest" || return $?
388
+ ;;
389
+ esac
390
+ done
391
+ }
392
+
393
+ __cb_prebackup_targets() {
394
+ case "$__cb_app" in
395
+ truncate) __cb_prebackup_truncate "$@" ;;
396
+ tee) __cb_prebackup_tee "$@" ;;
397
+ cp) __cb_prebackup_cp "$@" ;;
398
+ dd) __cb_prebackup_dd "$@" ;;
399
+ touch) __cb_prebackup_touch "$@" ;;
400
+ mkdir) __cb_prebackup_mkdir "$@" ;;
401
+ mv) __cb_prebackup_mv "$@" ;;
402
+ esac
403
+ }
404
+
405
+ __cb_host_op_ln() {
406
+ [ "$__cb_app" = "ln" ] || return 125
407
+ __cb_has_host_op_env || return 125
408
+
409
+ # Only simple ln [-s] SRC DEST is dispatched; other flags fall back to toybox.
410
+ __cb_run_node - "$__cb_broker_client" "$@" <<'NODE'
411
+ const fs = require('fs');
412
+ const path = require('path');
413
+ const { sendBrokerRequestSync } = require(process.argv[2]);
414
+
415
+ const args = process.argv.slice(3);
416
+ let symbolic = false;
417
+ let afterOptions = false;
418
+ const operands = [];
419
+
420
+ for (const arg of args) {
421
+ if (afterOptions) {
422
+ operands.push(arg);
423
+ continue;
424
+ }
425
+ if (arg === '--') {
426
+ afterOptions = true;
427
+ continue;
428
+ }
429
+ if (arg === '-s' || arg === '--symbolic') {
430
+ symbolic = true;
431
+ continue;
432
+ }
433
+ if (arg.startsWith('-')) {
434
+ process.exit(125);
435
+ }
436
+ operands.push(arg);
437
+ }
438
+
439
+ if (operands.length !== 2) {
440
+ process.exit(125);
441
+ }
442
+
443
+ const [fromArg, toArg] = operands;
444
+ const toPath = path.resolve(process.cwd(), toArg);
445
+ const fromPath = symbolic ? fromArg : path.resolve(process.cwd(), fromArg);
446
+ let linkPath = toPath;
447
+ try {
448
+ if (fs.statSync(toPath).isDirectory()) {
449
+ linkPath = path.join(toPath, path.basename(fromArg));
450
+ }
451
+ } catch {
452
+ linkPath = toPath;
453
+ }
454
+ const response = sendBrokerRequestSync({
455
+ command: process.env.CODEBUDDY_SANDBOX_HOST_FILE_OPERATION_COMMAND,
456
+ operation: 'link',
457
+ from: fromPath,
458
+ to: linkPath,
459
+ symbolic,
460
+ sessionId: process.env.CODEBUDDY_SANDBOX_BROKER_SESSION_ID,
461
+ toolCallId: process.env.CODEBUDDY_SANDBOX_BROKER_TOOL_CALL_ID,
462
+ brokerTraceId: process.env.CODEBUDDY_SANDBOX_BROKER_TRACE_ID,
463
+ runtime: 'toybox-dispatch',
464
+ });
465
+
466
+ if (response && response.ok === true) {
467
+ process.exit(0);
468
+ }
469
+ if (response && response.decision === 'sandbox') {
470
+ process.exit(125);
471
+ }
472
+ process.stderr.write(response && response.error ? response.error : 'Brokered link operation denied');
473
+ process.exit(13);
474
+ NODE
475
+ }
476
+
477
+ __cb_has_host_op_env() {
478
+ [ -n "${CODEBUDDY_SANDBOX_BROKER_IPC_ADDRESS:-}" ] || return 1
479
+ [ -n "${CODEBUDDY_SANDBOX_BROKER_SESSION_ID:-}" ] || return 1
480
+ [ -n "${CODEBUDDY_SANDBOX_HOST_FILE_OPERATION_COMMAND:-}" ] || return 1
481
+ [ -f "$__cb_broker_client" ] || return 1
482
+ }
483
+
484
+ __cb_host_op_touch_mkdir_mv() {
485
+ case "$__cb_app" in
486
+ touch|mkdir|mv) ;;
487
+ *) return 125 ;;
488
+ esac
489
+ __cb_has_host_op_env || return 125
490
+
491
+ __cb_run_node - "$__cb_broker_client" "$__cb_app" "$@" <<'NODE'
492
+ const fs = require('fs');
493
+ const path = require('path');
494
+ const { sendBrokerRequestSync } = require(process.argv[2]);
495
+
496
+ const app = process.argv[3];
497
+ const args = process.argv.slice(4);
498
+ const baseRequest = {
499
+ command: process.env.CODEBUDDY_SANDBOX_HOST_FILE_OPERATION_COMMAND,
500
+ sessionId: process.env.CODEBUDDY_SANDBOX_BROKER_SESSION_ID,
501
+ toolCallId: process.env.CODEBUDDY_SANDBOX_BROKER_TOOL_CALL_ID,
502
+ brokerTraceId: process.env.CODEBUDDY_SANDBOX_BROKER_TRACE_ID,
503
+ runtime: 'toybox-dispatch',
504
+ };
505
+
506
+ function parseOperands(acceptOption) {
507
+ let afterOptions = false;
508
+ const operands = [];
509
+ for (const arg of args) {
510
+ if (afterOptions) {
511
+ operands.push(arg);
512
+ continue;
513
+ }
514
+ if (arg === '--') {
515
+ afterOptions = true;
516
+ continue;
517
+ }
518
+ if (acceptOption(arg)) {
519
+ continue;
520
+ }
521
+ if (arg.startsWith('-')) {
522
+ process.exit(125);
523
+ }
524
+ operands.push(arg);
525
+ }
526
+ return operands;
527
+ }
528
+
529
+ function destinationPath(value, source) {
530
+ const resolved = path.resolve(process.cwd(), value);
531
+ try {
532
+ return fs.statSync(resolved).isDirectory()
533
+ ? path.join(resolved, path.basename(source))
534
+ : resolved;
535
+ } catch {
536
+ return resolved;
537
+ }
538
+ }
539
+
540
+ function dispatch(request) {
541
+ const response = sendBrokerRequestSync({ ...baseRequest, ...request });
542
+ if (response && response.ok === true) {
543
+ return;
544
+ }
545
+ if (response && response.decision === 'sandbox') {
546
+ process.exit(125);
547
+ }
548
+ process.stderr.write(response && response.error ? response.error : 'Brokered ' + app + ' operation denied');
549
+ process.exit(13);
550
+ }
551
+
552
+ if (app === 'touch') {
553
+ const operands = parseOperands(() => false);
554
+ if (operands.length === 0) { process.exit(125); }
555
+ for (const operand of operands) {
556
+ dispatch({ operation: 'touch', path: path.resolve(process.cwd(), operand) });
557
+ }
558
+ } else if (app === 'mkdir') {
559
+ let recursive = false;
560
+ const operands = parseOperands(arg => {
561
+ if (arg === '-p' || arg === '--parents') {
562
+ recursive = true;
563
+ return true;
564
+ }
565
+ return false;
566
+ });
567
+ if (operands.length !== 1) { process.exit(125); }
568
+ dispatch({ operation: 'mkdir', path: path.resolve(process.cwd(), operands[0]), recursive });
569
+ } else {
570
+ const operands = parseOperands(() => false);
571
+ if (operands.length !== 2) { process.exit(125); }
572
+ const [fromArg, toArg] = operands;
573
+ dispatch({
574
+ operation: 'rename',
575
+ from: path.resolve(process.cwd(), fromArg),
576
+ to: destinationPath(toArg, fromArg),
577
+ });
578
+ }
579
+ NODE
580
+ }
581
+
582
+ # rm/rmdir/unlink 在沙箱模式下由 toybox 原生实现直接执行,不会经过
583
+ # safe-bin/rm,因此批量删除审批(safe-delete-bulk-guard.cjs)在这里补一次,
584
+ # 与 node-safe-delete-shim.cjs / sitecustomize.py 里的调用方式保持一致。
585
+ __cb_bulk_guard_delete_check() {
586
+ case "$__cb_app" in
587
+ rm|rmdir|unlink) ;;
588
+ *) return 0 ;;
589
+ esac
590
+ __cb_bg_common_sh="${__cb_brokered_dir%/brokered-bin}/safe-bin/safe-delete-common.sh"
591
+ [ -f "$__cb_bg_common_sh" ] || return 0
592
+
593
+ __cb_bg_targets=()
594
+ __cb_bg_after_dd=
595
+ for __cb_bg_arg in "$@"; do
596
+ if [ -n "$__cb_bg_after_dd" ]; then
597
+ __cb_bg_targets+=("$__cb_bg_arg")
598
+ continue
599
+ fi
600
+ case "$__cb_bg_arg" in
601
+ --) __cb_bg_after_dd=1 ;;
602
+ -*) ;;
603
+ *) __cb_bg_targets+=("$__cb_bg_arg") ;;
604
+ esac
605
+ done
606
+ [ "${#__cb_bg_targets[@]}" -gt 0 ] || return 0
607
+
608
+ # shellcheck source=/dev/null
609
+ . "$__cb_bg_common_sh"
610
+ safe_delete_bulk_guard_non_tmp_check "${__cb_bg_targets[@]}"
611
+ }
612
+
613
+ if [ -z "$__cb_toybox" ] || [ ! -x "$__cb_toybox" ]; then __cb_fallback "$@"; exit $?; fi
614
+
615
+ __cb_bulk_guard_delete_check "$@" || exit $?
616
+ __cb_prebackup_targets "$@" || exit $?
617
+ __cb_host_op_ln "$@"
618
+ __cb_host_op_status=$?
619
+ if [ "$__cb_host_op_status" -eq 0 ]; then exit 0; fi
620
+ if [ "$__cb_host_op_status" -ne 125 ]; then exit "$__cb_host_op_status"; fi
621
+ __cb_host_op_touch_mkdir_mv "$@"
622
+ __cb_host_op_status=$?
623
+ if [ "$__cb_host_op_status" -eq 0 ]; then exit 0; fi
624
+ if [ "$__cb_host_op_status" -ne 125 ]; then exit "$__cb_host_op_status"; fi
625
+
626
+ __cb_err="$(/usr/bin/mktemp "${TMPDIR:-/tmp}/codebuddy-toybox.XXXXXX" 2>/dev/null || mktemp "${TMPDIR:-/tmp}/codebuddy-toybox.XXXXXX" 2>/dev/null)"
627
+ if [ -z "${__cb_err:-}" ]; then CODEBUDDY_TOYBOX_DISPATCH_ACTIVE="$__cb_app" exec "$__cb_toybox" "$__cb_app" "$@"; fi
628
+
629
+ CODEBUDDY_TOYBOX_DISPATCH_ACTIVE="$__cb_app" "$__cb_toybox" "$__cb_app" "$@" 2>"$__cb_err"
630
+ __cb_status=$?
631
+ if [ "$__cb_status" -eq 0 ]; then [ ! -s "$__cb_err" ] || /bin/cat "$__cb_err" >&2 2>/dev/null || true; __cb_cleanup; exit 0; fi
632
+
633
+ __cb_msg="$(/bin/cat "$__cb_err" 2>/dev/null || true)"
634
+ if __cb_should_fallback "$__cb_msg"; then
635
+ __cb_cleanup; __cb_fallback "$@"
636
+ exit $?
637
+ fi
638
+
639
+ [ -z "$__cb_msg" ] || printf '%s' "$__cb_msg" >&2
640
+ __cb_cleanup
641
+ exit "$__cb_status"