@tencent-ai/codebuddy-code 2.67.0 → 2.68.0-next.19b562c.20260330
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 +26 -0
- package/dist/codebuddy-headless.js +58 -58
- package/dist/codebuddy.js +120 -79
- package/dist/web-ui/assets/{index-BPT-qRRx.js → index-Cl0stqCM.js} +145 -116
- package/dist/web-ui/assets/index-Dt1puyHn.css +32 -0
- package/dist/web-ui/docs/cn/cli/acp.md +152 -0
- package/dist/web-ui/docs/cn/cli/agent-teams.md +327 -0
- package/dist/web-ui/docs/cn/cli/bash-sandboxing.md +290 -0
- package/dist/web-ui/docs/cn/cli/best-practices.md +554 -0
- package/dist/web-ui/docs/cn/cli/channels-reference.md +293 -0
- package/dist/web-ui/docs/cn/cli/channels.md +215 -0
- package/dist/web-ui/docs/cn/cli/checkpointing.md +51 -0
- package/dist/web-ui/docs/cn/cli/cli-reference.md +187 -0
- package/dist/web-ui/docs/cn/cli/common-workflows.md +1013 -0
- package/dist/web-ui/docs/cn/cli/costs.md +174 -0
- package/dist/web-ui/docs/cn/cli/devcontainer.md +553 -0
- package/dist/web-ui/docs/cn/cli/env-vars.md +326 -0
- package/dist/web-ui/docs/cn/cli/gitlab-ci-cd.md +357 -0
- package/dist/web-ui/docs/cn/cli/headless.md +258 -0
- package/dist/web-ui/docs/cn/cli/hooks-guide.md +9 -0
- package/dist/web-ui/docs/cn/cli/hooks.md +805 -0
- package/dist/web-ui/docs/cn/cli/iam.md +530 -0
- package/dist/web-ui/docs/cn/cli/ide-integrations.md +92 -0
- package/dist/web-ui/docs/cn/cli/installation.md +291 -0
- package/dist/web-ui/docs/cn/cli/interactive-mode.md +233 -0
- package/dist/web-ui/docs/cn/cli/mcp.md +739 -0
- package/dist/web-ui/docs/cn/cli/memory.md +436 -0
- package/dist/web-ui/docs/cn/cli/models.md +356 -0
- package/dist/web-ui/docs/cn/cli/overview.md +100 -0
- package/dist/web-ui/docs/cn/cli/plugin-marketplaces.md +533 -0
- package/dist/web-ui/docs/cn/cli/plugins-reference.md +774 -0
- package/dist/web-ui/docs/cn/cli/plugins.md +689 -0
- package/dist/web-ui/docs/cn/cli/quickstart.md +249 -0
- package/dist/web-ui/docs/cn/cli/release-notes/README.md +199 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.10.0.md +23 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.10.1.md +5 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.11.0.md +24 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.12.0.md +21 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.13.0.md +20 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.14.0.md +22 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.14.1.md +8 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.15.0.md +18 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.15.1.md +11 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.16.0.md +20 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.17.0.md +29 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.18.0.md +17 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.19.0.md +11 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.19.1.md +14 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.19.2.md +11 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.20.0.md +23 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.20.1.md +15 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.21.0.md +13 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.22.0.md +16 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.23.0.md +20 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.23.2.md +5 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.23.3.md +5 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.23.4.md +15 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.23.5.md +11 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.24.0.md +17 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.25.0.md +18 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.25.1.md +21 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.26.0.md +18 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.27.0.md +16 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.27.1.md +16 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.27.2.md +7 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.27.3.md +15 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.28.0.md +26 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.28.1.md +5 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.29.0.md +35 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.3.1.md +16 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.30.0.md +19 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.30.1.md +5 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.31.0.md +51 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.31.1.md +11 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.31.2.md +16 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.32.0.md +19 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.33.0.md +28 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.33.1.md +7 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.36.3.md +17 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.37.0.md +15 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.37.1.md +15 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.37.10.md +5 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.37.11.md +8 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.37.12.md +14 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.37.13.md +11 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.37.14.md +24 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.37.15.md +11 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.37.16.md +9 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.37.17.md +5 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.37.18.md +9 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.37.19.md +5 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.37.2.md +28 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.37.20.md +8 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.37.3.md +22 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.37.4.md +19 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.37.5.md +5 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.37.6.md +5 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.37.7.md +5 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.37.8.md +5 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.37.9.md +8 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.38.0.md +22 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.38.1.md +6 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.38.2.md +9 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.39.0.md +18 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.4.0.md +19 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.40.0.md +20 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.40.1.md +6 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.41.0.md +15 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.41.1.md +6 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.41.2.md +5 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.41.3.md +8 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.41.4.md +5 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.41.5.md +10 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.41.6.md +9 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.41.7.md +14 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.41.8.md +18 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.42.0.md +39 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.42.1.md +8 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.42.3.md +18 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.43.0.md +27 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.43.1.md +27 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.44.0.md +11 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.44.1.md +22 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.45.0.md +34 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.45.1.md +7 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.46.0.md +12 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.47.0.md +20 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.48.0.md +32 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.48.1.md +11 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.49.0.md +26 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.49.1.md +14 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.49.2.md +39 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.49.3.md +7 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.49.5.md +11 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.49.6.md +9 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.49.7.md +7 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.5.0.md +24 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.50.0.md +25 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.50.1.md +9 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.50.2.md +11 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.50.3.md +5 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.50.4.md +17 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.50.5.md +16 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.50.6.md +15 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.50.7.md +15 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.51.0.md +24 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.51.1.md +17 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.51.2.md +5 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.52.0.md +30 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.52.1.md +28 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.52.2.md +12 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.52.3.md +13 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.52.4.md +27 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.52.5.md +21 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.52.6.md +7 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.53.0.md +29 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.54.0.md +26 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.55.0.md +21 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.55.1.md +13 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.56.0.md +20 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.56.1.md +5 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.57.0.md +32 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.57.1.md +10 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.58.0.md +34 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.59.0.md +28 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.6.0.md +5 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.6.1.md +10 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.60.0.md +20 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.61.0.md +29 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.61.1.md +5 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.61.2.md +6 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.61.3.md +13 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.62.0.md +21 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.62.1.md +11 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.63.0.md +19 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.63.1.md +5 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.63.2.md +7 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.63.3.md +6 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.63.4.md +8 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.63.5.md +6 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.64.0.md +37 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.64.1.md +6 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.64.2.md +11 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.65.0.md +19 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.65.1.md +11 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.66.0.md +15 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.66.1.md +14 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.66.2.md +5 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.67.0.md +33 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.7.0.md +16 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.8.0.md +18 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.8.1.md +17 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.8.2.md +5 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.8.3.md +14 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.8.4.md +9 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.8.5.md +5 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.8.6.md +14 -0
- package/dist/web-ui/docs/cn/cli/release-notes/v2.9.0.md +5 -0
- package/dist/web-ui/docs/cn/cli/remote-control.md +247 -0
- package/dist/web-ui/docs/cn/cli/sandboxing.md +316 -0
- package/dist/web-ui/docs/cn/cli/scheduled-tasks.md +161 -0
- package/dist/web-ui/docs/cn/cli/sdk-custom-tools.md +1195 -0
- package/dist/web-ui/docs/cn/cli/sdk-demos.md +347 -0
- package/dist/web-ui/docs/cn/cli/sdk-hooks.md +803 -0
- package/dist/web-ui/docs/cn/cli/sdk-mcp.md +643 -0
- package/dist/web-ui/docs/cn/cli/sdk-permissions.md +501 -0
- package/dist/web-ui/docs/cn/cli/sdk-python.md +783 -0
- package/dist/web-ui/docs/cn/cli/sdk-sessions.md +332 -0
- package/dist/web-ui/docs/cn/cli/sdk-typescript.md +759 -0
- package/dist/web-ui/docs/cn/cli/sdk.md +1105 -0
- package/dist/web-ui/docs/cn/cli/security.md +387 -0
- package/dist/web-ui/docs/cn/cli/settings.md +602 -0
- package/dist/web-ui/docs/cn/cli/skills.md +448 -0
- package/dist/web-ui/docs/cn/cli/slash-commands.md +397 -0
- package/dist/web-ui/docs/cn/cli/statusline.md +525 -0
- package/dist/web-ui/docs/cn/cli/sub-agents.md +634 -0
- package/dist/web-ui/docs/cn/cli/terminal-config.md +77 -0
- package/dist/web-ui/docs/cn/cli/tools-reference.md +99 -0
- package/dist/web-ui/docs/cn/cli/troubleshooting.md +190 -0
- package/dist/web-ui/docs/cn/cli/web-ui.md +164 -0
- package/dist/web-ui/docs/cn/cli/wecom-bot-setup.md +274 -0
- package/dist/web-ui/docs/cn/cli/worktree.md +660 -0
- package/dist/web-ui/docs/en/cli/acp.md +126 -0
- package/dist/web-ui/docs/en/cli/agent-teams.md +327 -0
- package/dist/web-ui/docs/en/cli/bash-sandboxing.md +357 -0
- package/dist/web-ui/docs/en/cli/best-practices.md +554 -0
- package/dist/web-ui/docs/en/cli/channels-reference.md +293 -0
- package/dist/web-ui/docs/en/cli/channels.md +215 -0
- package/dist/web-ui/docs/en/cli/checkpointing.md +53 -0
- package/dist/web-ui/docs/en/cli/cli-reference.md +187 -0
- package/dist/web-ui/docs/en/cli/common-workflows.md +1011 -0
- package/dist/web-ui/docs/en/cli/costs.md +174 -0
- package/dist/web-ui/docs/en/cli/devcontainer.md +553 -0
- package/dist/web-ui/docs/en/cli/env-vars.md +326 -0
- package/dist/web-ui/docs/en/cli/gitlab-ci-cd.md +357 -0
- package/dist/web-ui/docs/en/cli/headless.md +258 -0
- package/dist/web-ui/docs/en/cli/hooks-guide.md +9 -0
- package/dist/web-ui/docs/en/cli/hooks.md +801 -0
- package/dist/web-ui/docs/en/cli/iam.md +526 -0
- package/dist/web-ui/docs/en/cli/ide-integrations.md +92 -0
- package/dist/web-ui/docs/en/cli/installation.md +266 -0
- package/dist/web-ui/docs/en/cli/interactive-mode.md +233 -0
- package/dist/web-ui/docs/en/cli/mcp.md +739 -0
- package/dist/web-ui/docs/en/cli/memory.md +436 -0
- package/dist/web-ui/docs/en/cli/models.md +355 -0
- package/dist/web-ui/docs/en/cli/overview.md +100 -0
- package/dist/web-ui/docs/en/cli/plugin-marketplaces.md +534 -0
- package/dist/web-ui/docs/en/cli/plugins-reference.md +774 -0
- package/dist/web-ui/docs/en/cli/plugins.md +688 -0
- package/dist/web-ui/docs/en/cli/quickstart.md +249 -0
- package/dist/web-ui/docs/en/cli/release-notes/README.md +193 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.10.0.md +23 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.10.1.md +5 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.11.0.md +24 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.12.0.md +21 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.13.0.md +20 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.14.0.md +22 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.14.1.md +8 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.15.0.md +18 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.15.1.md +11 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.16.0.md +20 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.17.0.md +29 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.18.0.md +17 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.19.0.md +11 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.19.1.md +14 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.19.2.md +11 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.20.0.md +23 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.20.1.md +15 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.21.0.md +13 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.22.0.md +16 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.23.0.md +41 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.23.2.md +5 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.23.3.md +5 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.23.4.md +15 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.23.5.md +11 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.24.0.md +17 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.25.0.md +18 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.25.1.md +21 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.26.0.md +18 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.27.0.md +16 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.27.1.md +16 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.27.2.md +7 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.27.3.md +15 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.28.0.md +26 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.28.1.md +5 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.29.0.md +35 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.3.1.md +16 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.30.0.md +19 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.30.1.md +5 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.31.0.md +51 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.31.1.md +11 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.31.2.md +16 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.32.0.md +19 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.33.0.md +28 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.33.1.md +7 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.34.0.md +27 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.34.1.md +7 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.35.0.md +22 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.36.0.md +23 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.36.1.md +5 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.36.2.md +22 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.36.3.md +17 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.37.0.md +15 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.37.1.md +15 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.37.10.md +5 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.37.11.md +8 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.37.12.md +14 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.37.13.md +11 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.37.14.md +24 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.37.15.md +11 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.37.16.md +9 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.37.17.md +5 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.37.18.md +9 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.37.19.md +5 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.37.2.md +28 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.37.20.md +8 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.37.3.md +22 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.37.4.md +19 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.37.5.md +5 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.37.6.md +5 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.37.7.md +5 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.37.8.md +5 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.37.9.md +8 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.38.0.md +22 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.38.1.md +6 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.38.2.md +9 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.39.0.md +18 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.4.0.md +19 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.40.0.md +20 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.40.1.md +6 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.41.0.md +15 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.41.1.md +6 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.41.2.md +5 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.41.3.md +8 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.41.4.md +5 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.41.5.md +10 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.41.6.md +9 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.41.7.md +14 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.41.8.md +18 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.42.0.md +39 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.42.1.md +8 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.42.3.md +18 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.43.0.md +27 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.43.1.md +27 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.44.0.md +11 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.44.1.md +22 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.45.0.md +34 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.45.1.md +7 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.46.0.md +12 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.47.0.md +20 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.48.0.md +32 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.48.1.md +11 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.49.0.md +26 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.49.1.md +14 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.49.2.md +39 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.49.3.md +7 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.49.5.md +11 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.49.6.md +9 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.49.7.md +7 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.5.0.md +24 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.50.0.md +25 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.50.1.md +9 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.50.2.md +11 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.50.3.md +5 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.50.4.md +17 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.50.5.md +16 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.50.6.md +15 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.50.7.md +15 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.51.0.md +24 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.51.1.md +17 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.51.2.md +5 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.52.0.md +30 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.52.1.md +28 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.52.2.md +12 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.52.3.md +13 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.52.4.md +27 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.52.5.md +21 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.52.6.md +7 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.53.0.md +29 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.54.0.md +26 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.55.0.md +21 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.55.1.md +13 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.56.0.md +20 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.56.1.md +5 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.57.0.md +32 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.57.1.md +10 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.58.0.md +34 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.59.0.md +28 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.6.0.md +5 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.6.1.md +10 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.60.0.md +20 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.61.0.md +29 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.61.1.md +5 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.61.2.md +6 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.61.3.md +13 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.62.0.md +21 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.62.1.md +11 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.63.0.md +19 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.63.1.md +5 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.63.2.md +7 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.63.3.md +6 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.63.4.md +8 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.63.5.md +6 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.64.0.md +37 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.64.1.md +6 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.64.2.md +11 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.65.0.md +19 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.65.1.md +11 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.66.0.md +15 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.66.1.md +14 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.66.2.md +5 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.67.0.md +33 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.7.0.md +16 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.8.0.md +18 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.8.1.md +17 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.8.2.md +5 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.8.3.md +14 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.8.4.md +9 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.8.5.md +5 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.8.6.md +14 -0
- package/dist/web-ui/docs/en/cli/release-notes/v2.9.0.md +5 -0
- package/dist/web-ui/docs/en/cli/remote-control.md +247 -0
- package/dist/web-ui/docs/en/cli/sandboxing.md +316 -0
- package/dist/web-ui/docs/en/cli/scheduled-tasks.md +160 -0
- package/dist/web-ui/docs/en/cli/sdk-custom-tools.md +1131 -0
- package/dist/web-ui/docs/en/cli/sdk-demos.md +347 -0
- package/dist/web-ui/docs/en/cli/sdk-hooks.md +813 -0
- package/dist/web-ui/docs/en/cli/sdk-mcp.md +645 -0
- package/dist/web-ui/docs/en/cli/sdk-permissions.md +461 -0
- package/dist/web-ui/docs/en/cli/sdk-python.md +797 -0
- package/dist/web-ui/docs/en/cli/sdk-sessions.md +340 -0
- package/dist/web-ui/docs/en/cli/sdk-typescript.md +770 -0
- package/dist/web-ui/docs/en/cli/sdk.md +1103 -0
- package/dist/web-ui/docs/en/cli/security.md +388 -0
- package/dist/web-ui/docs/en/cli/settings.md +602 -0
- package/dist/web-ui/docs/en/cli/skills.md +448 -0
- package/dist/web-ui/docs/en/cli/slash-commands.md +397 -0
- package/dist/web-ui/docs/en/cli/statusline.md +525 -0
- package/dist/web-ui/docs/en/cli/sub-agents.md +621 -0
- package/dist/web-ui/docs/en/cli/terminal-config.md +77 -0
- package/dist/web-ui/docs/en/cli/tools-reference.md +99 -0
- package/dist/web-ui/docs/en/cli/troubleshooting.md +190 -0
- package/dist/web-ui/docs/en/cli/web-ui.md +164 -0
- package/dist/web-ui/docs/en/cli/wecom-bot-setup.md +274 -0
- package/dist/web-ui/docs/en/cli/worktree.md +660 -0
- package/dist/web-ui/docs/search-index-en.json +1 -0
- package/dist/web-ui/docs/search-index-zh.json +1 -0
- package/dist/web-ui/docs/sidebar-en.json +1 -0
- package/dist/web-ui/docs/sidebar-zh.json +1 -0
- package/dist/web-ui/index.html +2 -2
- package/package.json +3 -2
- package/product.cloudhosted.json +2 -2
- package/product.internal.json +2 -2
- package/product.ioa.json +2 -2
- package/product.json +3 -3
- package/product.selfhosted.json +2 -2
- package/dist/web-ui/assets/index-f_ibHSHw.css +0 -32
|
@@ -0,0 +1,803 @@
|
|
|
1
|
+
# SDK Hook 系统
|
|
2
|
+
|
|
3
|
+
> **版本要求**:本文档针对 CodeBuddy Agent SDK v0.1.0 及以上版本。
|
|
4
|
+
|
|
5
|
+
本文档介绍如何在 SDK 中使用 Hook 系统,在工具执行前后插入自定义逻辑。
|
|
6
|
+
|
|
7
|
+
## 概述
|
|
8
|
+
|
|
9
|
+
Hook 允许你在 CodeBuddy 的会话生命周期内插入自定义逻辑,实现:
|
|
10
|
+
|
|
11
|
+
- 工具调用前的校验和拦截
|
|
12
|
+
- 工具执行后的日志记录
|
|
13
|
+
- 用户提交内容的审查
|
|
14
|
+
- 会话开始/结束时的初始化和清理
|
|
15
|
+
- `worktree` 创建与清理时的自定义流程
|
|
16
|
+
|
|
17
|
+
### 支持的事件
|
|
18
|
+
|
|
19
|
+
| 事件 | 触发时机 |
|
|
20
|
+
|------|---------|
|
|
21
|
+
| `PreToolUse` | 工具执行前 |
|
|
22
|
+
| `PostToolUse` | 工具执行成功后 |
|
|
23
|
+
| `UserPromptSubmit` | 用户提交消息时 |
|
|
24
|
+
| `Stop` | 主 Agent 响应结束时 |
|
|
25
|
+
| `SubagentStop` | 子 Agent 结束时 |
|
|
26
|
+
| `PreCompact` | 上下文压缩前 |
|
|
27
|
+
| `WorktreeCreate` | 创建隔离 `worktree` 时 |
|
|
28
|
+
| `WorktreeRemove` | 删除隔离 `worktree` 时 |
|
|
29
|
+
| `unstable_Checkpoint` | 文件修改后自动创建检查点时 |
|
|
30
|
+
|
|
31
|
+
## Hook 配置
|
|
32
|
+
|
|
33
|
+
通过 `hooks` 选项配置 Hook。每个事件可以有多个 matcher,每个 matcher 可以有多个 hook 回调。
|
|
34
|
+
|
|
35
|
+
### 基本结构
|
|
36
|
+
|
|
37
|
+
::: code-group
|
|
38
|
+
|
|
39
|
+
```typescript [TypeScript]
|
|
40
|
+
import { query } from '@tencent-ai/agent-sdk';
|
|
41
|
+
|
|
42
|
+
const q = query({
|
|
43
|
+
prompt: '帮我分析代码',
|
|
44
|
+
options: {
|
|
45
|
+
model: 'deepseek-v3.1',
|
|
46
|
+
hooks: {
|
|
47
|
+
PreToolUse: [
|
|
48
|
+
{
|
|
49
|
+
matcher: 'Bash', // 只匹配 Bash 工具
|
|
50
|
+
hooks: [
|
|
51
|
+
async (input, toolUseId, ctx) => {
|
|
52
|
+
console.log('即将执行:', input);
|
|
53
|
+
return { continue: true };
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
timeout:5000 // 超时时间(毫秒)
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```python [Python]
|
|
65
|
+
from codebuddy_agent_sdk import query, CodeBuddyAgentOptions, HookMatcher
|
|
66
|
+
|
|
67
|
+
async def pre_tool_hook(input_data, tool_use_id, context):
|
|
68
|
+
print(f"即将执行: {input_data}")
|
|
69
|
+
return {"continue_": True}
|
|
70
|
+
|
|
71
|
+
options = CodeBuddyAgentOptions(
|
|
72
|
+
model="deepseek-v3.1",
|
|
73
|
+
hooks={
|
|
74
|
+
"PreToolUse": [
|
|
75
|
+
HookMatcher(
|
|
76
|
+
matcher="Bash", # 只匹配 Bash 工具
|
|
77
|
+
hooks=[pre_tool_hook],
|
|
78
|
+
timeout=5.0 # 超时时间(秒)
|
|
79
|
+
)
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
async for msg in query(prompt="帮我分析代码", options=options):
|
|
85
|
+
print(msg)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
:::
|
|
89
|
+
|
|
90
|
+
### HookMatcher 结构
|
|
91
|
+
|
|
92
|
+
| 字段 | 类型 | 说明 |
|
|
93
|
+
|------|------|------|
|
|
94
|
+
| `matcher` | `string` | 匹配模式,支持正则表达式。`*` 或空字符串匹配所有 |
|
|
95
|
+
| `hooks` | `HookCallback[]` | 回调函数数组 |
|
|
96
|
+
| `timeout` | `number` | 超时时间(TypeScript 毫秒,Python 秒) |
|
|
97
|
+
|
|
98
|
+
### Matcher 模式
|
|
99
|
+
|
|
100
|
+
- **精确匹配**:`"Bash"` 只匹配 Bash 工具
|
|
101
|
+
- **正则匹配**:`"Edit|Write"` 匹配 Edit 或 Write
|
|
102
|
+
- **通配符**:`"*"` 或 `""` 匹配所有工具
|
|
103
|
+
- **前缀匹配**:`"mcp__.*"` 匹配所有 MCP 工具
|
|
104
|
+
|
|
105
|
+
## 事件类型
|
|
106
|
+
|
|
107
|
+
### PreToolUse
|
|
108
|
+
|
|
109
|
+
工具执行前触发,可以阻止执行或修改输入。
|
|
110
|
+
|
|
111
|
+
::: code-group
|
|
112
|
+
|
|
113
|
+
```typescript [TypeScript]
|
|
114
|
+
hooks: {
|
|
115
|
+
PreToolUse: [{
|
|
116
|
+
matcher: 'Bash',
|
|
117
|
+
hooks: [
|
|
118
|
+
async (input, toolUseId, ctx) => {
|
|
119
|
+
const command = input.command as string;
|
|
120
|
+
|
|
121
|
+
// 阻止危险命令
|
|
122
|
+
if (command.includes('rm -rf')) {
|
|
123
|
+
return {
|
|
124
|
+
decision: 'block',
|
|
125
|
+
reason: '危险命令被阻止'
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return { continue: true };
|
|
130
|
+
}
|
|
131
|
+
]
|
|
132
|
+
}]
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
```python [Python]
|
|
137
|
+
async def pre_bash_hook(input_data, tool_use_id, context):
|
|
138
|
+
command = input_data.get("command", "")
|
|
139
|
+
|
|
140
|
+
# 阻止危险命令
|
|
141
|
+
if "rm -rf" in command:
|
|
142
|
+
return {
|
|
143
|
+
"decision": "block",
|
|
144
|
+
"reason": "危险命令被阻止"
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return {"continue_": True}
|
|
148
|
+
|
|
149
|
+
hooks = {
|
|
150
|
+
"PreToolUse": [
|
|
151
|
+
HookMatcher(matcher="Bash", hooks=[pre_bash_hook])
|
|
152
|
+
]
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
:::
|
|
157
|
+
|
|
158
|
+
### PostToolUse
|
|
159
|
+
|
|
160
|
+
工具执行成功后触发,可以添加额外上下文。
|
|
161
|
+
|
|
162
|
+
::: code-group
|
|
163
|
+
|
|
164
|
+
```typescript [TypeScript]
|
|
165
|
+
hooks: {
|
|
166
|
+
PostToolUse: [{
|
|
167
|
+
matcher: 'Write|Edit',
|
|
168
|
+
hooks: [
|
|
169
|
+
async (input, toolUseId) => {
|
|
170
|
+
console.log(`文件已修改: ${input.file_path}`);
|
|
171
|
+
// 记录修改日志
|
|
172
|
+
await logFileChange(input.file_path);
|
|
173
|
+
return { continue: true };
|
|
174
|
+
}
|
|
175
|
+
]
|
|
176
|
+
}]
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
```python [Python]
|
|
181
|
+
async def post_write_hook(input_data, tool_use_id, context):
|
|
182
|
+
print(f"文件已修改: {input_data.get('file_path')}")
|
|
183
|
+
# 记录修改日志
|
|
184
|
+
await log_file_change(input_data.get("file_path"))
|
|
185
|
+
return {"continue_": True}
|
|
186
|
+
|
|
187
|
+
hooks = {
|
|
188
|
+
"PostToolUse": [
|
|
189
|
+
HookMatcher(matcher="Write|Edit", hooks=[post_write_hook])
|
|
190
|
+
]
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
:::
|
|
195
|
+
|
|
196
|
+
### UserPromptSubmit
|
|
197
|
+
|
|
198
|
+
用户提交消息时触发,可以添加上下文或阻止处理。
|
|
199
|
+
|
|
200
|
+
::: code-group
|
|
201
|
+
|
|
202
|
+
```typescript [TypeScript]
|
|
203
|
+
hooks: {
|
|
204
|
+
UserPromptSubmit: [{
|
|
205
|
+
hooks: [
|
|
206
|
+
async (input) => {
|
|
207
|
+
const prompt = input.prompt as string;
|
|
208
|
+
|
|
209
|
+
// 敏感词检查
|
|
210
|
+
if (containsSensitiveWords(prompt)) {
|
|
211
|
+
return {
|
|
212
|
+
decision: 'block',
|
|
213
|
+
reason: '消息包含敏感内容'
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return { continue: true };
|
|
218
|
+
}
|
|
219
|
+
]
|
|
220
|
+
}]
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
```python [Python]
|
|
225
|
+
async def prompt_check_hook(input_data, tool_use_id, context):
|
|
226
|
+
prompt = input_data.get("prompt", "")
|
|
227
|
+
|
|
228
|
+
# 敏感词检查
|
|
229
|
+
if contains_sensitive_words(prompt):
|
|
230
|
+
return {
|
|
231
|
+
"decision": "block",
|
|
232
|
+
"reason": "消息包含敏感内容"
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return {"continue_": True}
|
|
236
|
+
|
|
237
|
+
hooks = {
|
|
238
|
+
"UserPromptSubmit": [
|
|
239
|
+
HookMatcher(hooks=[prompt_check_hook])
|
|
240
|
+
]
|
|
241
|
+
}
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
:::
|
|
245
|
+
|
|
246
|
+
### Stop / SubagentStop
|
|
247
|
+
|
|
248
|
+
Agent 响应结束时触发,可以阻止停止并要求继续。
|
|
249
|
+
|
|
250
|
+
::: code-group
|
|
251
|
+
|
|
252
|
+
```typescript [TypeScript]
|
|
253
|
+
hooks: {
|
|
254
|
+
Stop: [{
|
|
255
|
+
hooks: [
|
|
256
|
+
async (input) => {
|
|
257
|
+
// 检查任务是否真正完成
|
|
258
|
+
if (!isTaskComplete()) {
|
|
259
|
+
return {
|
|
260
|
+
decision: 'block',
|
|
261
|
+
reason: '任务未完成,请继续'
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
return { continue: true };
|
|
265
|
+
}
|
|
266
|
+
]
|
|
267
|
+
}]
|
|
268
|
+
}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
```python [Python]
|
|
272
|
+
async def stop_hook(input_data, tool_use_id, context):
|
|
273
|
+
# 检查任务是否真正完成
|
|
274
|
+
if not is_task_complete():
|
|
275
|
+
return {
|
|
276
|
+
"decision": "block",
|
|
277
|
+
"reason": "任务未完成,请继续"
|
|
278
|
+
}
|
|
279
|
+
return {"continue_": True}
|
|
280
|
+
|
|
281
|
+
hooks = {
|
|
282
|
+
"Stop": [HookMatcher(hooks=[stop_hook])]
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
:::
|
|
287
|
+
|
|
288
|
+
### unstable_Checkpoint(实验性)
|
|
289
|
+
|
|
290
|
+
文件修改后(Write/Edit/MultiEdit 工具执行成功)自动触发,提供文件快照和变更统计信息。
|
|
291
|
+
|
|
292
|
+
::: warning 实验性 API
|
|
293
|
+
此 Hook 为实验性功能,API 可能在未来版本中发生变化。
|
|
294
|
+
:::
|
|
295
|
+
|
|
296
|
+
::: code-group
|
|
297
|
+
|
|
298
|
+
```typescript [TypeScript]
|
|
299
|
+
import type { CheckpointHookInput } from '@tencent-ai/agent-sdk';
|
|
300
|
+
|
|
301
|
+
hooks: {
|
|
302
|
+
unstable_Checkpoint: [{
|
|
303
|
+
hooks: [
|
|
304
|
+
async (input) => {
|
|
305
|
+
const checkpointInput = input as CheckpointHookInput;
|
|
306
|
+
const checkpoint = checkpointInput.checkpoint;
|
|
307
|
+
|
|
308
|
+
console.log('文件变更检查点:', {
|
|
309
|
+
id: checkpoint.id,
|
|
310
|
+
label: checkpoint.label,
|
|
311
|
+
files: checkpoint.fileChangeStats?.files,
|
|
312
|
+
additions: checkpoint.fileChangeStats?.additions,
|
|
313
|
+
deletions: checkpoint.fileChangeStats?.deletions
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
// 访问文件快照
|
|
317
|
+
for (const [filePath, version] of Object.entries(checkpoint.fileSnapshots)) {
|
|
318
|
+
console.log(` ${filePath} - 版本 ${version.version}`);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return { continue: true };
|
|
322
|
+
}
|
|
323
|
+
]
|
|
324
|
+
}]
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
```python [Python]
|
|
329
|
+
async def checkpoint_hook(input_data, tool_use_id, context):
|
|
330
|
+
checkpoint = input_data.get("checkpoint", {})
|
|
331
|
+
|
|
332
|
+
file_change_stats = checkpoint.get("fileChangeStats", {})
|
|
333
|
+
print(f"文件变更检查点:")
|
|
334
|
+
print(f" ID: {checkpoint.get('id')}")
|
|
335
|
+
print(f" Label: {checkpoint.get('label')}")
|
|
336
|
+
print(f" Files: {file_change_stats.get('files', [])}")
|
|
337
|
+
print(f" Additions: +{file_change_stats.get('additions', 0)} lines")
|
|
338
|
+
print(f" Deletions: -{file_change_stats.get('deletions', 0)} lines")
|
|
339
|
+
|
|
340
|
+
# 访问文件快照
|
|
341
|
+
for file_path, version in checkpoint.get("fileSnapshots", {}).items():
|
|
342
|
+
print(f" {file_path} - 版本 {version.get('version')}")
|
|
343
|
+
|
|
344
|
+
return {"continue_": True}
|
|
345
|
+
|
|
346
|
+
hooks = {
|
|
347
|
+
"unstable_Checkpoint": [HookMatcher(hooks=[checkpoint_hook])]
|
|
348
|
+
}
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
:::
|
|
352
|
+
|
|
353
|
+
**Checkpoint 数据结构**:
|
|
354
|
+
|
|
355
|
+
- `id`: 检查点唯一标识符
|
|
356
|
+
- `label`: 人类可读标签(通常为用户提示)
|
|
357
|
+
- `createdAt`: 创建时间戳
|
|
358
|
+
- `fileSnapshots`: 文件路径到版本信息的映射
|
|
359
|
+
- `filePath`: 文件绝对路径
|
|
360
|
+
- `version`: 版本号
|
|
361
|
+
- `backupFileName`: 备份文件名
|
|
362
|
+
- `backupTime`: 备份时间戳
|
|
363
|
+
- `fileChangeStats`: 文件变更统计
|
|
364
|
+
- `files`: 变更的文件路径列表
|
|
365
|
+
- `additions`: 新增行数
|
|
366
|
+
- `deletions`: 删除行数
|
|
367
|
+
|
|
368
|
+
## Hook 输入
|
|
369
|
+
|
|
370
|
+
Hook 回调接收的输入结构因事件类型而异。
|
|
371
|
+
|
|
372
|
+
### 公共字段
|
|
373
|
+
|
|
374
|
+
```json
|
|
375
|
+
{
|
|
376
|
+
"session_id": "abc123",
|
|
377
|
+
"cwd": "/path/to/project",
|
|
378
|
+
"permission_mode": "default",
|
|
379
|
+
"hook_event_name": "PreToolUse"
|
|
380
|
+
}
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
### PreToolUse / PostToolUse 输入
|
|
384
|
+
|
|
385
|
+
```json
|
|
386
|
+
{
|
|
387
|
+
"tool_name": "Bash",
|
|
388
|
+
"tool_input": {
|
|
389
|
+
"command": "ls -la"
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
### UserPromptSubmit 输入
|
|
395
|
+
|
|
396
|
+
```json
|
|
397
|
+
{
|
|
398
|
+
"prompt": "帮我写一个函数"
|
|
399
|
+
}
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
### Stop / SubagentStop 输入
|
|
403
|
+
|
|
404
|
+
```json
|
|
405
|
+
{
|
|
406
|
+
"stop_hook_active": false
|
|
407
|
+
}
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
**WorktreeCreate 输入示例**:
|
|
411
|
+
|
|
412
|
+
```json
|
|
413
|
+
{
|
|
414
|
+
"hook_event_name": "WorktreeCreate",
|
|
415
|
+
"session_id": "abc123",
|
|
416
|
+
"cwd": "/path/to/project",
|
|
417
|
+
"transcript_path": "/path/to/transcript.jsonl",
|
|
418
|
+
"name": "feature-auth"
|
|
419
|
+
}
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
**WorktreeRemove 输入示例**:
|
|
423
|
+
|
|
424
|
+
```json
|
|
425
|
+
{
|
|
426
|
+
"hook_event_name": "WorktreeRemove",
|
|
427
|
+
"session_id": "abc123",
|
|
428
|
+
"cwd": "/path/to/project",
|
|
429
|
+
"transcript_path": "/path/to/transcript.jsonl",
|
|
430
|
+
"worktree_path": "/tmp/codebuddy-worktrees/feature-auth"
|
|
431
|
+
}
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
### unstable_Checkpoint 输入
|
|
435
|
+
|
|
436
|
+
```json
|
|
437
|
+
{
|
|
438
|
+
"checkpoint": {
|
|
439
|
+
"id": "ckpt_abc123",
|
|
440
|
+
"label": "帮我写一个函数",
|
|
441
|
+
"createdAt": 1705920000000,
|
|
442
|
+
"fileSnapshots": {
|
|
443
|
+
"/path/to/file.ts": {
|
|
444
|
+
"filePath": "/path/to/file.ts",
|
|
445
|
+
"version": 1,
|
|
446
|
+
"backupFileName": "file.ts.v1.backup",
|
|
447
|
+
"backupTime": 1705920000000
|
|
448
|
+
}
|
|
449
|
+
},
|
|
450
|
+
"fileChangeStats": {
|
|
451
|
+
"files": ["/path/to/file.ts"],
|
|
452
|
+
"additions": 10,
|
|
453
|
+
"deletions": 2
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
## Hook 输出
|
|
460
|
+
|
|
461
|
+
Hook 回调返回的输出控制后续行为。
|
|
462
|
+
|
|
463
|
+
### 基本输出字段
|
|
464
|
+
|
|
465
|
+
| 字段 | 类型 | 说明 |
|
|
466
|
+
|------|------|------|
|
|
467
|
+
| `continue` / `continue_` | `boolean` | 是否继续执行(默认 true) |
|
|
468
|
+
| `decision` | `'block'` | 设为 `'block'` 阻止操作 |
|
|
469
|
+
| `reason` | `string` | 阻止原因 |
|
|
470
|
+
| `stopReason` | `string` | 当 `continue` 为 false 时显示的停止消息 |
|
|
471
|
+
| `suppressOutput` | `boolean` | 隐藏输出 |
|
|
472
|
+
|
|
473
|
+
### PreToolUse 特殊输出
|
|
474
|
+
|
|
475
|
+
可以修改工具输入:
|
|
476
|
+
|
|
477
|
+
::: code-group
|
|
478
|
+
|
|
479
|
+
```typescript [TypeScript]
|
|
480
|
+
return {
|
|
481
|
+
continue: true,
|
|
482
|
+
hookSpecificOutput: {
|
|
483
|
+
hookEventName: 'PreToolUse',
|
|
484
|
+
updatedInput: {
|
|
485
|
+
command: `echo "安全检查通过" && ${input.command}`
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
```python [Python]
|
|
492
|
+
return {
|
|
493
|
+
"continue_": True,
|
|
494
|
+
"hookSpecificOutput": {
|
|
495
|
+
"hookEventName": "PreToolUse",
|
|
496
|
+
"updatedInput": {
|
|
497
|
+
"command": f'echo "安全检查通过" && {input_data["command"]}'
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
:::
|
|
504
|
+
|
|
505
|
+
## 示例
|
|
506
|
+
|
|
507
|
+
### 完整示例:Bash 命令审计
|
|
508
|
+
|
|
509
|
+
::: code-group
|
|
510
|
+
|
|
511
|
+
```typescript [TypeScript]
|
|
512
|
+
import { query } from '@tencent-ai/agent-sdk';
|
|
513
|
+
import * as fs from 'fs';
|
|
514
|
+
|
|
515
|
+
const logFile = '/tmp/bash-audit.log';
|
|
516
|
+
|
|
517
|
+
const q = query({
|
|
518
|
+
prompt: '帮我清理临时文件',
|
|
519
|
+
options: {
|
|
520
|
+
model: 'deepseek-v3.1',
|
|
521
|
+
hooks: {
|
|
522
|
+
PreToolUse: [{
|
|
523
|
+
matcher: 'Bash',
|
|
524
|
+
hooks: [
|
|
525
|
+
async (input, toolUseId) => {
|
|
526
|
+
const command = input.command as string;
|
|
527
|
+
const timestamp = new Date().toISOString();
|
|
528
|
+
|
|
529
|
+
// 记录命令
|
|
530
|
+
fs.appendFileSync(logFile, `${timestamp} [PRE] ${command}\n`);
|
|
531
|
+
|
|
532
|
+
// 危险命令检查
|
|
533
|
+
const dangerous = ['rm -rf /', 'mkfs', ':(){:|:&};:'];
|
|
534
|
+
for (const d of dangerous) {
|
|
535
|
+
if (command.includes(d)) {
|
|
536
|
+
return {
|
|
537
|
+
decision: 'block',
|
|
538
|
+
reason: `危险命令被阻止: ${d}`
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
return { continue: true };
|
|
544
|
+
}
|
|
545
|
+
]
|
|
546
|
+
}],
|
|
547
|
+
PostToolUse: [{
|
|
548
|
+
matcher: 'Bash',
|
|
549
|
+
hooks: [
|
|
550
|
+
async (input, toolUseId) => {
|
|
551
|
+
const command = input.command as string;
|
|
552
|
+
const timestamp = new Date().toISOString();
|
|
553
|
+
|
|
554
|
+
// 记录执行完成
|
|
555
|
+
fs.appendFileSync(logFile, `${timestamp} [POST] ${command} - 完成\n`);
|
|
556
|
+
|
|
557
|
+
return { continue: true };
|
|
558
|
+
}
|
|
559
|
+
]
|
|
560
|
+
}]
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
for await (const message of q) {
|
|
566
|
+
console.log(message);
|
|
567
|
+
}
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
```python [Python]
|
|
571
|
+
import asyncio
|
|
572
|
+
from datetime import datetime
|
|
573
|
+
from codebuddy_agent_sdk import query, CodeBuddyAgentOptions, HookMatcher
|
|
574
|
+
|
|
575
|
+
log_file = "/tmp/bash-audit.log"
|
|
576
|
+
|
|
577
|
+
async def pre_bash_hook(input_data, tool_use_id, context):
|
|
578
|
+
command = input_data.get("command", "")
|
|
579
|
+
timestamp = datetime.now().isoformat()
|
|
580
|
+
|
|
581
|
+
# 记录命令
|
|
582
|
+
with open(log_file, "a") as f:
|
|
583
|
+
f.write(f"{timestamp} [PRE] {command}\n")
|
|
584
|
+
|
|
585
|
+
# 危险命令检查
|
|
586
|
+
dangerous = ["rm -rf /", "mkfs", ":(){:|:&};:"]
|
|
587
|
+
for d in dangerous:
|
|
588
|
+
if d in command:
|
|
589
|
+
return {
|
|
590
|
+
"decision": "block",
|
|
591
|
+
"reason": f"危险命令被阻止: {d}"
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
return {"continue_": True}
|
|
595
|
+
|
|
596
|
+
async def post_bash_hook(input_data, tool_use_id, context):
|
|
597
|
+
command = input_data.get("command", "")
|
|
598
|
+
timestamp = datetime.now().isoformat()
|
|
599
|
+
|
|
600
|
+
# 记录执行完成
|
|
601
|
+
with open(log_file, "a") as f:
|
|
602
|
+
f.write(f"{timestamp} [POST] {command} - 完成\n")
|
|
603
|
+
|
|
604
|
+
return {"continue_": True}
|
|
605
|
+
|
|
606
|
+
async def main():
|
|
607
|
+
options = CodeBuddyAgentOptions(
|
|
608
|
+
model="deepseek-v3.1",
|
|
609
|
+
hooks={
|
|
610
|
+
"PreToolUse": [
|
|
611
|
+
HookMatcher(matcher="Bash", hooks=[pre_bash_hook])
|
|
612
|
+
],
|
|
613
|
+
"PostToolUse": [
|
|
614
|
+
HookMatcher(matcher="Bash", hooks=[post_bash_hook])
|
|
615
|
+
]
|
|
616
|
+
}
|
|
617
|
+
)
|
|
618
|
+
|
|
619
|
+
async for message in query(prompt="帮我清理临时文件", options=options):
|
|
620
|
+
print(message)
|
|
621
|
+
|
|
622
|
+
asyncio.run(main())
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
:::
|
|
626
|
+
|
|
627
|
+
### 示例:限制文件修改范围
|
|
628
|
+
|
|
629
|
+
::: code-group
|
|
630
|
+
|
|
631
|
+
```typescript [TypeScript]
|
|
632
|
+
hooks: {
|
|
633
|
+
PreToolUse: [{
|
|
634
|
+
matcher: 'Write|Edit',
|
|
635
|
+
hooks: [
|
|
636
|
+
async (input) => {
|
|
637
|
+
const filePath = input.file_path as string;
|
|
638
|
+
|
|
639
|
+
// 只允许修改 src 目录
|
|
640
|
+
if (!filePath.startsWith('/path/to/project/src/')) {
|
|
641
|
+
return {
|
|
642
|
+
decision: 'block',
|
|
643
|
+
reason: `不允许修改 src 目录外的文件: ${filePath}`
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
// 禁止修改配置文件
|
|
648
|
+
if (filePath.endsWith('.env') || filePath.includes('.git/')) {
|
|
649
|
+
return {
|
|
650
|
+
decision: 'block',
|
|
651
|
+
reason: '不允许修改敏感文件'
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
return { continue: true };
|
|
656
|
+
}
|
|
657
|
+
]
|
|
658
|
+
}]
|
|
659
|
+
}
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
```python [Python]
|
|
663
|
+
async def file_scope_hook(input_data, tool_use_id, context):
|
|
664
|
+
file_path = input_data.get("file_path", "")
|
|
665
|
+
|
|
666
|
+
# 只允许修改 src 目录
|
|
667
|
+
if not file_path.startswith("/path/to/project/src/"):
|
|
668
|
+
return {
|
|
669
|
+
"decision": "block",
|
|
670
|
+
"reason": f"不允许修改 src 目录外的文件: {file_path}"
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
# 禁止修改配置文件
|
|
674
|
+
if file_path.endswith(".env") or ".git/" in file_path:
|
|
675
|
+
return {
|
|
676
|
+
"decision": "block",
|
|
677
|
+
"reason": "不允许修改敏感文件"
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
return {"continue_": True}
|
|
681
|
+
|
|
682
|
+
hooks = {
|
|
683
|
+
"PreToolUse": [
|
|
684
|
+
HookMatcher(matcher="Write|Edit", hooks=[file_scope_hook])
|
|
685
|
+
]
|
|
686
|
+
}
|
|
687
|
+
```
|
|
688
|
+
|
|
689
|
+
:::
|
|
690
|
+
|
|
691
|
+
### 示例:文件修改追踪(Checkpoint Hook)
|
|
692
|
+
|
|
693
|
+
::: code-group
|
|
694
|
+
|
|
695
|
+
```typescript [TypeScript]
|
|
696
|
+
import { query, type CheckpointHookInput } from '@tencent-ai/agent-sdk';
|
|
697
|
+
import * as fs from 'fs';
|
|
698
|
+
|
|
699
|
+
const changeLog = '/tmp/file-changes.log';
|
|
700
|
+
|
|
701
|
+
const q = query({
|
|
702
|
+
prompt: '重构 src/utils.ts 文件',
|
|
703
|
+
options: {
|
|
704
|
+
model: 'deepseek-v3.1',
|
|
705
|
+
hooks: {
|
|
706
|
+
unstable_Checkpoint: [{
|
|
707
|
+
hooks: [
|
|
708
|
+
async (input) => {
|
|
709
|
+
const checkpointInput = input as CheckpointHookInput;
|
|
710
|
+
const checkpoint = checkpointInput.checkpoint;
|
|
711
|
+
const stats = checkpoint.fileChangeStats;
|
|
712
|
+
|
|
713
|
+
if (!stats) return { continue: true };
|
|
714
|
+
|
|
715
|
+
// 记录文件变更
|
|
716
|
+
const timestamp = new Date().toISOString();
|
|
717
|
+
const logEntry = `
|
|
718
|
+
[${timestamp}] Checkpoint ${checkpoint.id}
|
|
719
|
+
Label: ${checkpoint.label}
|
|
720
|
+
Files: ${stats.files.join(', ')}
|
|
721
|
+
Changes: +${stats.additions}/-${stats.deletions}
|
|
722
|
+
Snapshots: ${Object.keys(checkpoint.fileSnapshots).length} files
|
|
723
|
+
`;
|
|
724
|
+
|
|
725
|
+
fs.appendFileSync(changeLog, logEntry);
|
|
726
|
+
|
|
727
|
+
// 如果变更过大,提醒用户
|
|
728
|
+
if (stats.additions + stats.deletions > 100) {
|
|
729
|
+
console.warn('⚠️ 大量代码变更,建议review');
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
return { continue: true };
|
|
733
|
+
}
|
|
734
|
+
]
|
|
735
|
+
}]
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
});
|
|
739
|
+
|
|
740
|
+
for await (const message of q) {
|
|
741
|
+
console.log(message);
|
|
742
|
+
}
|
|
743
|
+
```
|
|
744
|
+
|
|
745
|
+
```python [Python]
|
|
746
|
+
import asyncio
|
|
747
|
+
from datetime import datetime
|
|
748
|
+
from codebuddy_agent_sdk import query, CodeBuddyAgentOptions, HookMatcher
|
|
749
|
+
|
|
750
|
+
change_log = "/tmp/file-changes.log"
|
|
751
|
+
|
|
752
|
+
async def checkpoint_tracker(input_data, tool_use_id, context):
|
|
753
|
+
checkpoint = input_data.get("checkpoint", {})
|
|
754
|
+
stats = checkpoint.get("fileChangeStats")
|
|
755
|
+
|
|
756
|
+
if not stats:
|
|
757
|
+
return {"continue_": True}
|
|
758
|
+
|
|
759
|
+
# 记录文件变更
|
|
760
|
+
timestamp = datetime.now().isoformat()
|
|
761
|
+
log_entry = f"""
|
|
762
|
+
[{timestamp}] Checkpoint {checkpoint.get('id')}
|
|
763
|
+
Label: {checkpoint.get('label')}
|
|
764
|
+
Files: {', '.join(stats.get('files', []))}
|
|
765
|
+
Changes: +{stats.get('additions', 0)}/-{stats.get('deletions', 0)}
|
|
766
|
+
Snapshots: {len(checkpoint.get('fileSnapshots', {}))} files
|
|
767
|
+
"""
|
|
768
|
+
|
|
769
|
+
with open(change_log, "a") as f:
|
|
770
|
+
f.write(log_entry)
|
|
771
|
+
|
|
772
|
+
# 如果变更过大,提醒用户
|
|
773
|
+
total_changes = stats.get("additions", 0) + stats.get("deletions", 0)
|
|
774
|
+
if total_changes > 100:
|
|
775
|
+
print("⚠️ 大量代码变更,建议 review")
|
|
776
|
+
|
|
777
|
+
return {"continue_": True}
|
|
778
|
+
|
|
779
|
+
async def main():
|
|
780
|
+
options = CodeBuddyAgentOptions(
|
|
781
|
+
model="deepseek-v3.1",
|
|
782
|
+
hooks={
|
|
783
|
+
"unstable_Checkpoint": [
|
|
784
|
+
HookMatcher(hooks=[checkpoint_tracker])
|
|
785
|
+
]
|
|
786
|
+
}
|
|
787
|
+
)
|
|
788
|
+
|
|
789
|
+
async for message in query(prompt="重构 src/utils.ts 文件", options=options):
|
|
790
|
+
print(message)
|
|
791
|
+
|
|
792
|
+
asyncio.run(main())
|
|
793
|
+
```
|
|
794
|
+
|
|
795
|
+
:::
|
|
796
|
+
|
|
797
|
+
## 相关文档
|
|
798
|
+
|
|
799
|
+
- [SDK 概览](sdk.md) - 快速入门和使用示例
|
|
800
|
+
- [SDK 权限控制](sdk-permissions.md) - canUseTool 回调
|
|
801
|
+
- [Hook 参考指南](hooks.md) - CLI Hook 完整参考
|
|
802
|
+
- [TypeScript SDK 参考](sdk-typescript.md) - 完整 API 参考
|
|
803
|
+
- [Python SDK 参考](sdk-python.md) - 完整 API 参考
|