@tencent-ai/agent-sdk 0.3.206 → 0.3.209
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/cli/CHANGELOG.md +53 -0
- package/cli/builtin/workflows/deep-research.workflow.js +77 -20
- package/cli/dist/codebuddy-headless.js +293 -245
- package/cli/dist/web-ui/assets/index-CH6e4vvI.css +32 -0
- package/cli/dist/web-ui/assets/index-GcU4pZms.js +1102 -0
- package/cli/dist/web-ui/index.html +2 -2
- package/cli/dist/web-ui/sw.js +1 -1
- package/cli/package.json +4 -4
- package/cli/product.cloudhosted.json +2 -2
- package/cli/product.internal.json +2 -2
- package/cli/product.ioa.json +2 -2
- package/cli/product.json +3 -3
- package/cli/product.selfhosted.json +2 -2
- package/cli/vendor/native-builds.json +18 -0
- package/cli/vendor/shim/broker-ipc-client.cjs +158 -0
- package/cli/vendor/shim/brokered-bin/codebuddy-toybox-dispatch +381 -0
- package/cli/vendor/shim/brokered-sandbox-bash-env.sh +10 -0
- package/cli/vendor/shim/genie-safe-delete.cjs +4 -781
- package/cli/vendor/shim/native/binding.gyp +13 -0
- package/cli/vendor/shim/native/brokered_sandbox_native.c +293 -0
- package/cli/vendor/shim/native/darwin-arm64/brokered-sandbox-native.node +0 -0
- package/cli/vendor/shim/native/darwin-x64/brokered-sandbox-native.node +0 -0
- package/cli/vendor/shim/node-brokered-fs-shim.cjs +932 -0
- package/cli/vendor/shim/node-language-shim.cjs +35 -0
- package/cli/vendor/shim/node-safe-delete-shim.cjs +810 -0
- package/cli/vendor/shim/safe-bin/safe-delete-bash-env.sh +1 -1
- package/cli/vendor/shim/safe-bin/safe-delete-common.sh +95 -34
- package/cli/vendor/shim/safe-delete-broker-delete.cjs +166 -0
- package/cli/vendor/shim/shell-runtime-bash-env.sh +8 -0
- package/cli/vendor/shim/sitecustomize.py +551 -22
- package/cli/vendor/toybox-macos/LICENSE +12 -0
- package/cli/vendor/toybox-macos/toybox +0 -0
- package/cli/vendor/toybox-macos/toybox.sb +19 -0
- package/cli/vendor/zsh-macos/LICENSE +37 -0
- package/cli/vendor/zsh-macos/bin/zsh +0 -0
- package/package.json +1 -1
- package/cli/dist/web-ui/assets/index-BZjhFKbY.js +0 -1051
- package/cli/dist/web-ui/assets/index-C5EhSt3C.css +0 -32
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# genie-safe-delete bash environment — sourced via BASH_ENV for every bash subprocess.
|
|
2
|
-
# Defines
|
|
2
|
+
# Defines safe-bin wrappers to intercept shell file commands.
|
|
3
3
|
if [ -n "${CODEBUDDY_SAFE_DELETE_BIN_DIR:-}" ]; then
|
|
4
4
|
rm() { "${CODEBUDDY_SAFE_DELETE_BIN_DIR}/rm" "$@"; }
|
|
5
5
|
unlink() { "${CODEBUDDY_SAFE_DELETE_BIN_DIR}/unlink" "$@"; }
|
|
@@ -72,11 +72,6 @@ safe_delete_normalize_path() {
|
|
|
72
72
|
while [ "$p" != "/" ] && [ "${p%/}" != "$p" ]; do
|
|
73
73
|
p="${p%/}"
|
|
74
74
|
done
|
|
75
|
-
case "$OS" in
|
|
76
|
-
MINGW*|MSYS*|CYGWIN*)
|
|
77
|
-
p="$(printf '%s' "$p" | tr '[:upper:]' '[:lower:]')"
|
|
78
|
-
;;
|
|
79
|
-
esac
|
|
80
75
|
printf '%s' "$p"
|
|
81
76
|
}
|
|
82
77
|
|
|
@@ -148,17 +143,50 @@ SAFE_DELETE_OS_TMP_DIRS="$(safe_delete_build_os_tmp_dirs)"
|
|
|
148
143
|
safe_delete_is_under_os_tmp_dir() {
|
|
149
144
|
local abs
|
|
150
145
|
abs="$(safe_delete_normalize_path "$(safe_delete_abs_path "$1")")"
|
|
151
|
-
|
|
146
|
+
|
|
147
|
+
# 用数组分片而不是 heredoc/here-string 遍历 tmp 目录列表:heredoc 在 bash 内部
|
|
148
|
+
# 会落一个临时文件再 unlink(/tmp/sh-thd-*),在沙箱 broker 场景下这次 unlink
|
|
149
|
+
# 会被 Seatbelt 的 file-write-unlink 监控误判为一次“受保护文件修改”拦截,
|
|
150
|
+
# 抢在批量删除确认信号之前触发提权 UI。纯数组分片不产生任何文件系统操作。
|
|
151
|
+
local tmp_dir
|
|
152
|
+
local __sdiotd_old_ifs="$IFS"
|
|
153
|
+
IFS=$'\n'
|
|
154
|
+
set -f
|
|
155
|
+
local -a __sdiotd_tmp_dirs=($SAFE_DELETE_OS_TMP_DIRS)
|
|
156
|
+
set +f
|
|
157
|
+
IFS="$__sdiotd_old_ifs"
|
|
158
|
+
|
|
159
|
+
for tmp_dir in "${__sdiotd_tmp_dirs[@]}"; do
|
|
152
160
|
[ -n "$tmp_dir" ] || continue
|
|
161
|
+
case "$OS" in
|
|
162
|
+
MINGW*|MSYS*|CYGWIN*)
|
|
163
|
+
local abs_lower tmp_lower
|
|
164
|
+
abs_lower="$(printf '%s' "$abs" | tr '[:upper:]' '[:lower:]')"
|
|
165
|
+
tmp_lower="$(printf '%s' "$tmp_dir" | tr '[:upper:]' '[:lower:]')"
|
|
166
|
+
case "$abs_lower" in
|
|
167
|
+
"$tmp_lower"/*) return 0 ;;
|
|
168
|
+
esac
|
|
169
|
+
continue
|
|
170
|
+
;;
|
|
171
|
+
esac
|
|
153
172
|
case "$abs" in
|
|
154
173
|
"$tmp_dir"/*) return 0 ;;
|
|
155
174
|
esac
|
|
156
|
-
done
|
|
157
|
-
$SAFE_DELETE_OS_TMP_DIRS
|
|
158
|
-
EOF
|
|
175
|
+
done
|
|
159
176
|
return 1
|
|
160
177
|
}
|
|
161
178
|
|
|
179
|
+
safe_delete_bulk_guard_non_tmp_check() {
|
|
180
|
+
local targets=()
|
|
181
|
+
local p
|
|
182
|
+
for p in "$@"; do
|
|
183
|
+
safe_delete_is_under_os_tmp_dir "$p" && continue
|
|
184
|
+
targets+=("$p")
|
|
185
|
+
done
|
|
186
|
+
[ ${#targets[@]} -eq 0 ] && return 0
|
|
187
|
+
safe_delete_bulk_guard_check "${targets[@]}"
|
|
188
|
+
}
|
|
189
|
+
|
|
162
190
|
# ---- platform-specific trash helpers -----------------------------------------
|
|
163
191
|
|
|
164
192
|
trash_darwin() {
|
|
@@ -374,10 +402,57 @@ trash_one() {
|
|
|
374
402
|
esac
|
|
375
403
|
}
|
|
376
404
|
|
|
405
|
+
try_broker_delete() {
|
|
406
|
+
local abs="$1"
|
|
407
|
+
local recursive="${2:-false}"
|
|
408
|
+
local force="${3:-false}"
|
|
409
|
+
[ -n "${CODEBUDDY_SANDBOX_BROKER_IPC_ADDRESS:-}" ] || return 2
|
|
410
|
+
[ -n "${CODEBUDDY_SANDBOX_BROKER_SESSION_ID:-}" ] || return 2
|
|
411
|
+
[ -n "${CODEBUDDY_SANDBOX_HOST_FILE_OPERATION_COMMAND:-}" ] || return 2
|
|
412
|
+
|
|
413
|
+
local helper="${CODEBUDDY_SAFE_DELETE_BROKER_DELETE:-}"
|
|
414
|
+
local node_bin="${CODEBUDDY_NODE_BIN:-}"
|
|
415
|
+
[ -n "$helper" ] && [ -f "$helper" ] && [ -n "$node_bin" ] || return 2
|
|
416
|
+
|
|
417
|
+
local broker_out broker_rc
|
|
418
|
+
local broker_args=()
|
|
419
|
+
[ "$recursive" = "true" ] && broker_args+=("--recursive")
|
|
420
|
+
[ "$force" = "true" ] && broker_args+=("--force")
|
|
421
|
+
broker_out="$(
|
|
422
|
+
NODE_OPTIONS= "$node_bin" "$helper" "${broker_args[@]}" -- "$abs" 2>&1 >/dev/null
|
|
423
|
+
)"
|
|
424
|
+
broker_rc=$?
|
|
425
|
+
|
|
426
|
+
if [ $broker_rc -eq 0 ]; then
|
|
427
|
+
return 0
|
|
428
|
+
fi
|
|
429
|
+
if [ $broker_rc -eq 2 ]; then
|
|
430
|
+
_safe_delete_diag "broker unavailable, falling back to local trash: path=$abs"
|
|
431
|
+
return 2
|
|
432
|
+
fi
|
|
433
|
+
_safe_delete_diag "broker denied delete: path=$abs stderr=$(_safe_delete_one_line "$broker_out")"
|
|
434
|
+
return 1
|
|
435
|
+
}
|
|
436
|
+
|
|
377
437
|
try_trash() {
|
|
378
438
|
local p="$1"
|
|
439
|
+
local recursive="${2:-false}"
|
|
440
|
+
local force="${3:-false}"
|
|
379
441
|
local abs
|
|
380
442
|
abs="$(safe_delete_abs_path "$p")"
|
|
443
|
+
|
|
444
|
+
try_broker_delete "$abs" "$recursive" "$force"
|
|
445
|
+
local broker_rc=$?
|
|
446
|
+
if [ $broker_rc -eq 0 ]; then
|
|
447
|
+
return 0
|
|
448
|
+
fi
|
|
449
|
+
if [ $broker_rc -eq 1 ]; then
|
|
450
|
+
local target_json
|
|
451
|
+
target_json="$(safe_delete_json_string "$p")"
|
|
452
|
+
echo "[safe-delete][SAFE_DELETE_FAIL_CLOSED] {\"target\":$target_json,\"reason\":\"broker-denied\"}" >&2
|
|
453
|
+
return 1
|
|
454
|
+
fi
|
|
455
|
+
|
|
381
456
|
if trash_one "$p"; then
|
|
382
457
|
safe_delete_record_trash "$abs"
|
|
383
458
|
return 0
|
|
@@ -468,7 +543,9 @@ safe_delete_rm() {
|
|
|
468
543
|
_exit=1
|
|
469
544
|
fi
|
|
470
545
|
done
|
|
471
|
-
|
|
546
|
+
if ! safe_delete_bulk_guard_non_tmp_check "${trash_targets[@]}"; then
|
|
547
|
+
return 1
|
|
548
|
+
fi
|
|
472
549
|
for p in "${trash_targets[@]}"; do
|
|
473
550
|
if safe_delete_is_under_os_tmp_dir "$p"; then
|
|
474
551
|
local native_args=()
|
|
@@ -478,16 +555,7 @@ safe_delete_rm() {
|
|
|
478
555
|
if ! "$REAL_RM" "${native_args[@]}" -- "$p"; then
|
|
479
556
|
_exit=1
|
|
480
557
|
fi
|
|
481
|
-
|
|
482
|
-
guarded_targets+=("$p")
|
|
483
|
-
fi
|
|
484
|
-
done
|
|
485
|
-
|
|
486
|
-
if ! safe_delete_bulk_guard_check "${guarded_targets[@]}"; then
|
|
487
|
-
return 1
|
|
488
|
-
fi
|
|
489
|
-
for p in "${guarded_targets[@]}"; do
|
|
490
|
-
if ! try_trash "$p"; then
|
|
558
|
+
elif ! try_trash "$p" "$recursive" "$force"; then
|
|
491
559
|
_exit=1
|
|
492
560
|
fi
|
|
493
561
|
done
|
|
@@ -525,13 +593,13 @@ safe_delete_unlink() {
|
|
|
525
593
|
return 1
|
|
526
594
|
fi
|
|
527
595
|
|
|
596
|
+
if ! safe_delete_bulk_guard_non_tmp_check "$target"; then
|
|
597
|
+
return 1
|
|
598
|
+
fi
|
|
528
599
|
if safe_delete_is_under_os_tmp_dir "$target"; then
|
|
529
600
|
"$REAL_UNLINK" -- "$target"
|
|
530
601
|
return $?
|
|
531
602
|
fi
|
|
532
|
-
if ! safe_delete_bulk_guard_check "$target"; then
|
|
533
|
-
return 1
|
|
534
|
-
fi
|
|
535
603
|
|
|
536
604
|
try_trash "$target"
|
|
537
605
|
return $?
|
|
@@ -590,22 +658,15 @@ safe_delete_rmdir() {
|
|
|
590
658
|
fi
|
|
591
659
|
trash_targets+=("$p")
|
|
592
660
|
done
|
|
593
|
-
|
|
661
|
+
if ! safe_delete_bulk_guard_non_tmp_check "${trash_targets[@]}"; then
|
|
662
|
+
return 1
|
|
663
|
+
fi
|
|
594
664
|
for p in "${trash_targets[@]}"; do
|
|
595
665
|
if safe_delete_is_under_os_tmp_dir "$p"; then
|
|
596
666
|
if ! "$REAL_RMDIR" -- "$p"; then
|
|
597
667
|
_exit=1
|
|
598
668
|
fi
|
|
599
|
-
|
|
600
|
-
guarded_targets+=("$p")
|
|
601
|
-
fi
|
|
602
|
-
done
|
|
603
|
-
|
|
604
|
-
if ! safe_delete_bulk_guard_check "${guarded_targets[@]}"; then
|
|
605
|
-
return 1
|
|
606
|
-
fi
|
|
607
|
-
for p in "${guarded_targets[@]}"; do
|
|
608
|
-
if ! try_trash "$p"; then
|
|
669
|
+
elif ! try_trash "$p"; then
|
|
609
670
|
_exit=1
|
|
610
671
|
fi
|
|
611
672
|
done
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* safe-delete broker delete helper.
|
|
3
|
+
*
|
|
4
|
+
* Shared by bash safe-delete wrappers and the Node safe-delete shim.
|
|
5
|
+
* Delete-specific response classification stays here; broker-ipc-client.cjs
|
|
6
|
+
* only owns neutral JSON-line transport.
|
|
7
|
+
*
|
|
8
|
+
* CLI contract: `node safe-delete-broker-delete.cjs [--recursive] [--force] -- <path>`
|
|
9
|
+
* accepts exactly one target. Callers that need to delete multiple paths must
|
|
10
|
+
* loop and invoke once per path. Exit codes: 0 = ok, 1 = broker denied
|
|
11
|
+
* (fail-closed), 2 = unavailable.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
'use strict';
|
|
15
|
+
|
|
16
|
+
const path = require('path');
|
|
17
|
+
const brokerIpc = require('./broker-ipc-client.cjs');
|
|
18
|
+
|
|
19
|
+
let requestSeq = 0;
|
|
20
|
+
|
|
21
|
+
function buildDeleteRequest(targetPath, options = {}) {
|
|
22
|
+
const command = options.command || process.env.CODEBUDDY_SANDBOX_HOST_FILE_OPERATION_COMMAND;
|
|
23
|
+
const sessionId = options.sessionId || process.env.CODEBUDDY_SANDBOX_BROKER_SESSION_ID;
|
|
24
|
+
const toolCallId = options.toolCallId || process.env.CODEBUDDY_SANDBOX_BROKER_TOOL_CALL_ID;
|
|
25
|
+
const traceId = options.brokerTraceId || process.env.CODEBUDDY_SANDBOX_BROKER_TRACE_ID;
|
|
26
|
+
|
|
27
|
+
const request = {
|
|
28
|
+
id: `sd-${process.pid}-${++requestSeq}`,
|
|
29
|
+
runtime: options.runtime || 'bash',
|
|
30
|
+
command,
|
|
31
|
+
operation: 'delete',
|
|
32
|
+
path: path.resolve(targetPath),
|
|
33
|
+
deleteMode: 'trash',
|
|
34
|
+
sessionId,
|
|
35
|
+
};
|
|
36
|
+
if (options.recursive === true) { request.recursive = true; }
|
|
37
|
+
if (options.force === true) { request.force = true; }
|
|
38
|
+
if (toolCallId) { request.toolCallId = toolCallId; }
|
|
39
|
+
if (traceId) { request.brokerTraceId = traceId; }
|
|
40
|
+
return request;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function hasBrokerDeleteEnv(options = {}) {
|
|
44
|
+
return !!(
|
|
45
|
+
(options.socketPath || process.env.CODEBUDDY_SANDBOX_BROKER_IPC_ADDRESS)
|
|
46
|
+
&& (options.sessionId || process.env.CODEBUDDY_SANDBOX_BROKER_SESSION_ID)
|
|
47
|
+
&& (options.command || process.env.CODEBUDDY_SANDBOX_HOST_FILE_OPERATION_COMMAND)
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function classifyDeleteResult(response) {
|
|
52
|
+
if (response && response.ok === true) {
|
|
53
|
+
return 'ok';
|
|
54
|
+
}
|
|
55
|
+
if (response && response.decision === 'sandbox') {
|
|
56
|
+
return 'unavailable';
|
|
57
|
+
}
|
|
58
|
+
return 'denied';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function tryBrokerDeleteSync(absPath, options = {}) {
|
|
62
|
+
if (!hasBrokerDeleteEnv(options)) {
|
|
63
|
+
return 'unavailable';
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
return classifyDeleteResult(
|
|
67
|
+
brokerIpc.sendBrokerRequestSync(buildDeleteRequest(absPath, options), options),
|
|
68
|
+
);
|
|
69
|
+
} catch (_) {
|
|
70
|
+
return 'unavailable';
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function tryBrokerDeleteAsync(absPath, options = {}) {
|
|
75
|
+
if (!hasBrokerDeleteEnv(options)) {
|
|
76
|
+
return 'unavailable';
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
return classifyDeleteResult(
|
|
80
|
+
await brokerIpc.sendBrokerRequest(buildDeleteRequest(absPath, options), options),
|
|
81
|
+
);
|
|
82
|
+
} catch (_) {
|
|
83
|
+
return 'unavailable';
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function tryBrokerDelete(absPath, options = {}) {
|
|
88
|
+
if (options.sync === false) {
|
|
89
|
+
return tryBrokerDeleteAsync(absPath, options);
|
|
90
|
+
}
|
|
91
|
+
return tryBrokerDeleteSync(absPath, options);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function parseDeleteCliArgs(argv) {
|
|
95
|
+
const options = {
|
|
96
|
+
recursive: false,
|
|
97
|
+
force: false,
|
|
98
|
+
};
|
|
99
|
+
const targets = [];
|
|
100
|
+
let afterDashDash = false;
|
|
101
|
+
for (const arg of argv) {
|
|
102
|
+
if (!afterDashDash && arg === '--') {
|
|
103
|
+
afterDashDash = true;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (!afterDashDash && arg === '--recursive') {
|
|
107
|
+
options.recursive = true;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (!afterDashDash && arg === '--force') {
|
|
111
|
+
options.force = true;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (!afterDashDash && arg.startsWith('-')) {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
targets.push(arg);
|
|
118
|
+
}
|
|
119
|
+
if (targets.length !== 1) {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
target: targets[0],
|
|
124
|
+
options,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function runDeleteCli(argv = process.argv.slice(2)) {
|
|
129
|
+
const parsed = parseDeleteCliArgs(argv);
|
|
130
|
+
if (!parsed) {
|
|
131
|
+
process.stderr.write('[safe-delete-broker] expected exactly one target path\n');
|
|
132
|
+
return 2;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const result = await tryBrokerDelete(parsed.target, {
|
|
136
|
+
runtime: 'bash',
|
|
137
|
+
recursive: parsed.options.recursive,
|
|
138
|
+
force: parsed.options.force,
|
|
139
|
+
sync: false,
|
|
140
|
+
});
|
|
141
|
+
if (result === 'ok') {
|
|
142
|
+
return 0;
|
|
143
|
+
}
|
|
144
|
+
if (result === 'denied') {
|
|
145
|
+
process.stderr.write(`[safe-delete-broker] denied: path=${parsed.target}\n`);
|
|
146
|
+
return 1;
|
|
147
|
+
}
|
|
148
|
+
return 2;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
module.exports = {
|
|
152
|
+
buildDeleteRequest,
|
|
153
|
+
classifyDeleteResult,
|
|
154
|
+
tryBrokerDelete,
|
|
155
|
+
runDeleteCli,
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
if (require.main === module) {
|
|
159
|
+
runDeleteCli().then(
|
|
160
|
+
code => process.exit(code),
|
|
161
|
+
error => {
|
|
162
|
+
process.stderr.write(`[safe-delete-broker] unavailable: ${error && error.message ? error.message : error}\n`);
|
|
163
|
+
process.exit(2);
|
|
164
|
+
},
|
|
165
|
+
);
|
|
166
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# CodeBuddy bash runtime environment — sourced via BASH_ENV for bash subprocesses.
|
|
2
|
+
# Keep feature-specific bootstrap scripts separate and compose them here.
|
|
3
|
+
__codebuddy_shell_runtime_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
4
|
+
|
|
5
|
+
[ ! -f "${__codebuddy_shell_runtime_dir}/safe-bin/safe-delete-bash-env.sh" ] || . "${__codebuddy_shell_runtime_dir}/safe-bin/safe-delete-bash-env.sh"
|
|
6
|
+
[ ! -f "${__codebuddy_shell_runtime_dir}/brokered-sandbox-bash-env.sh" ] || . "${__codebuddy_shell_runtime_dir}/brokered-sandbox-bash-env.sh"
|
|
7
|
+
|
|
8
|
+
unset __codebuddy_shell_runtime_dir
|