@tencent-ai/agent-harness 0.2.0-beta.1 → 0.2.0-beta.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.
- package/CHANGELOG.md +44 -0
- package/README.md +1 -1
- package/cli/CHANGELOG.md +135 -0
- package/cli/dist-server/shared.cjs +455 -387
- package/cli/dist-server/types/node/acp/acp-protocol.d.ts +40 -12
- package/cli/dist-server/types/node/acp/usage-by-category-calculator.d.ts +21 -0
- package/cli/dist-server/types/node/bash-sandbox/bash-sandbox-protocol.d.ts +3 -0
- package/cli/dist-server/types/node/cli/cli-protocol.d.ts +3 -0
- package/cli/dist-server/types/node/cli/stream-json-protocol.d.ts +23 -2
- package/cli/dist-server/types/node/data-fs/index.d.ts +13 -1
- package/cli/dist-server/types/node/hooks/hook-protocol.d.ts +2 -2
- package/cli/dist-server/types/node/sensitive-content/sensitive-content-protocol.d.ts +7 -0
- package/cli/dist-server/types/node/server/boot.d.ts +7 -4
- package/{lib/components → cli/dist-server/types/node/server/formats}/acp/acp-error-model.d.ts +1 -1
- package/{lib/components → cli/dist-server/types/node/server/formats}/acp/acp-protocol.d.ts +2 -3
- package/cli/dist-server/types/node/server/formats/acp/index.d.ts +12 -0
- package/cli/dist-server/types/node/server/formats/acp/projection.d.ts +10 -0
- package/cli/dist-server/types/node/server/index.d.ts +1 -1
- package/cli/dist-server/types/node/server/sessions.d.ts +27 -2
- package/cli/dist-server/types/node/server/types.d.ts +65 -7
- package/cli/dist-server/types/node/settings/settings-protocol.d.ts +5 -0
- package/cli/dist-server/types/node/tools/tool-protocol.d.ts +128 -4
- package/cli/dist-server/types/vendor/cbc-core/node/agent/agent-protocol.d.ts +60 -2
- package/cli/dist-server/types/vendor/cbc-core/node/agent/agent-purpose-protocol.d.ts +8 -4
- package/cli/dist-server/types/vendor/cbc-core/node/agent/agent-purpose-scope.d.ts +46 -0
- package/cli/dist-server/types/vendor/cbc-core/node/agent/agent-service.d.ts +28 -3
- package/cli/dist-server/types/vendor/cbc-core/node/agent/index.d.ts +4 -0
- package/cli/dist-server/types/vendor/cbc-core/node/agent/interceptors/input-interceptors.d.ts +1 -6
- package/cli/dist-server/types/vendor/cbc-core/node/agent/model-call-failure.d.ts +9 -0
- package/cli/dist-server/types/vendor/cbc-core/node/agent/model-step-sequence.d.ts +11 -0
- package/cli/dist-server/types/vendor/cbc-core/node/agent/runner-factory.d.ts +56 -20
- package/cli/dist-server/types/vendor/cbc-core/node/agent/speaker-label.d.ts +44 -0
- package/cli/dist-server/types/vendor/cbc-core/node/agent/tool-call-loop-detector-service.d.ts +5 -4
- package/cli/dist-server/types/vendor/cbc-core/node/agent/tool-call-loop-guard-protocol.d.ts +1 -1
- package/cli/dist-server/types/vendor/cbc-core/node/agent/tool-call-loop-pattern.d.ts +16 -4
- package/cli/dist-server/types/vendor/cbc-core/node/context/compaction-lineage.d.ts +39 -0
- package/cli/dist-server/types/vendor/cbc-core/node/context/context-compact-summarizer.d.ts +2 -0
- package/cli/dist-server/types/vendor/cbc-core/node/context/context-protocol.d.ts +17 -0
- package/cli/dist-server/types/vendor/cbc-core/node/context/index.d.ts +1 -0
- package/cli/dist-server/types/vendor/cbc-core/node/context/pre-message-compact-strategy.d.ts +1 -2
- package/cli/dist-server/types/vendor/cbc-core/node/hooks/agent-trigger.d.ts +6 -22
- package/cli/dist-server/types/vendor/cbc-core/node/hooks/hook-protocol.d.ts +4 -1
- package/cli/dist-server/types/vendor/cbc-core/node/session/idle-queue-drain-service.d.ts +4 -56
- package/cli/dist-server/types/vendor/cbc-core/node/session/index.d.ts +4 -0
- package/cli/dist-server/types/vendor/cbc-core/node/session/interruption-service.d.ts +63 -9
- package/cli/dist-server/types/vendor/cbc-core/node/session/model-request-retry-phase.d.ts +16 -0
- package/cli/dist-server/types/vendor/cbc-core/node/session/model-response-interceptors.d.ts +33 -0
- package/cli/dist-server/types/vendor/cbc-core/node/session/recovery-budget.d.ts +55 -0
- package/cli/dist-server/types/vendor/cbc-core/node/session/session-hook-manager.d.ts +15 -0
- package/cli/dist-server/types/vendor/cbc-core/node/session/session-manager-host-protocol.d.ts +3 -2
- package/cli/dist-server/types/vendor/cbc-core/node/session/session-manager.d.ts +17 -4
- package/cli/dist-server/types/vendor/cbc-core/node/session/session-persistence-error.d.ts +43 -0
- package/cli/dist-server/types/vendor/cbc-core/node/session/session-protocol.d.ts +110 -9
- package/cli/dist-server/types/vendor/cbc-core/node/session/session-run-state-machine-protocol.d.ts +15 -1
- package/cli/dist-server/types/vendor/cbc-core/node/session/session-runtime-lifecycle.d.ts +5 -0
- package/cli/dist-server/types/vendor/cbc-core/node/session/session-store.d.ts +150 -4
- package/cli/dist-server/types/vendor/cbc-core/node/session/stream-timeout-retry-budget.d.ts +20 -1
- package/cli/dist-server/types/vendor/cbc-core/node/trace/turn-context.d.ts +28 -1
- package/cli/dist-server/types/vendor/cbc-core/node/utils/command-message-utils.d.ts +20 -0
- package/cli/dist-server/types/vendor/cbc-core/node/utils/history-utils.d.ts +27 -4
- package/cli/dist-server/types/vendor/cbc-core/node/utils/index.d.ts +1 -0
- package/cli/dist-server/types/vendor/cbc-core/node/utils/input-item-utils.d.ts +8 -0
- package/cli/dist-server/types/vendor/cbc-core/node/utils/message-utils.d.ts +12 -0
- package/cli/dist-server/types/vendor/cbc-core/node/utils/model-utils.d.ts +7 -0
- package/cli/dist-server/types/vendor/cbc-core/node/utils/queue-dispatch-utils.d.ts +24 -2
- package/cli/dist-server/types/vendor/cbc-core/node/utils/session-utils.d.ts +4 -1
- package/cli/dist-server/types/vendor/cbc-core/node/utils/string-retention-utils.d.ts +4 -0
- package/cli/dist-server/types/vendor/cbc-core/node/utils/token-utils.d.ts +3 -1
- package/cli/dist-server/types/vendor/cbc-shared/node/agent/openai-agents-types.d.ts +1 -0
- package/cli/dist-server/types/vendor/cbc-shared/node/checkpoint/checkpoint-types.d.ts +6 -0
- package/cli/dist-server/types/vendor/cbc-shared/node/hooks/hook-types.d.ts +7 -1
- package/cli/dist-server/types/vendor/cbc-shared/node/index.d.ts +2 -0
- package/cli/dist-server/types/vendor/cbc-shared/node/model/model-errors.d.ts +36 -4
- package/cli/dist-server/types/vendor/cbc-shared/node/tools/tool-names.d.ts +1 -0
- package/cli/dist-server/types/vendor/cbc-shared/node/utils/retry-backoff.d.ts +30 -0
- package/cli/dist-server/types/vendor/cbc-shared/node/utils/retry-policy.d.ts +26 -0
- package/cli/dist-server/types/workspace/agent-client-protocol/lib/common/index.d.ts +1 -0
- package/cli/dist-server/types/workspace/agent-client-protocol/lib/common/sandbox-rule-context.d.ts +38 -0
- package/cli/dist-server/types/workspace/authentication/lib/common/account-scoped-external-link-authentication-provider.d.ts +5 -5
- package/cli/dist-server/types/workspace/authentication/lib/common/account-utils.d.ts +25 -0
- package/cli/dist-server/types/workspace/authentication/lib/common/authentication-manager.d.ts +8 -2
- package/cli/dist-server/types/workspace/authentication/lib/common/authentication-observation.d.ts +36 -0
- package/cli/dist-server/types/workspace/authentication/lib/common/authentication-protocol.d.ts +40 -2
- package/cli/dist-server/types/workspace/authentication/lib/common/external-link-authentication-provider.d.ts +21 -5
- package/cli/dist-server/types/workspace/authentication/lib/common/index.d.ts +1 -0
- package/cli/dist-server/types/workspace/authentication/lib/common/wx-authentication-provider.d.ts +2 -2
- package/cli/dist-server/types/workspace/cbc-checkpoint/lib/node/checkpoint/checkpoint-protocol.d.ts +2 -0
- package/cli/dist-server/types/workspace/cbc-checkpoint/lib/node/checkpoint/checkpoint-service.d.ts +1 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/agent-protocol.d.ts +60 -2
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/agent-purpose-protocol.d.ts +8 -4
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/agent-purpose-scope.d.ts +46 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/agent-service.d.ts +28 -3
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/index.d.ts +4 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/interceptors/input-interceptors.d.ts +1 -6
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/model-call-failure.d.ts +9 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/model-step-sequence.d.ts +11 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/runner-factory.d.ts +56 -20
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/speaker-label.d.ts +44 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/tool-call-loop-detector-service.d.ts +5 -4
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/tool-call-loop-guard-protocol.d.ts +1 -1
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/tool-call-loop-pattern.d.ts +16 -4
- package/cli/dist-server/types/workspace/cbc-core/lib/node/context/compaction-lineage.d.ts +39 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/context/context-compact-summarizer.d.ts +2 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/context/context-protocol.d.ts +17 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/context/index.d.ts +1 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/context/pre-message-compact-strategy.d.ts +1 -2
- package/cli/dist-server/types/workspace/cbc-core/lib/node/hooks/agent-trigger.d.ts +6 -22
- package/cli/dist-server/types/workspace/cbc-core/lib/node/hooks/hook-protocol.d.ts +4 -1
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/idle-queue-drain-service.d.ts +4 -56
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/index.d.ts +4 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/interruption-service.d.ts +63 -9
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/model-request-retry-phase.d.ts +16 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/model-response-interceptors.d.ts +33 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/recovery-budget.d.ts +55 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-hook-manager.d.ts +15 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-manager-host-protocol.d.ts +3 -2
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-manager.d.ts +17 -4
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-persistence-error.d.ts +43 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-protocol.d.ts +110 -9
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-run-state-machine-protocol.d.ts +15 -1
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-runtime-lifecycle.d.ts +5 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-store.d.ts +150 -4
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/stream-timeout-retry-budget.d.ts +20 -1
- package/cli/dist-server/types/workspace/cbc-core/lib/node/trace/turn-context.d.ts +28 -1
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/command-message-utils.d.ts +20 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/history-utils.d.ts +27 -4
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/index.d.ts +1 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/input-item-utils.d.ts +8 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/message-utils.d.ts +12 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/model-utils.d.ts +7 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/queue-dispatch-utils.d.ts +24 -2
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/session-utils.d.ts +4 -1
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/string-retention-utils.d.ts +4 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/token-utils.d.ts +3 -1
- package/cli/dist-server/types/workspace/cbc-shared/lib/node/agent/openai-agents-types.d.ts +1 -0
- package/cli/dist-server/types/workspace/cbc-shared/lib/node/checkpoint/checkpoint-types.d.ts +6 -0
- package/cli/dist-server/types/workspace/cbc-shared/lib/node/hooks/hook-types.d.ts +7 -1
- package/cli/dist-server/types/workspace/cbc-shared/lib/node/index.d.ts +2 -0
- package/cli/dist-server/types/workspace/cbc-shared/lib/node/model/model-errors.d.ts +36 -4
- package/cli/dist-server/types/workspace/cbc-shared/lib/node/tools/tool-names.d.ts +1 -0
- package/cli/dist-server/types/workspace/cbc-shared/lib/node/utils/retry-backoff.d.ts +30 -0
- package/cli/dist-server/types/workspace/cbc-shared/lib/node/utils/retry-policy.d.ts +26 -0
- package/cli/dist-server/types/workspace/cbc-workflow/lib/node/workflow/workflow-execution.d.ts +14 -1
- package/cli/dist-server/types/workspace/cbc-workflow/lib/node/workflow/workflow-manager.d.ts +7 -0
- package/cli/dist-server/types/workspace/cbc-worktree/lib/node/worktree/worktree-service.d.ts +5 -0
- package/cli/dist-server/types/workspace/cbc-worktree/lib/node/worktree/worktree-session.d.ts +3 -0
- package/cli/dist-server/types/workspace/core/lib/common/protocol.d.ts +8 -1
- package/cli/dist-server/types/workspace/product/lib/common/cloud-product-provider.d.ts +9 -0
- package/cli/dist-server/types/workspace/product/lib/common/index.d.ts +2 -0
- package/cli/dist-server/types/workspace/product/lib/common/pick-market-skill-id.d.ts +13 -0
- package/cli/dist-server/types/workspace/product/lib/common/tencent-docs-endpoint.d.ts +37 -0
- package/cli/dist-server/types/workspace/product/lib/common/tool-control-catalog.d.ts +2 -2
- package/cli/dist-server/types/workspace/product/lib/common/types/config.d.ts +12 -0
- package/cli/dist-server/types/workspace/product/lib/common/types/features.d.ts +63 -11
- package/cli/dist-server/types/workspace/product/lib/common/types/language-model.d.ts +66 -0
- package/cli/dist-server/types/workspace/product/lib/common/types/product.d.ts +22 -1
- package/cli/dist-server/types/workspace/sandbox-cli/lib/common/backup-policy.d.ts +10 -1
- package/cli/dist-server/types/workspace/sandbox-cli/lib/common/center-protocol.generated.d.ts +375 -4
- package/cli/dist-server/types/workspace/sandbox-cli/lib/common/file-policy.d.ts +5 -2
- package/cli/dist-server/types/workspace/sandbox-cli/lib/common/http-policy.d.ts +20 -0
- package/cli/dist-server/types/workspace/sandbox-cli/lib/common/rule-config.d.ts +10 -0
- package/cli/dist-server/types/workspace/sandbox-cli/lib/node/sandbox-center-client.d.ts +219 -0
- package/cli/dist-server/types/workspace/telemetry/lib/common/event/types/craft.d.ts +43 -3
- package/cli/package.json +1 -1
- package/cli/product.cloudhosted.json +4 -4
- package/cli/product.internal.json +268 -45
- package/cli/product.ioa.json +354 -161
- package/cli/product.json +338 -352
- package/cli/product.selfhosted.json +2 -2
- package/cli/vendor/shim/brokered-bin/7z +675 -0
- package/cli/vendor/shim/brokered-bin/7za +675 -0
- package/cli/vendor/shim/brokered-bin/7zz +675 -0
- package/cli/vendor/shim/brokered-bin/rar +675 -0
- package/cli/vendor/shim/brokered-bin/tar +675 -0
- package/cli/vendor/shim/brokered-bin/zip +187 -0
- package/docs/README.md +1 -0
- package/docs/in-process.md +42 -2
- package/docs/protocol.md +7 -1
- package/docs/server.md +2 -0
- package/lib/agent/v2.js +1 -1
- package/lib/application/services.d.ts +3 -1
- package/lib/application/services.js +1 -1
- package/lib/client/client.js +1 -1
- package/lib/client/mcp.d.ts +1 -1
- package/lib/client/mcp.js +1 -1
- package/lib/components/acp-mcp-transport.d.mts +84 -1
- package/lib/components/question-elicitation.d.mts +20 -1
- package/lib/components/sandbox-center.d.mts +2 -0
- package/lib/components/sandbox-center.mjs +1 -0
- package/lib/components/{acp/acp-prompt-input.d.ts → session/prompt-input.d.ts} +1 -1
- package/lib/components/session-config.d.mts +2 -0
- package/lib/components/session-config.mjs +1 -1
- package/lib/components/session-replay.d.mts +6 -7
- package/lib/components/session-replay.mjs +1 -1
- package/lib/effect-runtime/mcp-lifecycle.mjs +1 -1
- package/lib/harness/create-harness.js +1 -1
- package/lib/harness/runtime.js +1 -1
- package/lib/harness/types.d.ts +3 -0
- package/lib/integration/agent-integration.d.ts +5 -0
- package/lib/integration/executor-supervisor.js +1 -1
- package/lib/public.d.ts +1 -0
- package/lib/runtime/private-runtime-role.js +1 -1
- package/lib/runtime/sandbox-center.d.ts +21 -0
- package/lib/runtime/sandbox-center.js +1 -0
- package/lib/server/public.d.ts +1 -0
- package/lib/session/agent-backend.d.ts +5 -0
- package/lib/session/agent-backend.js +1 -1
- package/lib/session/config-defaults.d.ts +4 -0
- package/lib/session/config-defaults.js +1 -0
- package/lib/session/config-store.d.ts +1 -1
- package/lib/session/config-store.js +1 -1
- package/lib/session/local-fs.js +1 -1
- package/lib/session/replay.d.ts +2 -2
- package/lib/session/replay.js +1 -1
- package/lib/session/server-config.d.ts +11 -2
- package/lib/session/server-config.js +1 -1
- package/lib/session/server-events.d.ts +10 -8
- package/lib/session/server-events.js +1 -1
- package/lib/session/server-interactions.js +1 -1
- package/lib/session/server-mcp.js +1 -1
- package/package.json +27 -16
- package/lib/components/acp/acp-client-channel.d.ts +0 -36
- package/lib/components/acp/acp-mcp-transport.d.ts +0 -84
- package/lib/components/acp/acp-question-elicitation.d.ts +0 -20
- package/lib/session/local-options.d.ts +0 -50
- package/lib/session/local-options.js +0 -1
|
@@ -0,0 +1,675 @@
|
|
|
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
|
+
if [ "${CODEBUDDY_SAFE_DELETE_ENABLED:-1}" = "0" ]; then
|
|
65
|
+
case "$__cb_app" in
|
|
66
|
+
rm|rmdir|unlink) __cb_fallback "$@"; exit $? ;;
|
|
67
|
+
esac
|
|
68
|
+
fi
|
|
69
|
+
|
|
70
|
+
__cb_prebackup_path() {
|
|
71
|
+
[ -n "${1:-}" ] || return 0
|
|
72
|
+
[ "$1" != "-" ] || return 0
|
|
73
|
+
[ -n "${CODEBUDDY_SANDBOX_BROKER_IPC_ADDRESS:-}" ] || return 0
|
|
74
|
+
[ -n "${CODEBUDDY_SANDBOX_BROKER_SESSION_ID:-}" ] || return 0
|
|
75
|
+
[ -n "${CODEBUDDY_SANDBOX_FILE_TOKEN_OPERATION_COMMAND:-}" ] || return 0
|
|
76
|
+
[ -f "$__cb_broker_client" ] || return 0
|
|
77
|
+
|
|
78
|
+
__cb_run_node - "$__cb_broker_client" "$1" <<'NODE'
|
|
79
|
+
const path = require('path');
|
|
80
|
+
const { sendBrokerRequestSync } = require(process.argv[2]);
|
|
81
|
+
const response = sendBrokerRequestSync({
|
|
82
|
+
command: process.env.CODEBUDDY_SANDBOX_FILE_TOKEN_OPERATION_COMMAND,
|
|
83
|
+
operation: 'write',
|
|
84
|
+
path: path.resolve(process.argv[3]),
|
|
85
|
+
sessionId: process.env.CODEBUDDY_SANDBOX_BROKER_SESSION_ID,
|
|
86
|
+
toolCallId: process.env.CODEBUDDY_SANDBOX_BROKER_TOOL_CALL_ID,
|
|
87
|
+
brokerTraceId: process.env.CODEBUDDY_SANDBOX_BROKER_TRACE_ID,
|
|
88
|
+
runtime: 'toybox-dispatch',
|
|
89
|
+
});
|
|
90
|
+
if (response && (response.ok === true || response.decision === 'sandbox')) {
|
|
91
|
+
process.exit(0);
|
|
92
|
+
}
|
|
93
|
+
process.stderr.write(response && response.error ? response.error : 'Brokered write preflight denied');
|
|
94
|
+
process.exit(13);
|
|
95
|
+
NODE
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
__cb_prebackup_tree() {
|
|
99
|
+
[ -n "${1:-}" ] || return 0
|
|
100
|
+
[ -d "$1" ] || return 0
|
|
101
|
+
[ -n "${CODEBUDDY_SANDBOX_BROKER_IPC_ADDRESS:-}" ] || return 0
|
|
102
|
+
[ -n "${CODEBUDDY_SANDBOX_BROKER_SESSION_ID:-}" ] || return 0
|
|
103
|
+
[ -n "${CODEBUDDY_SANDBOX_FILE_TOKEN_OPERATION_COMMAND:-}" ] || return 0
|
|
104
|
+
[ -f "$__cb_broker_client" ] || return 0
|
|
105
|
+
|
|
106
|
+
__cb_run_node - "$__cb_broker_client" "$1" <<'NODE'
|
|
107
|
+
const fs = require('fs');
|
|
108
|
+
const path = require('path');
|
|
109
|
+
const { sendBrokerRequestSync } = require(process.argv[2]);
|
|
110
|
+
|
|
111
|
+
function prebackupFile(filePath) {
|
|
112
|
+
const response = sendBrokerRequestSync({
|
|
113
|
+
command: process.env.CODEBUDDY_SANDBOX_FILE_TOKEN_OPERATION_COMMAND,
|
|
114
|
+
operation: 'write',
|
|
115
|
+
path: path.resolve(filePath),
|
|
116
|
+
sessionId: process.env.CODEBUDDY_SANDBOX_BROKER_SESSION_ID,
|
|
117
|
+
toolCallId: process.env.CODEBUDDY_SANDBOX_BROKER_TOOL_CALL_ID,
|
|
118
|
+
brokerTraceId: process.env.CODEBUDDY_SANDBOX_BROKER_TRACE_ID,
|
|
119
|
+
runtime: 'toybox-dispatch',
|
|
120
|
+
});
|
|
121
|
+
if (response && (response.ok === true || response.decision === 'sandbox')) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
process.stderr.write(response && response.error ? response.error : 'Brokered write preflight denied');
|
|
125
|
+
process.exit(13);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function walk(dir) {
|
|
129
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
130
|
+
const entryPath = path.join(dir, entry.name);
|
|
131
|
+
if (entry.isDirectory()) {
|
|
132
|
+
walk(entryPath);
|
|
133
|
+
} else if (entry.isFile()) {
|
|
134
|
+
prebackupFile(entryPath);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
walk(process.argv[3]);
|
|
140
|
+
NODE
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
__cb_prebackup_tree_or_file() {
|
|
144
|
+
if [ -f "$1" ]; then
|
|
145
|
+
__cb_prebackup_path "$1"
|
|
146
|
+
return $?
|
|
147
|
+
fi
|
|
148
|
+
if [ -d "$1" ]; then
|
|
149
|
+
__cb_prebackup_tree "$1"
|
|
150
|
+
return $?
|
|
151
|
+
fi
|
|
152
|
+
__cb_prebackup_path "$1"
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
__cb_prebackup_truncate() {
|
|
156
|
+
__cb_after_options=
|
|
157
|
+
__cb_skip_next=
|
|
158
|
+
for __cb_arg in "$@"; do
|
|
159
|
+
if [ -n "$__cb_skip_next" ]; then __cb_skip_next=; continue; fi
|
|
160
|
+
if [ -n "$__cb_after_options" ]; then __cb_prebackup_path "$__cb_arg" || return $?; continue; fi
|
|
161
|
+
case "$__cb_arg" in
|
|
162
|
+
--) __cb_after_options=1 ;;
|
|
163
|
+
-s|--size) __cb_skip_next=1 ;;
|
|
164
|
+
--size=*) ;;
|
|
165
|
+
-*) ;;
|
|
166
|
+
*) __cb_prebackup_path "$__cb_arg" || return $? ;;
|
|
167
|
+
esac
|
|
168
|
+
done
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
__cb_prebackup_dd() {
|
|
172
|
+
for __cb_arg in "$@"; do
|
|
173
|
+
case "$__cb_arg" in
|
|
174
|
+
of=*) __cb_prebackup_path "${__cb_arg#of=}" || return $? ;;
|
|
175
|
+
esac
|
|
176
|
+
done
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
__cb_prebackup_tee() {
|
|
180
|
+
__cb_after_options=
|
|
181
|
+
for __cb_arg in "$@"; do
|
|
182
|
+
if [ -n "$__cb_after_options" ]; then __cb_prebackup_path "$__cb_arg" || return $?; continue; fi
|
|
183
|
+
case "$__cb_arg" in
|
|
184
|
+
--) __cb_after_options=1 ;;
|
|
185
|
+
-*) ;;
|
|
186
|
+
*) __cb_prebackup_path "$__cb_arg" || return $? ;;
|
|
187
|
+
esac
|
|
188
|
+
done
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
__cb_prebackup_touch() {
|
|
192
|
+
__cb_needs_prebackup=
|
|
193
|
+
__cb_after_options=
|
|
194
|
+
__cb_skip_next=
|
|
195
|
+
for __cb_arg in "$@"; do
|
|
196
|
+
if [ -n "$__cb_skip_next" ]; then __cb_skip_next=; continue; fi
|
|
197
|
+
if [ -n "$__cb_after_options" ]; then continue; fi
|
|
198
|
+
case "$__cb_arg" in
|
|
199
|
+
--) __cb_after_options=1 ;;
|
|
200
|
+
-d|--date|-r|--reference|-t|--time) __cb_skip_next=1; __cb_needs_prebackup=1 ;;
|
|
201
|
+
--date=*|--reference=*|--time=*|-*) __cb_needs_prebackup=1 ;;
|
|
202
|
+
esac
|
|
203
|
+
done
|
|
204
|
+
[ -n "$__cb_needs_prebackup" ] || return 0
|
|
205
|
+
|
|
206
|
+
__cb_after_options=
|
|
207
|
+
__cb_skip_next=
|
|
208
|
+
for __cb_arg in "$@"; do
|
|
209
|
+
if [ -n "$__cb_skip_next" ]; then __cb_skip_next=; continue; fi
|
|
210
|
+
if [ -n "$__cb_after_options" ]; then __cb_prebackup_path "$__cb_arg" || return $?; continue; fi
|
|
211
|
+
case "$__cb_arg" in
|
|
212
|
+
--) __cb_after_options=1 ;;
|
|
213
|
+
-d|--date|-r|--reference|-t|--time) __cb_skip_next=1 ;;
|
|
214
|
+
--date=*|--reference=*|--time=*|-*) ;;
|
|
215
|
+
*) __cb_prebackup_path "$__cb_arg" || return $? ;;
|
|
216
|
+
esac
|
|
217
|
+
done
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
__cb_prebackup_mkdir() {
|
|
221
|
+
__cb_needs_prebackup=
|
|
222
|
+
__cb_operand_count=0
|
|
223
|
+
__cb_after_options=
|
|
224
|
+
__cb_skip_next=
|
|
225
|
+
for __cb_arg in "$@"; do
|
|
226
|
+
if [ -n "$__cb_skip_next" ]; then __cb_skip_next=; continue; fi
|
|
227
|
+
if [ -n "$__cb_after_options" ]; then __cb_operand_count=$((__cb_operand_count + 1)); continue; fi
|
|
228
|
+
case "$__cb_arg" in
|
|
229
|
+
--) __cb_after_options=1 ;;
|
|
230
|
+
-p|--parents) ;;
|
|
231
|
+
-m|--mode) __cb_skip_next=1; __cb_needs_prebackup=1 ;;
|
|
232
|
+
--mode=*|-) __cb_needs_prebackup=1 ;;
|
|
233
|
+
-*) __cb_needs_prebackup=1 ;;
|
|
234
|
+
*) __cb_operand_count=$((__cb_operand_count + 1)) ;;
|
|
235
|
+
esac
|
|
236
|
+
done
|
|
237
|
+
[ "$__cb_operand_count" -gt 1 ] && __cb_needs_prebackup=1
|
|
238
|
+
[ -n "$__cb_needs_prebackup" ] || return 0
|
|
239
|
+
|
|
240
|
+
__cb_after_options=
|
|
241
|
+
__cb_skip_next=
|
|
242
|
+
for __cb_arg in "$@"; do
|
|
243
|
+
if [ -n "$__cb_skip_next" ]; then __cb_skip_next=; continue; fi
|
|
244
|
+
if [ -n "$__cb_after_options" ]; then __cb_prebackup_path "$__cb_arg" || return $?; continue; fi
|
|
245
|
+
case "$__cb_arg" in
|
|
246
|
+
--) __cb_after_options=1 ;;
|
|
247
|
+
-m|--mode) __cb_skip_next=1 ;;
|
|
248
|
+
--mode=*|-p|--parents|-) ;;
|
|
249
|
+
-*) ;;
|
|
250
|
+
*) __cb_prebackup_path "$__cb_arg" || return $? ;;
|
|
251
|
+
esac
|
|
252
|
+
done
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
__cb_prebackup_mv() {
|
|
256
|
+
__cb_needs_prebackup=
|
|
257
|
+
__cb_operand_count=0
|
|
258
|
+
__cb_after_options=
|
|
259
|
+
__cb_skip_next=
|
|
260
|
+
for __cb_arg in "$@"; do
|
|
261
|
+
if [ "$__cb_skip_next" = "target-dir" ]; then __cb_skip_next=; continue; fi
|
|
262
|
+
if [ -n "$__cb_after_options" ]; then __cb_operand_count=$((__cb_operand_count + 1)); continue; fi
|
|
263
|
+
case "$__cb_arg" in
|
|
264
|
+
--) __cb_after_options=1 ;;
|
|
265
|
+
-t|--target-directory) __cb_skip_next=target-dir; __cb_needs_prebackup=1 ;;
|
|
266
|
+
--target-directory=*) __cb_needs_prebackup=1 ;;
|
|
267
|
+
-*) __cb_needs_prebackup=1 ;;
|
|
268
|
+
*) __cb_operand_count=$((__cb_operand_count + 1)) ;;
|
|
269
|
+
esac
|
|
270
|
+
done
|
|
271
|
+
[ "$__cb_operand_count" -gt 2 ] && __cb_needs_prebackup=1
|
|
272
|
+
[ -n "$__cb_needs_prebackup" ] || return 0
|
|
273
|
+
|
|
274
|
+
# Rename mutates both the source entry and the destination entry. Preflight
|
|
275
|
+
# sources separately, then reuse cp's destination resolution for directories.
|
|
276
|
+
__cb_mv_target_dir=
|
|
277
|
+
__cb_after_options=
|
|
278
|
+
__cb_skip_next=
|
|
279
|
+
for __cb_arg in "$@"; do
|
|
280
|
+
if [ "$__cb_skip_next" = "target-dir" ]; then __cb_mv_target_dir="$__cb_arg"; __cb_skip_next=; continue; fi
|
|
281
|
+
if [ -n "$__cb_after_options" ]; then continue; fi
|
|
282
|
+
case "$__cb_arg" in
|
|
283
|
+
--) __cb_after_options=1 ;;
|
|
284
|
+
-t|--target-directory) __cb_skip_next=target-dir ;;
|
|
285
|
+
--target-directory=*) __cb_mv_target_dir="${__cb_arg#*=}" ;;
|
|
286
|
+
esac
|
|
287
|
+
done
|
|
288
|
+
|
|
289
|
+
__cb_mv_index=0
|
|
290
|
+
__cb_after_options=
|
|
291
|
+
__cb_skip_next=
|
|
292
|
+
for __cb_arg in "$@"; do
|
|
293
|
+
if [ "$__cb_skip_next" = "target-dir" ]; then __cb_skip_next=; continue; fi
|
|
294
|
+
if [ -n "$__cb_after_options" ]; then
|
|
295
|
+
__cb_mv_index=$((__cb_mv_index + 1))
|
|
296
|
+
if [ -n "$__cb_mv_target_dir" ] || [ "$__cb_mv_index" -lt "$__cb_operand_count" ]; then
|
|
297
|
+
__cb_prebackup_path "$__cb_arg" || return $?
|
|
298
|
+
fi
|
|
299
|
+
continue
|
|
300
|
+
fi
|
|
301
|
+
case "$__cb_arg" in
|
|
302
|
+
--) __cb_after_options=1 ;;
|
|
303
|
+
-t|--target-directory) __cb_skip_next=target-dir ;;
|
|
304
|
+
--target-directory=*|-*) ;;
|
|
305
|
+
*)
|
|
306
|
+
__cb_mv_index=$((__cb_mv_index + 1))
|
|
307
|
+
if [ -n "$__cb_mv_target_dir" ] || [ "$__cb_mv_index" -lt "$__cb_operand_count" ]; then
|
|
308
|
+
__cb_prebackup_path "$__cb_arg" || return $?
|
|
309
|
+
fi
|
|
310
|
+
;;
|
|
311
|
+
esac
|
|
312
|
+
done
|
|
313
|
+
__cb_prebackup_cp "$@"
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
__cb_prebackup_last_operand() {
|
|
317
|
+
__cb_after_options=
|
|
318
|
+
__cb_last=
|
|
319
|
+
for __cb_arg in "$@"; do
|
|
320
|
+
if [ -n "$__cb_after_options" ]; then __cb_last="$__cb_arg"; continue; fi
|
|
321
|
+
case "$__cb_arg" in
|
|
322
|
+
--) __cb_after_options=1 ;;
|
|
323
|
+
-*) ;;
|
|
324
|
+
*) __cb_last="$__cb_arg" ;;
|
|
325
|
+
esac
|
|
326
|
+
done
|
|
327
|
+
[ -z "$__cb_last" ] || __cb_prebackup_tree_or_file "$__cb_last"
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
__cb_cp_target_for_source() {
|
|
331
|
+
__cb_src="$1"
|
|
332
|
+
__cb_dest="$2"
|
|
333
|
+
if [ -d "$__cb_dest" ] && [ -z "${__cb_cp_no_target_dir:-}" ]; then
|
|
334
|
+
__cb_base="${__cb_src%/}"
|
|
335
|
+
__cb_base="${__cb_base##*/}"
|
|
336
|
+
[ -z "$__cb_base" ] || __cb_prebackup_tree_or_file "$__cb_dest/$__cb_base"
|
|
337
|
+
return $?
|
|
338
|
+
fi
|
|
339
|
+
__cb_prebackup_tree_or_file "$__cb_dest"
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
__cb_prebackup_cp() {
|
|
343
|
+
__cb_after_options=
|
|
344
|
+
__cb_skip_next=
|
|
345
|
+
__cb_cp_no_target_dir=
|
|
346
|
+
__cb_cp_target_dir=
|
|
347
|
+
__cb_cp_count=0
|
|
348
|
+
__cb_cp_dest=
|
|
349
|
+
for __cb_arg in "$@"; do
|
|
350
|
+
if [ "$__cb_skip_next" = "target-dir" ]; then __cb_cp_target_dir="$__cb_arg"; __cb_skip_next=; continue; fi
|
|
351
|
+
if [ -n "$__cb_after_options" ]; then __cb_cp_count=$((__cb_cp_count + 1)); __cb_cp_dest="$__cb_arg"; continue; fi
|
|
352
|
+
case "$__cb_arg" in
|
|
353
|
+
--) __cb_after_options=1 ;;
|
|
354
|
+
-t|--target-directory) __cb_skip_next=target-dir ;;
|
|
355
|
+
--target-directory=*) __cb_cp_target_dir="${__cb_arg#*=}" ;;
|
|
356
|
+
-T|--no-target-directory) __cb_cp_no_target_dir=1 ;;
|
|
357
|
+
-*) ;;
|
|
358
|
+
*) __cb_cp_count=$((__cb_cp_count + 1)); __cb_cp_dest="$__cb_arg" ;;
|
|
359
|
+
esac
|
|
360
|
+
done
|
|
361
|
+
|
|
362
|
+
if [ -n "$__cb_cp_target_dir" ]; then
|
|
363
|
+
__cb_after_options=
|
|
364
|
+
__cb_skip_next=
|
|
365
|
+
for __cb_arg in "$@"; do
|
|
366
|
+
if [ "$__cb_skip_next" = "target-dir" ]; then __cb_skip_next=; continue; fi
|
|
367
|
+
if [ -n "$__cb_after_options" ]; then __cb_cp_target_for_source "$__cb_arg" "$__cb_cp_target_dir" || return $?; continue; fi
|
|
368
|
+
case "$__cb_arg" in
|
|
369
|
+
--) __cb_after_options=1 ;;
|
|
370
|
+
-t|--target-directory) __cb_skip_next=target-dir ;;
|
|
371
|
+
--target-directory=*|-T|--no-target-directory|-*) ;;
|
|
372
|
+
*) __cb_cp_target_for_source "$__cb_arg" "$__cb_cp_target_dir" || return $? ;;
|
|
373
|
+
esac
|
|
374
|
+
done
|
|
375
|
+
return 0
|
|
376
|
+
fi
|
|
377
|
+
|
|
378
|
+
[ "$__cb_cp_count" -ge 2 ] || return 0
|
|
379
|
+
__cb_after_options=
|
|
380
|
+
__cb_index=0
|
|
381
|
+
for __cb_arg in "$@"; do
|
|
382
|
+
if [ -n "$__cb_after_options" ]; then
|
|
383
|
+
__cb_index=$((__cb_index + 1))
|
|
384
|
+
[ "$__cb_index" -ge "$__cb_cp_count" ] || __cb_cp_target_for_source "$__cb_arg" "$__cb_cp_dest" || return $?
|
|
385
|
+
continue
|
|
386
|
+
fi
|
|
387
|
+
case "$__cb_arg" in
|
|
388
|
+
--) __cb_after_options=1 ;;
|
|
389
|
+
-t|--target-directory) __cb_skip_next=target-dir ;;
|
|
390
|
+
--target-directory=*|-T|--no-target-directory|-*) ;;
|
|
391
|
+
*)
|
|
392
|
+
__cb_index=$((__cb_index + 1))
|
|
393
|
+
[ "$__cb_index" -ge "$__cb_cp_count" ] || __cb_cp_target_for_source "$__cb_arg" "$__cb_cp_dest" || return $?
|
|
394
|
+
;;
|
|
395
|
+
esac
|
|
396
|
+
done
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
__cb_prebackup_targets() {
|
|
400
|
+
case "$__cb_app" in
|
|
401
|
+
truncate) __cb_prebackup_truncate "$@" ;;
|
|
402
|
+
tee) __cb_prebackup_tee "$@" ;;
|
|
403
|
+
cp) __cb_prebackup_cp "$@" ;;
|
|
404
|
+
dd) __cb_prebackup_dd "$@" ;;
|
|
405
|
+
touch) __cb_prebackup_touch "$@" ;;
|
|
406
|
+
mkdir) __cb_prebackup_mkdir "$@" ;;
|
|
407
|
+
mv) __cb_prebackup_mv "$@" ;;
|
|
408
|
+
esac
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
__cb_host_op_ln() {
|
|
412
|
+
[ "$__cb_app" = "ln" ] || return 125
|
|
413
|
+
__cb_has_host_op_env || return 125
|
|
414
|
+
|
|
415
|
+
# Only simple ln [-s] SRC DEST is dispatched; other flags fall back to toybox.
|
|
416
|
+
__cb_run_node - "$__cb_broker_client" "$@" <<'NODE'
|
|
417
|
+
const fs = require('fs');
|
|
418
|
+
const path = require('path');
|
|
419
|
+
const { sendBrokerRequestSync } = require(process.argv[2]);
|
|
420
|
+
|
|
421
|
+
const args = process.argv.slice(3);
|
|
422
|
+
let symbolic = false;
|
|
423
|
+
let afterOptions = false;
|
|
424
|
+
const operands = [];
|
|
425
|
+
|
|
426
|
+
for (const arg of args) {
|
|
427
|
+
if (afterOptions) {
|
|
428
|
+
operands.push(arg);
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
if (arg === '--') {
|
|
432
|
+
afterOptions = true;
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
if (arg === '-s' || arg === '--symbolic') {
|
|
436
|
+
symbolic = true;
|
|
437
|
+
continue;
|
|
438
|
+
}
|
|
439
|
+
if (arg.startsWith('-')) {
|
|
440
|
+
process.exit(125);
|
|
441
|
+
}
|
|
442
|
+
operands.push(arg);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
if (operands.length !== 2) {
|
|
446
|
+
process.exit(125);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
const [fromArg, toArg] = operands;
|
|
450
|
+
const toPath = path.resolve(process.cwd(), toArg);
|
|
451
|
+
const fromPath = symbolic ? fromArg : path.resolve(process.cwd(), fromArg);
|
|
452
|
+
let linkPath = toPath;
|
|
453
|
+
try {
|
|
454
|
+
if (fs.statSync(toPath).isDirectory()) {
|
|
455
|
+
linkPath = path.join(toPath, path.basename(fromArg));
|
|
456
|
+
}
|
|
457
|
+
} catch {
|
|
458
|
+
linkPath = toPath;
|
|
459
|
+
}
|
|
460
|
+
const response = sendBrokerRequestSync({
|
|
461
|
+
command: process.env.CODEBUDDY_SANDBOX_HOST_FILE_OPERATION_COMMAND,
|
|
462
|
+
operation: 'link',
|
|
463
|
+
from: fromPath,
|
|
464
|
+
to: linkPath,
|
|
465
|
+
symbolic,
|
|
466
|
+
sessionId: process.env.CODEBUDDY_SANDBOX_BROKER_SESSION_ID,
|
|
467
|
+
toolCallId: process.env.CODEBUDDY_SANDBOX_BROKER_TOOL_CALL_ID,
|
|
468
|
+
brokerTraceId: process.env.CODEBUDDY_SANDBOX_BROKER_TRACE_ID,
|
|
469
|
+
runtime: 'toybox-dispatch',
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
if (response && response.ok === true) {
|
|
473
|
+
process.exit(0);
|
|
474
|
+
}
|
|
475
|
+
if (response && response.decision === 'sandbox') {
|
|
476
|
+
process.exit(125);
|
|
477
|
+
}
|
|
478
|
+
process.stderr.write(response && response.error ? response.error : 'Brokered link operation denied');
|
|
479
|
+
process.exit(13);
|
|
480
|
+
NODE
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
__cb_has_host_op_env() {
|
|
484
|
+
[ -n "${CODEBUDDY_SANDBOX_BROKER_IPC_ADDRESS:-}" ] || return 1
|
|
485
|
+
[ -n "${CODEBUDDY_SANDBOX_BROKER_SESSION_ID:-}" ] || return 1
|
|
486
|
+
[ -n "${CODEBUDDY_SANDBOX_HOST_FILE_OPERATION_COMMAND:-}" ] || return 1
|
|
487
|
+
[ -f "$__cb_broker_client" ] || return 1
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
__cb_host_op_file_mutation() {
|
|
491
|
+
case "$__cb_app" in
|
|
492
|
+
touch|mkdir|mv|cp) ;;
|
|
493
|
+
*) return 125 ;;
|
|
494
|
+
esac
|
|
495
|
+
__cb_has_host_op_env || return 125
|
|
496
|
+
|
|
497
|
+
__cb_run_node - "$__cb_broker_client" "$__cb_app" "$@" <<'NODE'
|
|
498
|
+
const fs = require('fs');
|
|
499
|
+
const path = require('path');
|
|
500
|
+
const { sendBrokerRequestSync } = require(process.argv[2]);
|
|
501
|
+
|
|
502
|
+
const app = process.argv[3];
|
|
503
|
+
const args = process.argv.slice(4);
|
|
504
|
+
const baseRequest = {
|
|
505
|
+
command: process.env.CODEBUDDY_SANDBOX_HOST_FILE_OPERATION_COMMAND,
|
|
506
|
+
sessionId: process.env.CODEBUDDY_SANDBOX_BROKER_SESSION_ID,
|
|
507
|
+
toolCallId: process.env.CODEBUDDY_SANDBOX_BROKER_TOOL_CALL_ID,
|
|
508
|
+
brokerTraceId: process.env.CODEBUDDY_SANDBOX_BROKER_TRACE_ID,
|
|
509
|
+
runtime: 'toybox-dispatch',
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
function parseOperands(acceptOption) {
|
|
513
|
+
let afterOptions = false;
|
|
514
|
+
const operands = [];
|
|
515
|
+
for (const arg of args) {
|
|
516
|
+
if (afterOptions) {
|
|
517
|
+
operands.push(arg);
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
if (arg === '--') {
|
|
521
|
+
afterOptions = true;
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
if (acceptOption(arg)) {
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
if (arg.startsWith('-')) {
|
|
528
|
+
process.exit(125);
|
|
529
|
+
}
|
|
530
|
+
operands.push(arg);
|
|
531
|
+
}
|
|
532
|
+
return operands;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
function destinationPath(value, source) {
|
|
536
|
+
const resolved = path.resolve(process.cwd(), value);
|
|
537
|
+
try {
|
|
538
|
+
return fs.statSync(resolved).isDirectory()
|
|
539
|
+
? path.join(resolved, path.basename(source))
|
|
540
|
+
: resolved;
|
|
541
|
+
} catch {
|
|
542
|
+
return resolved;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
function dispatch(request) {
|
|
547
|
+
const response = sendBrokerRequestSync({ ...baseRequest, ...request });
|
|
548
|
+
if (response && response.ok === true) {
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
if (response && response.decision === 'sandbox') {
|
|
552
|
+
process.exit(125);
|
|
553
|
+
}
|
|
554
|
+
process.stderr.write(response && response.error ? response.error : 'Brokered ' + app + ' operation denied');
|
|
555
|
+
process.exit(13);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
if (app === 'touch') {
|
|
559
|
+
const operands = parseOperands(() => false);
|
|
560
|
+
if (operands.length === 0) { process.exit(125); }
|
|
561
|
+
for (const operand of operands) {
|
|
562
|
+
dispatch({ operation: 'touch', path: path.resolve(process.cwd(), operand) });
|
|
563
|
+
}
|
|
564
|
+
} else if (app === 'mkdir') {
|
|
565
|
+
let recursive = false;
|
|
566
|
+
const operands = parseOperands(arg => {
|
|
567
|
+
if (arg === '-p' || arg === '--parents') {
|
|
568
|
+
recursive = true;
|
|
569
|
+
return true;
|
|
570
|
+
}
|
|
571
|
+
return false;
|
|
572
|
+
});
|
|
573
|
+
if (operands.length !== 1) { process.exit(125); }
|
|
574
|
+
dispatch({ operation: 'mkdir', path: path.resolve(process.cwd(), operands[0]), recursive });
|
|
575
|
+
} else if (app === 'cp') {
|
|
576
|
+
let recursive = false;
|
|
577
|
+
const operands = parseOperands(arg => {
|
|
578
|
+
if (arg === '-R' || arg === '-r' || arg === '--recursive') {
|
|
579
|
+
recursive = true;
|
|
580
|
+
return true;
|
|
581
|
+
}
|
|
582
|
+
return false;
|
|
583
|
+
});
|
|
584
|
+
if (operands.length !== 2) { process.exit(125); }
|
|
585
|
+
const [fromArg, toArg] = operands;
|
|
586
|
+
const resolvedTo = path.resolve(process.cwd(), toArg);
|
|
587
|
+
if (toArg.endsWith(path.sep)) {
|
|
588
|
+
try {
|
|
589
|
+
if (!fs.statSync(resolvedTo).isDirectory()) { process.exit(125); }
|
|
590
|
+
} catch {
|
|
591
|
+
process.exit(125);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
dispatch({
|
|
595
|
+
operation: 'copy',
|
|
596
|
+
from: path.resolve(process.cwd(), fromArg),
|
|
597
|
+
to: destinationPath(toArg, fromArg),
|
|
598
|
+
...(recursive ? { recursive } : {}),
|
|
599
|
+
});
|
|
600
|
+
} else {
|
|
601
|
+
const operands = parseOperands(arg => {
|
|
602
|
+
if (arg === '-f' || arg === '--force') { return true; }
|
|
603
|
+
return false;
|
|
604
|
+
});
|
|
605
|
+
if (operands.length !== 2) { process.exit(125); }
|
|
606
|
+
const [fromArg, toArg] = operands;
|
|
607
|
+
dispatch({
|
|
608
|
+
operation: 'rename',
|
|
609
|
+
from: path.resolve(process.cwd(), fromArg),
|
|
610
|
+
to: destinationPath(toArg, fromArg),
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
NODE
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
# rm/rmdir/unlink 在沙箱模式下由 toybox 原生实现直接执行,不会经过
|
|
617
|
+
# safe-bin/rm,因此批量删除审批(safe-delete-bulk-guard.cjs)在这里补一次,
|
|
618
|
+
# 与 node-safe-delete-shim.cjs / sitecustomize.py 里的调用方式保持一致。
|
|
619
|
+
__cb_bulk_guard_delete_check() {
|
|
620
|
+
case "$__cb_app" in
|
|
621
|
+
rm|rmdir|unlink) ;;
|
|
622
|
+
*) return 0 ;;
|
|
623
|
+
esac
|
|
624
|
+
__cb_bg_common_sh="${__cb_brokered_dir%/brokered-bin}/safe-bin/safe-delete-common.sh"
|
|
625
|
+
[ -f "$__cb_bg_common_sh" ] || return 0
|
|
626
|
+
|
|
627
|
+
__cb_bg_targets=()
|
|
628
|
+
__cb_bg_after_dd=
|
|
629
|
+
for __cb_bg_arg in "$@"; do
|
|
630
|
+
if [ -n "$__cb_bg_after_dd" ]; then
|
|
631
|
+
__cb_bg_targets+=("$__cb_bg_arg")
|
|
632
|
+
continue
|
|
633
|
+
fi
|
|
634
|
+
case "$__cb_bg_arg" in
|
|
635
|
+
--) __cb_bg_after_dd=1 ;;
|
|
636
|
+
-*) ;;
|
|
637
|
+
*) __cb_bg_targets+=("$__cb_bg_arg") ;;
|
|
638
|
+
esac
|
|
639
|
+
done
|
|
640
|
+
[ "${#__cb_bg_targets[@]}" -gt 0 ] || return 0
|
|
641
|
+
|
|
642
|
+
# shellcheck source=/dev/null
|
|
643
|
+
. "$__cb_bg_common_sh"
|
|
644
|
+
safe_delete_bulk_guard_non_tmp_check "${__cb_bg_targets[@]}"
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
if [ -z "$__cb_toybox" ] || [ ! -x "$__cb_toybox" ]; then __cb_fallback "$@"; exit $?; fi
|
|
648
|
+
|
|
649
|
+
__cb_bulk_guard_delete_check "$@" || exit $?
|
|
650
|
+
__cb_prebackup_targets "$@" || exit $?
|
|
651
|
+
__cb_host_op_ln "$@"
|
|
652
|
+
__cb_host_op_status=$?
|
|
653
|
+
if [ "$__cb_host_op_status" -eq 0 ]; then exit 0; fi
|
|
654
|
+
if [ "$__cb_host_op_status" -ne 125 ]; then exit "$__cb_host_op_status"; fi
|
|
655
|
+
__cb_host_op_file_mutation "$@"
|
|
656
|
+
__cb_host_op_status=$?
|
|
657
|
+
if [ "$__cb_host_op_status" -eq 0 ]; then exit 0; fi
|
|
658
|
+
if [ "$__cb_host_op_status" -ne 125 ]; then exit "$__cb_host_op_status"; fi
|
|
659
|
+
|
|
660
|
+
__cb_err="$(/usr/bin/mktemp "${TMPDIR:-/tmp}/codebuddy-toybox.XXXXXX" 2>/dev/null || mktemp "${TMPDIR:-/tmp}/codebuddy-toybox.XXXXXX" 2>/dev/null)"
|
|
661
|
+
if [ -z "${__cb_err:-}" ]; then CODEBUDDY_TOYBOX_DISPATCH_ACTIVE="$__cb_app" exec "$__cb_toybox" "$__cb_app" "$@"; fi
|
|
662
|
+
|
|
663
|
+
CODEBUDDY_TOYBOX_DISPATCH_ACTIVE="$__cb_app" "$__cb_toybox" "$__cb_app" "$@" 2>"$__cb_err"
|
|
664
|
+
__cb_status=$?
|
|
665
|
+
if [ "$__cb_status" -eq 0 ]; then [ ! -s "$__cb_err" ] || /bin/cat "$__cb_err" >&2 2>/dev/null || true; __cb_cleanup; exit 0; fi
|
|
666
|
+
|
|
667
|
+
__cb_msg="$(/bin/cat "$__cb_err" 2>/dev/null || true)"
|
|
668
|
+
if __cb_should_fallback "$__cb_msg"; then
|
|
669
|
+
__cb_cleanup; __cb_fallback "$@"
|
|
670
|
+
exit $?
|
|
671
|
+
fi
|
|
672
|
+
|
|
673
|
+
[ -z "$__cb_msg" ] || printf '%s' "$__cb_msg" >&2
|
|
674
|
+
__cb_cleanup
|
|
675
|
+
exit "$__cb_status"
|