xtep-workspace 1.10.10
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 +525 -0
- package/README.md +188 -0
- package/config/component-versions.json +16 -0
- package/config/scenarioCapabilities.json +29 -0
- package/config/version-notes.yaml +244 -0
- package/dist/adapters/OutputAdapter.d.ts +79 -0
- package/dist/adapters/OutputAdapter.d.ts.map +1 -0
- package/dist/adapters/OutputAdapter.js +124 -0
- package/dist/adapters/OutputAdapter.js.map +1 -0
- package/dist/cli/check-node-version.d.ts +3 -0
- package/dist/cli/check-node-version.d.ts.map +1 -0
- package/dist/cli/check-node-version.js +153 -0
- package/dist/cli/check-node-version.js.map +1 -0
- package/dist/cli/plugins.d.ts +41 -0
- package/dist/cli/plugins.d.ts.map +1 -0
- package/dist/cli/plugins.js +742 -0
- package/dist/cli/plugins.js.map +1 -0
- package/dist/cli/rebuild.d.ts +63 -0
- package/dist/cli/rebuild.d.ts.map +1 -0
- package/dist/cli/rebuild.js +989 -0
- package/dist/cli/rebuild.js.map +1 -0
- package/dist/cli/repair.d.ts +7 -0
- package/dist/cli/repair.d.ts.map +1 -0
- package/dist/cli/repair.js +925 -0
- package/dist/cli/repair.js.map +1 -0
- package/dist/cli/setup.d.ts +7 -0
- package/dist/cli/setup.d.ts.map +1 -0
- package/dist/cli/setup.js +452 -0
- package/dist/cli/setup.js.map +1 -0
- package/dist/cli/update.d.ts +10 -0
- package/dist/cli/update.d.ts.map +1 -0
- package/dist/cli/update.js +426 -0
- package/dist/cli/update.js.map +1 -0
- package/dist/cli/webui.d.ts +6 -0
- package/dist/cli/webui.d.ts.map +1 -0
- package/dist/cli/webui.js +210 -0
- package/dist/cli/webui.js.map +1 -0
- package/dist/http/index.d.ts +3 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/http/index.js +15 -0
- package/dist/http/index.js.map +1 -0
- package/dist/http/middleware/errorHandler.d.ts +16 -0
- package/dist/http/middleware/errorHandler.d.ts.map +1 -0
- package/dist/http/middleware/errorHandler.js +79 -0
- package/dist/http/middleware/errorHandler.js.map +1 -0
- package/dist/http/routes/admin.d.ts +3 -0
- package/dist/http/routes/admin.d.ts.map +1 -0
- package/dist/http/routes/admin.js +730 -0
- package/dist/http/routes/admin.js.map +1 -0
- package/dist/http/routes/backup.d.ts +3 -0
- package/dist/http/routes/backup.d.ts.map +1 -0
- package/dist/http/routes/backup.js +172 -0
- package/dist/http/routes/backup.js.map +1 -0
- package/dist/http/routes/config.d.ts +3 -0
- package/dist/http/routes/config.d.ts.map +1 -0
- package/dist/http/routes/config.js +157 -0
- package/dist/http/routes/config.js.map +1 -0
- package/dist/http/routes/context.d.ts +3 -0
- package/dist/http/routes/context.d.ts.map +1 -0
- package/dist/http/routes/context.js +82 -0
- package/dist/http/routes/context.js.map +1 -0
- package/dist/http/routes/log.d.ts +3 -0
- package/dist/http/routes/log.d.ts.map +1 -0
- package/dist/http/routes/log.js +105 -0
- package/dist/http/routes/log.js.map +1 -0
- package/dist/http/routes/memo.d.ts +6 -0
- package/dist/http/routes/memo.d.ts.map +1 -0
- package/dist/http/routes/memo.js +29 -0
- package/dist/http/routes/memo.js.map +1 -0
- package/dist/http/routes/node.d.ts +3 -0
- package/dist/http/routes/node.d.ts.map +1 -0
- package/dist/http/routes/node.js +251 -0
- package/dist/http/routes/node.js.map +1 -0
- package/dist/http/routes/state.d.ts +3 -0
- package/dist/http/routes/state.d.ts.map +1 -0
- package/dist/http/routes/state.js +48 -0
- package/dist/http/routes/state.js.map +1 -0
- package/dist/http/routes/workspace.d.ts +3 -0
- package/dist/http/routes/workspace.d.ts.map +1 -0
- package/dist/http/routes/workspace.js +249 -0
- package/dist/http/routes/workspace.js.map +1 -0
- package/dist/http/server.d.ts +10 -0
- package/dist/http/server.d.ts.map +1 -0
- package/dist/http/server.js +284 -0
- package/dist/http/server.js.map +1 -0
- package/dist/http/services.d.ts +93 -0
- package/dist/http/services.d.ts.map +1 -0
- package/dist/http/services.js +297 -0
- package/dist/http/services.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1073 -0
- package/dist/index.js.map +1 -0
- package/dist/prompts/guidanceContent.d.ts +18 -0
- package/dist/prompts/guidanceContent.d.ts.map +1 -0
- package/dist/prompts/guidanceContent.js +814 -0
- package/dist/prompts/guidanceContent.js.map +1 -0
- package/dist/prompts/index.d.ts +2 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +4 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/prompts/instructions.d.ts +56 -0
- package/dist/prompts/instructions.d.ts.map +1 -0
- package/dist/prompts/instructions.js +1343 -0
- package/dist/prompts/instructions.js.map +1 -0
- package/dist/services/BackupService.d.ts +104 -0
- package/dist/services/BackupService.d.ts.map +1 -0
- package/dist/services/BackupService.js +549 -0
- package/dist/services/BackupService.js.map +1 -0
- package/dist/services/CapabilityService.d.ts +38 -0
- package/dist/services/CapabilityService.d.ts.map +1 -0
- package/dist/services/CapabilityService.js +256 -0
- package/dist/services/CapabilityService.js.map +1 -0
- package/dist/services/ConfigService.d.ts +35 -0
- package/dist/services/ConfigService.d.ts.map +1 -0
- package/dist/services/ConfigService.js +105 -0
- package/dist/services/ConfigService.js.map +1 -0
- package/dist/services/ContextService.d.ts +65 -0
- package/dist/services/ContextService.d.ts.map +1 -0
- package/dist/services/ContextService.js +503 -0
- package/dist/services/ContextService.js.map +1 -0
- package/dist/services/DetectionService.d.ts +76 -0
- package/dist/services/DetectionService.d.ts.map +1 -0
- package/dist/services/DetectionService.js +262 -0
- package/dist/services/DetectionService.js.map +1 -0
- package/dist/services/DispatchService.d.ts +267 -0
- package/dist/services/DispatchService.d.ts.map +1 -0
- package/dist/services/DispatchService.js +1357 -0
- package/dist/services/DispatchService.js.map +1 -0
- package/dist/services/EventService.d.ts +81 -0
- package/dist/services/EventService.d.ts.map +1 -0
- package/dist/services/EventService.js +187 -0
- package/dist/services/EventService.js.map +1 -0
- package/dist/services/GuidanceService.d.ts +64 -0
- package/dist/services/GuidanceService.d.ts.map +1 -0
- package/dist/services/GuidanceService.js +259 -0
- package/dist/services/GuidanceService.js.map +1 -0
- package/dist/services/HealthService.d.ts +43 -0
- package/dist/services/HealthService.d.ts.map +1 -0
- package/dist/services/HealthService.js +276 -0
- package/dist/services/HealthService.js.map +1 -0
- package/dist/services/InstallationService.d.ts +62 -0
- package/dist/services/InstallationService.d.ts.map +1 -0
- package/dist/services/InstallationService.js +204 -0
- package/dist/services/InstallationService.js.map +1 -0
- package/dist/services/LogService.d.ts +35 -0
- package/dist/services/LogService.d.ts.map +1 -0
- package/dist/services/LogService.js +189 -0
- package/dist/services/LogService.js.map +1 -0
- package/dist/services/MemoService.d.ts +39 -0
- package/dist/services/MemoService.d.ts.map +1 -0
- package/dist/services/MemoService.js +288 -0
- package/dist/services/MemoService.js.map +1 -0
- package/dist/services/NodeService.d.ts +90 -0
- package/dist/services/NodeService.d.ts.map +1 -0
- package/dist/services/NodeService.js +958 -0
- package/dist/services/NodeService.js.map +1 -0
- package/dist/services/OpenSpecParser.d.ts +43 -0
- package/dist/services/OpenSpecParser.d.ts.map +1 -0
- package/dist/services/OpenSpecParser.js +191 -0
- package/dist/services/OpenSpecParser.js.map +1 -0
- package/dist/services/ReferenceService.d.ts +35 -0
- package/dist/services/ReferenceService.d.ts.map +1 -0
- package/dist/services/ReferenceService.js +195 -0
- package/dist/services/ReferenceService.js.map +1 -0
- package/dist/services/RepairService.d.ts +36 -0
- package/dist/services/RepairService.d.ts.map +1 -0
- package/dist/services/RepairService.js +429 -0
- package/dist/services/RepairService.js.map +1 -0
- package/dist/services/SearchService.d.ts +34 -0
- package/dist/services/SearchService.d.ts.map +1 -0
- package/dist/services/SearchService.js +293 -0
- package/dist/services/SearchService.js.map +1 -0
- package/dist/services/SessionService.d.ts +136 -0
- package/dist/services/SessionService.d.ts.map +1 -0
- package/dist/services/SessionService.js +297 -0
- package/dist/services/SessionService.js.map +1 -0
- package/dist/services/StateService.d.ts +97 -0
- package/dist/services/StateService.d.ts.map +1 -0
- package/dist/services/StateService.js +846 -0
- package/dist/services/StateService.js.map +1 -0
- package/dist/services/TutorialService.d.ts +114 -0
- package/dist/services/TutorialService.d.ts.map +1 -0
- package/dist/services/TutorialService.js +1262 -0
- package/dist/services/TutorialService.js.map +1 -0
- package/dist/services/WorkspaceService.d.ts +273 -0
- package/dist/services/WorkspaceService.d.ts.map +1 -0
- package/dist/services/WorkspaceService.js +1764 -0
- package/dist/services/WorkspaceService.js.map +1 -0
- package/dist/services/index.d.ts +15 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +14 -0
- package/dist/services/index.js.map +1 -0
- package/dist/storage/FileSystemAdapter.d.ts +223 -0
- package/dist/storage/FileSystemAdapter.d.ts.map +1 -0
- package/dist/storage/FileSystemAdapter.js +384 -0
- package/dist/storage/FileSystemAdapter.js.map +1 -0
- package/dist/storage/JsonStorage.d.ts +158 -0
- package/dist/storage/JsonStorage.d.ts.map +1 -0
- package/dist/storage/JsonStorage.js +613 -0
- package/dist/storage/JsonStorage.js.map +1 -0
- package/dist/storage/MarkdownStorage.d.ts +178 -0
- package/dist/storage/MarkdownStorage.d.ts.map +1 -0
- package/dist/storage/MarkdownStorage.js +918 -0
- package/dist/storage/MarkdownStorage.js.map +1 -0
- package/dist/storage/SessionBindingStorage.d.ts +69 -0
- package/dist/storage/SessionBindingStorage.d.ts.map +1 -0
- package/dist/storage/SessionBindingStorage.js +131 -0
- package/dist/storage/SessionBindingStorage.js.map +1 -0
- package/dist/storage/index.d.ts +6 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +6 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/tools/capability.d.ts +18 -0
- package/dist/tools/capability.d.ts.map +1 -0
- package/dist/tools/capability.js +73 -0
- package/dist/tools/capability.js.map +1 -0
- package/dist/tools/config.d.ts +14 -0
- package/dist/tools/config.d.ts.map +1 -0
- package/dist/tools/config.js +61 -0
- package/dist/tools/config.js.map +1 -0
- package/dist/tools/context.d.ts +22 -0
- package/dist/tools/context.d.ts.map +1 -0
- package/dist/tools/context.js +139 -0
- package/dist/tools/context.js.map +1 -0
- package/dist/tools/dispatch.d.ts +41 -0
- package/dist/tools/dispatch.d.ts.map +1 -0
- package/dist/tools/dispatch.js +380 -0
- package/dist/tools/dispatch.js.map +1 -0
- package/dist/tools/help.d.ts +44 -0
- package/dist/tools/help.d.ts.map +1 -0
- package/dist/tools/help.js +227 -0
- package/dist/tools/help.js.map +1 -0
- package/dist/tools/import.d.ts +17 -0
- package/dist/tools/import.d.ts.map +1 -0
- package/dist/tools/import.js +96 -0
- package/dist/tools/import.js.map +1 -0
- package/dist/tools/index.d.ts +12 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +13 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/log.d.ts +21 -0
- package/dist/tools/log.d.ts.map +1 -0
- package/dist/tools/log.js +93 -0
- package/dist/tools/log.js.map +1 -0
- package/dist/tools/memo.d.ts +26 -0
- package/dist/tools/memo.d.ts.map +1 -0
- package/dist/tools/memo.js +188 -0
- package/dist/tools/memo.js.map +1 -0
- package/dist/tools/node.d.ts +34 -0
- package/dist/tools/node.d.ts.map +1 -0
- package/dist/tools/node.js +328 -0
- package/dist/tools/node.js.map +1 -0
- package/dist/tools/search.d.ts +14 -0
- package/dist/tools/search.d.ts.map +1 -0
- package/dist/tools/search.js +95 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/tools/session.d.ts +22 -0
- package/dist/tools/session.d.ts.map +1 -0
- package/dist/tools/session.js +127 -0
- package/dist/tools/session.js.map +1 -0
- package/dist/tools/state.d.ts +10 -0
- package/dist/tools/state.d.ts.map +1 -0
- package/dist/tools/state.js +79 -0
- package/dist/tools/state.js.map +1 -0
- package/dist/tools/workspace.d.ts +38 -0
- package/dist/tools/workspace.d.ts.map +1 -0
- package/dist/tools/workspace.js +240 -0
- package/dist/tools/workspace.js.map +1 -0
- package/dist/types/capability.d.ts +36 -0
- package/dist/types/capability.d.ts.map +1 -0
- package/dist/types/capability.js +3 -0
- package/dist/types/capability.js.map +1 -0
- package/dist/types/confirmation.d.ts +35 -0
- package/dist/types/confirmation.d.ts.map +1 -0
- package/dist/types/confirmation.js +3 -0
- package/dist/types/confirmation.js.map +1 -0
- package/dist/types/context.d.ts +174 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/context.js +3 -0
- package/dist/types/context.js.map +1 -0
- package/dist/types/errors.d.ts +81 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +154 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/guidance.d.ts +162 -0
- package/dist/types/guidance.d.ts.map +1 -0
- package/dist/types/guidance.js +4 -0
- package/dist/types/guidance.js.map +1 -0
- package/dist/types/health.d.ts +61 -0
- package/dist/types/health.d.ts.map +1 -0
- package/dist/types/health.js +3 -0
- package/dist/types/health.js.map +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +11 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/memo.d.ts +132 -0
- package/dist/types/memo.d.ts.map +1 -0
- package/dist/types/memo.js +3 -0
- package/dist/types/memo.js.map +1 -0
- package/dist/types/node.d.ts +316 -0
- package/dist/types/node.d.ts.map +1 -0
- package/dist/types/node.js +3 -0
- package/dist/types/node.js.map +1 -0
- package/dist/types/repair.d.ts +62 -0
- package/dist/types/repair.d.ts.map +1 -0
- package/dist/types/repair.js +4 -0
- package/dist/types/repair.js.map +1 -0
- package/dist/types/search.d.ts +58 -0
- package/dist/types/search.d.ts.map +1 -0
- package/dist/types/search.js +3 -0
- package/dist/types/search.js.map +1 -0
- package/dist/types/settings.d.ts +109 -0
- package/dist/types/settings.d.ts.map +1 -0
- package/dist/types/settings.js +30 -0
- package/dist/types/settings.js.map +1 -0
- package/dist/types/workspace.d.ts +357 -0
- package/dist/types/workspace.d.ts.map +1 -0
- package/dist/types/workspace.js +3 -0
- package/dist/types/workspace.js.map +1 -0
- package/dist/utils/contentValidation.d.ts +47 -0
- package/dist/utils/contentValidation.d.ts.map +1 -0
- package/dist/utils/contentValidation.js +93 -0
- package/dist/utils/contentValidation.js.map +1 -0
- package/dist/utils/devLog.d.ts +43 -0
- package/dist/utils/devLog.d.ts.map +1 -0
- package/dist/utils/devLog.js +94 -0
- package/dist/utils/devLog.js.map +1 -0
- package/dist/utils/errorLogger.d.ts +27 -0
- package/dist/utils/errorLogger.d.ts.map +1 -0
- package/dist/utils/errorLogger.js +105 -0
- package/dist/utils/errorLogger.js.map +1 -0
- package/dist/utils/git.d.ts +123 -0
- package/dist/utils/git.d.ts.map +1 -0
- package/dist/utils/git.js +400 -0
- package/dist/utils/git.js.map +1 -0
- package/dist/utils/hash.d.ts +32 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/utils/hash.js +37 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/id.d.ts +54 -0
- package/dist/utils/id.d.ts.map +1 -0
- package/dist/utils/id.js +96 -0
- package/dist/utils/id.js.map +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +9 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.d.ts +42 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +228 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/manualChangeFormatter.d.ts +8 -0
- package/dist/utils/manualChangeFormatter.d.ts.map +1 -0
- package/dist/utils/manualChangeFormatter.js +21 -0
- package/dist/utils/manualChangeFormatter.js.map +1 -0
- package/dist/utils/paramValidator.d.ts +35 -0
- package/dist/utils/paramValidator.d.ts.map +1 -0
- package/dist/utils/paramValidator.js +214 -0
- package/dist/utils/paramValidator.js.map +1 -0
- package/dist/utils/port.d.ts +7 -0
- package/dist/utils/port.d.ts.map +1 -0
- package/dist/utils/port.js +28 -0
- package/dist/utils/port.js.map +1 -0
- package/dist/utils/processManager.d.ts +53 -0
- package/dist/utils/processManager.d.ts.map +1 -0
- package/dist/utils/processManager.js +267 -0
- package/dist/utils/processManager.js.map +1 -0
- package/dist/utils/sessionLogger.d.ts +28 -0
- package/dist/utils/sessionLogger.d.ts.map +1 -0
- package/dist/utils/sessionLogger.js +142 -0
- package/dist/utils/sessionLogger.js.map +1 -0
- package/dist/utils/time.d.ts +15 -0
- package/dist/utils/time.d.ts.map +1 -0
- package/dist/utils/time.js +32 -0
- package/dist/utils/time.js.map +1 -0
- package/dist/utils/validation.d.ts +23 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +88 -0
- package/dist/utils/validation.js.map +1 -0
- package/docs//346/227/245/345/277/227/347/263/273/347/273/237.md +389 -0
- package/docs//347/224/250/346/210/267/346/211/213/345/206/214.md +1446 -0
- package/docs//347/224/250/346/210/267/346/211/213/345/206/214/344/270/216/346/212/200/346/234/257/346/214/207/345/215/227.md +873 -0
- package/package.json +89 -0
- package/plugin/README.md +141 -0
- package/plugin/agents/xtep-executor.md +114 -0
- package/plugin/agents/xtep-reviewer.md +133 -0
- package/plugin/docs/diagnostic-guide.md +128 -0
- package/plugin/hooks/hooks.json.deprecated +70 -0
- package/plugin/scripts/cursor-hook-entry.cjs +217 -0
- package/plugin/scripts/hook-entry.cjs +663 -0
- package/plugin/scripts/openspec-import.cjs +714 -0
- package/plugin/scripts/shared/binding.cjs +98 -0
- package/plugin/scripts/shared/config.cjs +65 -0
- package/plugin/scripts/shared/context.cjs +120 -0
- package/plugin/scripts/shared/index.cjs +34 -0
- package/plugin/scripts/shared/logger.cjs +196 -0
- package/plugin/scripts/shared/reminder.cjs +261 -0
- package/plugin/scripts/shared/utils.cjs +62 -0
- package/plugin/scripts/shared/workspace.cjs +322 -0
- package/plugin/skills/aligning-intent/SKILL.md +275 -0
- package/plugin/skills/analyzing-measurements/SKILL.md +223 -0
- package/plugin/skills/bootstrapping-workspace/SKILL.md +260 -0
- package/plugin/skills/designing-solutions/SKILL.md +363 -0
- package/plugin/skills/diagnosing-issues/SKILL.md +219 -0
- package/plugin/skills/discovering-context/SKILL.md +283 -0
- package/plugin/skills/dispatching-parent/SKILL.md +399 -0
- package/plugin/skills/executing-task/SKILL.md +340 -0
- package/plugin/skills/memo-create/SKILL.md +222 -0
- package/plugin/skills/planning-verification/SKILL.md +245 -0
- package/plugin/skills/preparing-dispatch/SKILL.md +299 -0
- package/plugin/skills/researching-tech/SKILL.md +223 -0
- package/plugin/skills/reviewing-quality/SKILL.md +354 -0
- package/plugin/skills/reviewing-spec/SKILL.md +333 -0
- package/plugin/skills/starting-info-flow/SKILL.md +196 -0
- package/web/README.md +5 -0
- package//351/205/215/347/275/256/346/226/271/345/274/217.md +330 -0
|
@@ -0,0 +1,663 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Xtep-Workspace Hook 入口脚本 (Claude Code 版)
|
|
4
|
+
*
|
|
5
|
+
* 此脚本作为 Claude Code Hook 的入口点,负责:
|
|
6
|
+
* 1. SessionStart 时始终注入 sessionId(让 AI 知道自己的会话 ID)
|
|
7
|
+
* 2. 如果已绑定工作区,同时注入工作区上下文
|
|
8
|
+
* 3. UserPromptSubmit 时检测工作区关键词,未绑定则提醒 AI 绑定
|
|
9
|
+
*
|
|
10
|
+
* 使用方式:由 Claude Code 的 Hook 机制自动调用
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const {
|
|
14
|
+
readStdin,
|
|
15
|
+
getSessionBinding,
|
|
16
|
+
containsWorkspaceKeywords,
|
|
17
|
+
getFullWorkspaceContext,
|
|
18
|
+
generateSessionIdContext,
|
|
19
|
+
generateBindingReminder,
|
|
20
|
+
analyzeNodeStatus,
|
|
21
|
+
shouldThrottle,
|
|
22
|
+
updateLastReminder,
|
|
23
|
+
logHook,
|
|
24
|
+
logHookOutput,
|
|
25
|
+
getNodeGraph,
|
|
26
|
+
getWorkspacesByCwd
|
|
27
|
+
} = require('./shared/index.cjs');
|
|
28
|
+
|
|
29
|
+
// ============================================================================
|
|
30
|
+
// Claude Code 专用响应格式
|
|
31
|
+
// ============================================================================
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 输出 Claude Code Hook 响应
|
|
35
|
+
* @param {string} eventType - 事件类型
|
|
36
|
+
* @param {string} context - 上下文内容
|
|
37
|
+
*/
|
|
38
|
+
function outputHookResponse(eventType, context) {
|
|
39
|
+
const response = {
|
|
40
|
+
hookSpecificOutput: {
|
|
41
|
+
hookEventName: eventType,
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
if (context) {
|
|
46
|
+
response.hookSpecificOutput.additionalContext = context;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
console.log(JSON.stringify(response));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ============================================================================
|
|
53
|
+
// 事件处理
|
|
54
|
+
// ============================================================================
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 生成工作区绑定建议提示
|
|
58
|
+
* @param {string} sessionId - 会话 ID
|
|
59
|
+
* @param {Array} matchedWorkspaces - 匹配的工作区列表
|
|
60
|
+
* @returns {string} 建议提示内容
|
|
61
|
+
*/
|
|
62
|
+
function generateBindingSuggestion(sessionId, matchedWorkspaces) {
|
|
63
|
+
const sessionContext = generateSessionIdContext(sessionId, 'claude-code');
|
|
64
|
+
|
|
65
|
+
// 生成工作区列表
|
|
66
|
+
const workspaceList = matchedWorkspaces.map(ws => {
|
|
67
|
+
const goalInfo = ws.goal ? `\n 目标: ${ws.goal.slice(0, 80)}${ws.goal.length > 80 ? '...' : ''}` : '';
|
|
68
|
+
return `- **${ws.name}** (${ws.id})${goalInfo}`;
|
|
69
|
+
}).join('\n');
|
|
70
|
+
|
|
71
|
+
const suggestion = `${sessionContext}
|
|
72
|
+
|
|
73
|
+
<xtep-workspace-suggestion>
|
|
74
|
+
## 检测到匹配的工作区
|
|
75
|
+
|
|
76
|
+
当前目录下存在以下活跃工作区:
|
|
77
|
+
|
|
78
|
+
${workspaceList}
|
|
79
|
+
|
|
80
|
+
**建议**: 如果本次会话涉及以上工作区的任务,请考虑使用 \`session_bind\` 绑定工作区以获取完整上下文。
|
|
81
|
+
|
|
82
|
+
绑定示例:
|
|
83
|
+
\`\`\`
|
|
84
|
+
session_bind(workspaceId: "${matchedWorkspaces[0].id}")
|
|
85
|
+
\`\`\`
|
|
86
|
+
|
|
87
|
+
如果本次会话与工作区无关,可以忽略此建议。
|
|
88
|
+
</xtep-workspace-suggestion>`;
|
|
89
|
+
|
|
90
|
+
return suggestion;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 处理 SessionStart 事件
|
|
95
|
+
* 始终注入 sessionId,如果已绑定则同时注入工作区上下文
|
|
96
|
+
* 如果未绑定但检测到匹配工作区,则提示绑定建议
|
|
97
|
+
*/
|
|
98
|
+
function handleSessionStart(sessionId, binding, input) {
|
|
99
|
+
let context = '';
|
|
100
|
+
let logDetails = {};
|
|
101
|
+
|
|
102
|
+
if (binding) {
|
|
103
|
+
// 已绑定:注入工作区上下文
|
|
104
|
+
context = getFullWorkspaceContext(binding);
|
|
105
|
+
logDetails = { bound: true, workspaceId: binding.workspaceId };
|
|
106
|
+
} else {
|
|
107
|
+
// 未绑定:检查是否有匹配的工作区
|
|
108
|
+
const cwd = input?.cwd || process.cwd();
|
|
109
|
+
const matchedWorkspaces = getWorkspacesByCwd(cwd);
|
|
110
|
+
|
|
111
|
+
if (matchedWorkspaces.length > 0) {
|
|
112
|
+
// 有匹配的工作区:生成绑定建议
|
|
113
|
+
context = generateBindingSuggestion(sessionId, matchedWorkspaces);
|
|
114
|
+
logDetails = {
|
|
115
|
+
bound: false,
|
|
116
|
+
matchedCount: matchedWorkspaces.length,
|
|
117
|
+
matchedWorkspaces: matchedWorkspaces.slice(0, 5).map(ws => ws.id)
|
|
118
|
+
};
|
|
119
|
+
} else {
|
|
120
|
+
// 无匹配工作区:仅注入 sessionId
|
|
121
|
+
context = generateSessionIdContext(sessionId, 'claude-code');
|
|
122
|
+
logDetails = { bound: false, matchedCount: 0 };
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (context) {
|
|
127
|
+
logHookOutput(sessionId, 'SessionStart', 'output', logDetails, context);
|
|
128
|
+
outputHookResponse('SessionStart', context);
|
|
129
|
+
} else {
|
|
130
|
+
logHookOutput(sessionId, 'SessionStart', 'silent', logDetails);
|
|
131
|
+
process.exit(0);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* 处理 PostToolUse 事件
|
|
137
|
+
* 1. MCP 调用失败时提醒查看 schema
|
|
138
|
+
* 2. Edit/Write 成功后提醒记录日志
|
|
139
|
+
* 3. Bash 失败后提醒记录问题
|
|
140
|
+
*/
|
|
141
|
+
function handlePostToolUse(sessionId, binding, input) {
|
|
142
|
+
const { tool_name, tool_response, tool_input } = input;
|
|
143
|
+
|
|
144
|
+
// 根据工具类型分发处理
|
|
145
|
+
if (tool_name?.startsWith('mcp__xtep-workspace__')) {
|
|
146
|
+
handleMcpToolUse(sessionId, tool_name, tool_response);
|
|
147
|
+
} else if (tool_name === 'Edit' || tool_name === 'Write') {
|
|
148
|
+
handleFileToolUse(sessionId, binding, tool_name, tool_input, tool_response);
|
|
149
|
+
} else if (tool_name === 'Bash') {
|
|
150
|
+
handleBashToolUse(sessionId, binding, tool_input, tool_response);
|
|
151
|
+
} else if (tool_name === 'TodoWrite') {
|
|
152
|
+
handleTodoWriteToolUse(sessionId, binding, tool_input, tool_response);
|
|
153
|
+
} else {
|
|
154
|
+
process.exit(0);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* 处理 MCP 工具调用
|
|
160
|
+
*/
|
|
161
|
+
function handleMcpToolUse(sessionId, tool_name, tool_response) {
|
|
162
|
+
const responseStr = typeof tool_response === 'string'
|
|
163
|
+
? tool_response
|
|
164
|
+
: JSON.stringify(tool_response || '');
|
|
165
|
+
|
|
166
|
+
const errorPatterns = [
|
|
167
|
+
'undefined',
|
|
168
|
+
'无效',
|
|
169
|
+
'INVALID_PARAMS',
|
|
170
|
+
'不存在',
|
|
171
|
+
'缺少必填参数',
|
|
172
|
+
'required'
|
|
173
|
+
];
|
|
174
|
+
|
|
175
|
+
const isError = tool_response?.isError ||
|
|
176
|
+
errorPatterns.some(pattern => responseStr.includes(pattern));
|
|
177
|
+
const toolPath = tool_name.replace('mcp__xtep-workspace__', 'xtep-workspace/');
|
|
178
|
+
|
|
179
|
+
if (isError) {
|
|
180
|
+
const reminder = `<xtep-mcp-error-hint>
|
|
181
|
+
⚠️ MCP 调用可能使用了错误的参数名。
|
|
182
|
+
|
|
183
|
+
请运行以下命令查看正确的参数 schema:
|
|
184
|
+
\`\`\`bash
|
|
185
|
+
mcp-cli info ${toolPath}
|
|
186
|
+
\`\`\`
|
|
187
|
+
|
|
188
|
+
然后使用正确的参数名重试。
|
|
189
|
+
</xtep-mcp-error-hint>`;
|
|
190
|
+
|
|
191
|
+
logHookOutput(sessionId, 'PostToolUse', 'output', {
|
|
192
|
+
tool: toolPath,
|
|
193
|
+
error: true,
|
|
194
|
+
response: responseStr.slice(0, 200)
|
|
195
|
+
}, reminder);
|
|
196
|
+
|
|
197
|
+
outputHookResponse('PostToolUse', reminder);
|
|
198
|
+
} else {
|
|
199
|
+
logHookOutput(sessionId, 'PostToolUse', 'silent', {
|
|
200
|
+
tool: toolPath,
|
|
201
|
+
error: false
|
|
202
|
+
});
|
|
203
|
+
process.exit(0);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* 处理文件编辑工具 (Edit/Write)
|
|
209
|
+
* 成功后提醒记录日志
|
|
210
|
+
*/
|
|
211
|
+
function handleFileToolUse(sessionId, binding, tool_name, tool_input, tool_response) {
|
|
212
|
+
const filePath = tool_input?.file_path || '';
|
|
213
|
+
const fileName = filePath.split('/').pop() || filePath;
|
|
214
|
+
|
|
215
|
+
// 未绑定工作区时不提醒
|
|
216
|
+
if (!binding?.workspaceId) {
|
|
217
|
+
logHookOutput(sessionId, 'PostToolUse', 'silent', {
|
|
218
|
+
tool: tool_name,
|
|
219
|
+
file: fileName,
|
|
220
|
+
reason: 'not_bound'
|
|
221
|
+
});
|
|
222
|
+
process.exit(0);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// 检查是否成功
|
|
227
|
+
const isSuccess = tool_response?.success !== false;
|
|
228
|
+
if (!isSuccess) {
|
|
229
|
+
logHookOutput(sessionId, 'PostToolUse', 'silent', {
|
|
230
|
+
tool: tool_name,
|
|
231
|
+
file: fileName,
|
|
232
|
+
reason: 'not_success'
|
|
233
|
+
});
|
|
234
|
+
process.exit(0);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// 节流检查:file_changed 类型,10秒内不重复提醒
|
|
239
|
+
if (shouldThrottle(binding, 'file_changed', 10000)) {
|
|
240
|
+
logHookOutput(sessionId, 'PostToolUse', 'throttled', {
|
|
241
|
+
tool: tool_name,
|
|
242
|
+
file: fileName,
|
|
243
|
+
reminderType: 'file_changed'
|
|
244
|
+
});
|
|
245
|
+
process.exit(0);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const reminder = `<xtep-post-tool-reminder>
|
|
250
|
+
📝 文件 \`${fileName}\` 已${tool_name === 'Edit' ? '编辑' : '写入'}。
|
|
251
|
+
|
|
252
|
+
**请使用 \`log_append\` 记录本次变更**,说明改动内容和目的。
|
|
253
|
+
</xtep-post-tool-reminder>`;
|
|
254
|
+
|
|
255
|
+
updateLastReminder(sessionId, 'file_changed');
|
|
256
|
+
|
|
257
|
+
logHookOutput(sessionId, 'PostToolUse', 'output', {
|
|
258
|
+
tool: tool_name,
|
|
259
|
+
file: fileName,
|
|
260
|
+
reminderType: 'file_changed'
|
|
261
|
+
}, reminder);
|
|
262
|
+
|
|
263
|
+
outputHookResponse('PostToolUse', reminder);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* 处理 Bash 命令
|
|
268
|
+
* 失败后提醒记录问题
|
|
269
|
+
*/
|
|
270
|
+
function handleBashToolUse(sessionId, binding, tool_input, tool_response) {
|
|
271
|
+
const command = tool_input?.command || '';
|
|
272
|
+
const cmdPreview = command.length > 50 ? command.slice(0, 50) + '...' : command;
|
|
273
|
+
|
|
274
|
+
// 未绑定工作区时不提醒
|
|
275
|
+
if (!binding?.workspaceId) {
|
|
276
|
+
logHookOutput(sessionId, 'PostToolUse', 'silent', {
|
|
277
|
+
tool: 'Bash',
|
|
278
|
+
command: cmdPreview,
|
|
279
|
+
reason: 'not_bound'
|
|
280
|
+
});
|
|
281
|
+
process.exit(0);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// 检查是否失败
|
|
286
|
+
const responseStr = typeof tool_response === 'string'
|
|
287
|
+
? tool_response
|
|
288
|
+
: JSON.stringify(tool_response || '');
|
|
289
|
+
|
|
290
|
+
// 检测错误:exit code 非 0,或包含错误关键词
|
|
291
|
+
const exitCode = tool_response?.exit_code ?? tool_response?.exitCode;
|
|
292
|
+
const hasExitError = exitCode !== undefined && exitCode !== 0;
|
|
293
|
+
|
|
294
|
+
const errorKeywords = ['error', 'Error', 'ERROR', 'failed', 'Failed', 'FAILED',
|
|
295
|
+
'exception', 'Exception', 'ENOENT', 'EACCES', 'Permission denied',
|
|
296
|
+
'command not found', 'No such file'];
|
|
297
|
+
const hasErrorKeyword = errorKeywords.some(kw => responseStr.includes(kw));
|
|
298
|
+
|
|
299
|
+
const isError = hasExitError || hasErrorKeyword;
|
|
300
|
+
|
|
301
|
+
if (!isError) {
|
|
302
|
+
logHookOutput(sessionId, 'PostToolUse', 'silent', {
|
|
303
|
+
tool: 'Bash',
|
|
304
|
+
command: cmdPreview,
|
|
305
|
+
reason: 'no_error'
|
|
306
|
+
});
|
|
307
|
+
process.exit(0);
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// 节流检查:bash_error 类型,5秒内不重复提醒
|
|
312
|
+
if (shouldThrottle(binding, 'bash_error', 5000)) {
|
|
313
|
+
logHookOutput(sessionId, 'PostToolUse', 'throttled', {
|
|
314
|
+
tool: 'Bash',
|
|
315
|
+
command: cmdPreview,
|
|
316
|
+
exitCode,
|
|
317
|
+
reminderType: 'bash_error'
|
|
318
|
+
});
|
|
319
|
+
process.exit(0);
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const reminder = `<xtep-post-tool-reminder>
|
|
324
|
+
⚠️ 命令执行出错${hasExitError ? ` (exit code: ${exitCode})` : ''}。
|
|
325
|
+
|
|
326
|
+
命令: \`${cmdPreview}\`
|
|
327
|
+
|
|
328
|
+
**请使用 \`problem_update\` 记录问题**,描述错误原因和解决思路。
|
|
329
|
+
</xtep-post-tool-reminder>`;
|
|
330
|
+
|
|
331
|
+
updateLastReminder(sessionId, 'bash_error');
|
|
332
|
+
|
|
333
|
+
logHookOutput(sessionId, 'PostToolUse', 'output', {
|
|
334
|
+
tool: 'Bash',
|
|
335
|
+
command: cmdPreview,
|
|
336
|
+
exitCode,
|
|
337
|
+
reminderType: 'bash_error'
|
|
338
|
+
}, reminder);
|
|
339
|
+
|
|
340
|
+
outputHookResponse('PostToolUse', reminder);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* 处理 TodoWrite 工具
|
|
345
|
+
* 提醒 AI 应该在工作区创建执行节点跟踪任务
|
|
346
|
+
*
|
|
347
|
+
* 注意:此提醒【不需要节流】,每次都提醒
|
|
348
|
+
* 原因:AI 可能忘记同步到工作区,用户在 WebUI 看不到本地 Todo 进度
|
|
349
|
+
*/
|
|
350
|
+
function handleTodoWriteToolUse(sessionId, binding, tool_input, tool_response) {
|
|
351
|
+
// 统计 todo 数量
|
|
352
|
+
const todos = tool_input?.todos || [];
|
|
353
|
+
const pendingCount = todos.filter(t => t.status === 'pending').length;
|
|
354
|
+
const inProgressCount = todos.filter(t => t.status === 'in_progress').length;
|
|
355
|
+
|
|
356
|
+
// 未绑定工作区时不提醒
|
|
357
|
+
if (!binding?.workspaceId) {
|
|
358
|
+
logHookOutput(sessionId, 'PostToolUse', 'silent', {
|
|
359
|
+
tool: 'TodoWrite',
|
|
360
|
+
todoCount: todos.length,
|
|
361
|
+
reason: 'not_bound'
|
|
362
|
+
});
|
|
363
|
+
process.exit(0);
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// 检查是否成功
|
|
368
|
+
const isSuccess = tool_response?.success !== false;
|
|
369
|
+
if (!isSuccess) {
|
|
370
|
+
logHookOutput(sessionId, 'PostToolUse', 'silent', {
|
|
371
|
+
tool: 'TodoWrite',
|
|
372
|
+
todoCount: todos.length,
|
|
373
|
+
reason: 'not_success'
|
|
374
|
+
});
|
|
375
|
+
process.exit(0);
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const reminder = `<xtep-post-tool-reminder>
|
|
380
|
+
📋 TodoWrite 已更新 (${todos.length} 项,${inProgressCount} 进行中,${pendingCount} 待办)。
|
|
381
|
+
|
|
382
|
+
**注意:TodoWrite 是本地工具,用户在 WebUI 看不到进度。**
|
|
383
|
+
**MUST** 评估是否需要同步到工作区(创建节点或使用 log_append 记录)。
|
|
384
|
+
</xtep-post-tool-reminder>`;
|
|
385
|
+
|
|
386
|
+
logHookOutput(sessionId, 'PostToolUse', 'output', {
|
|
387
|
+
tool: 'TodoWrite',
|
|
388
|
+
todoCount: todos.length,
|
|
389
|
+
pending: pendingCount,
|
|
390
|
+
inProgress: inProgressCount,
|
|
391
|
+
reminderType: 'todo_write'
|
|
392
|
+
}, reminder);
|
|
393
|
+
|
|
394
|
+
outputHookResponse('PostToolUse', reminder);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* 处理 Stop 事件
|
|
399
|
+
* 分析 AI 响应中是否遇到错误/阻碍,提醒记录问题
|
|
400
|
+
*/
|
|
401
|
+
function handleStop(sessionId, binding, input) {
|
|
402
|
+
const fs = require('node:fs');
|
|
403
|
+
|
|
404
|
+
// 未绑定工作区时不处理
|
|
405
|
+
if (!binding?.workspaceId) {
|
|
406
|
+
logHookOutput(sessionId, 'Stop', 'silent', { reason: 'not_bound' });
|
|
407
|
+
process.exit(0);
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// 如果已经因为 Stop hook 继续过,避免无限循环
|
|
412
|
+
if (input.stop_hook_active) {
|
|
413
|
+
logHookOutput(sessionId, 'Stop', 'silent', { reason: 'stop_hook_active' });
|
|
414
|
+
process.exit(0);
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// 节流检查:stop_error 类型,30秒内不重复提醒
|
|
419
|
+
if (shouldThrottle(binding, 'stop_error', 30000)) {
|
|
420
|
+
logHookOutput(sessionId, 'Stop', 'throttled', { reminderType: 'stop_error' });
|
|
421
|
+
process.exit(0);
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// 读取 transcript 分析错误
|
|
426
|
+
const transcriptPath = input.transcript_path;
|
|
427
|
+
if (!transcriptPath) {
|
|
428
|
+
logHookOutput(sessionId, 'Stop', 'silent', { reason: 'no_transcript' });
|
|
429
|
+
process.exit(0);
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
try {
|
|
434
|
+
const content = fs.readFileSync(transcriptPath, 'utf-8');
|
|
435
|
+
const lines = content.trim().split('\n');
|
|
436
|
+
|
|
437
|
+
// 分析最后 10 条消息
|
|
438
|
+
const recentLines = lines.slice(-10);
|
|
439
|
+
let errorContext = null;
|
|
440
|
+
|
|
441
|
+
// 错误/阻碍的检测模式
|
|
442
|
+
const errorPatterns = [
|
|
443
|
+
/遇到了?(错误|问题|异常|失败)/,
|
|
444
|
+
/出现了?(错误|问题|异常|失败)/,
|
|
445
|
+
/发现了?(错误|问题|bug|Bug|BUG)/,
|
|
446
|
+
/(错误|问题|异常)[::]/,
|
|
447
|
+
/无法(完成|执行|实现|解决)/,
|
|
448
|
+
/不能(正常|成功)/,
|
|
449
|
+
/(失败|报错|异常|崩溃)/,
|
|
450
|
+
/Error:|error:|ERROR:/,
|
|
451
|
+
/Exception:|exception:/,
|
|
452
|
+
/failed|Failed|FAILED/,
|
|
453
|
+
/blocked|Blocked|阻塞/,
|
|
454
|
+
/卡住了|卡在/,
|
|
455
|
+
/需要.*帮助/,
|
|
456
|
+
/不确定.*如何/
|
|
457
|
+
];
|
|
458
|
+
|
|
459
|
+
for (const line of recentLines) {
|
|
460
|
+
try {
|
|
461
|
+
const msg = JSON.parse(line);
|
|
462
|
+
// 只分析 assistant 的消息
|
|
463
|
+
if (msg.role !== 'assistant') continue;
|
|
464
|
+
|
|
465
|
+
const text = typeof msg.content === 'string'
|
|
466
|
+
? msg.content
|
|
467
|
+
: JSON.stringify(msg.content || '');
|
|
468
|
+
|
|
469
|
+
for (const pattern of errorPatterns) {
|
|
470
|
+
if (pattern.test(text)) {
|
|
471
|
+
// 提取错误上下文(前后 50 字符)
|
|
472
|
+
const match = text.match(pattern);
|
|
473
|
+
if (match) {
|
|
474
|
+
const idx = match.index || 0;
|
|
475
|
+
const start = Math.max(0, idx - 30);
|
|
476
|
+
const end = Math.min(text.length, idx + match[0].length + 50);
|
|
477
|
+
errorContext = text.slice(start, end).replace(/\n/g, ' ').trim();
|
|
478
|
+
if (start > 0) errorContext = '...' + errorContext;
|
|
479
|
+
if (end < text.length) errorContext = errorContext + '...';
|
|
480
|
+
break;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
if (errorContext) break;
|
|
485
|
+
} catch {
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
if (errorContext) {
|
|
491
|
+
updateLastReminder(sessionId, 'stop_error');
|
|
492
|
+
|
|
493
|
+
// 使用 decision: block 来提醒 AI
|
|
494
|
+
const blockReason = `<xtep-error-detected>
|
|
495
|
+
⚠️ 检测到可能遇到了问题或阻碍。
|
|
496
|
+
|
|
497
|
+
上下文: "${errorContext}"
|
|
498
|
+
|
|
499
|
+
**MUST** 使用 \`problem_update\` 记录当前问题和下一步计划。
|
|
500
|
+
</xtep-error-detected>`;
|
|
501
|
+
|
|
502
|
+
logHookOutput(sessionId, 'Stop', 'output', {
|
|
503
|
+
errorDetected: true,
|
|
504
|
+
context: errorContext.slice(0, 100),
|
|
505
|
+
reminderType: 'stop_error'
|
|
506
|
+
}, blockReason);
|
|
507
|
+
|
|
508
|
+
const response = {
|
|
509
|
+
decision: 'block',
|
|
510
|
+
reason: blockReason
|
|
511
|
+
};
|
|
512
|
+
console.log(JSON.stringify(response));
|
|
513
|
+
} else {
|
|
514
|
+
logHookOutput(sessionId, 'Stop', 'silent', { reason: 'no_error_detected' });
|
|
515
|
+
process.exit(0);
|
|
516
|
+
}
|
|
517
|
+
} catch {
|
|
518
|
+
logHookOutput(sessionId, 'Stop', 'silent', { reason: 'read_error' });
|
|
519
|
+
process.exit(0);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* 处理 UserPromptSubmit 事件
|
|
525
|
+
* 已绑定时进行智能提醒,未绑定时检测关键词提醒绑定
|
|
526
|
+
*/
|
|
527
|
+
function handleUserPromptSubmit(sessionId, binding, input) {
|
|
528
|
+
const userPrompt = input.prompt || '';
|
|
529
|
+
const promptPreview = userPrompt.slice(0, 100) + (userPrompt.length > 100 ? '...' : '');
|
|
530
|
+
|
|
531
|
+
// 已绑定:进行智能提醒分析
|
|
532
|
+
if (binding && binding.workspaceId) {
|
|
533
|
+
// 优先从 graph.currentFocus 获取焦点节点(权威来源)
|
|
534
|
+
const graph = getNodeGraph(binding.workspaceId);
|
|
535
|
+
const focusNodeId = graph?.currentFocus || binding.focusedNodeId;
|
|
536
|
+
|
|
537
|
+
if (focusNodeId) {
|
|
538
|
+
// 分析节点状态
|
|
539
|
+
const reminderInfo = analyzeNodeStatus(binding.workspaceId, focusNodeId);
|
|
540
|
+
|
|
541
|
+
if (reminderInfo) {
|
|
542
|
+
// 检查是否应该节流
|
|
543
|
+
if (shouldThrottle(binding, reminderInfo.type)) {
|
|
544
|
+
// 被节流,记录但不输出
|
|
545
|
+
logHookOutput(sessionId, 'UserPromptSubmit', 'throttled', {
|
|
546
|
+
bound: true,
|
|
547
|
+
workspaceId: binding.workspaceId,
|
|
548
|
+
focusNodeId,
|
|
549
|
+
reminderType: reminderInfo.type,
|
|
550
|
+
prompt: promptPreview
|
|
551
|
+
});
|
|
552
|
+
process.exit(0);
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// 更新上次提醒记录
|
|
557
|
+
updateLastReminder(sessionId, reminderInfo.type);
|
|
558
|
+
|
|
559
|
+
// 输出智能提醒
|
|
560
|
+
const reminderContent = `<xtep-smart-reminder>\n${reminderInfo.message}\n</xtep-smart-reminder>`;
|
|
561
|
+
|
|
562
|
+
logHookOutput(sessionId, 'UserPromptSubmit', 'output', {
|
|
563
|
+
bound: true,
|
|
564
|
+
workspaceId: binding.workspaceId,
|
|
565
|
+
focusNodeId,
|
|
566
|
+
reminderType: reminderInfo.type,
|
|
567
|
+
prompt: promptPreview
|
|
568
|
+
}, reminderContent);
|
|
569
|
+
|
|
570
|
+
outputHookResponse('UserPromptSubmit', reminderContent);
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// 无需提醒,静默退出
|
|
576
|
+
logHookOutput(sessionId, 'UserPromptSubmit', 'silent', {
|
|
577
|
+
bound: true,
|
|
578
|
+
workspaceId: binding.workspaceId,
|
|
579
|
+
focusNodeId: focusNodeId || null,
|
|
580
|
+
reason: focusNodeId ? 'no_reminder_needed' : 'no_focus_node',
|
|
581
|
+
prompt: promptPreview
|
|
582
|
+
});
|
|
583
|
+
process.exit(0);
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// 未绑定:检测用户消息是否涉及工作区
|
|
588
|
+
const hasKeywords = containsWorkspaceKeywords(userPrompt);
|
|
589
|
+
|
|
590
|
+
if (hasKeywords) {
|
|
591
|
+
// 检测到工作区关键词,提醒绑定
|
|
592
|
+
const reminder = generateBindingReminder(sessionId, 'claude-code');
|
|
593
|
+
|
|
594
|
+
logHookOutput(sessionId, 'UserPromptSubmit', 'output', {
|
|
595
|
+
bound: false,
|
|
596
|
+
keywordDetected: true,
|
|
597
|
+
prompt: promptPreview
|
|
598
|
+
}, reminder);
|
|
599
|
+
|
|
600
|
+
outputHookResponse('UserPromptSubmit', reminder);
|
|
601
|
+
} else {
|
|
602
|
+
// 普通对话,静默退出
|
|
603
|
+
logHookOutput(sessionId, 'UserPromptSubmit', 'silent', {
|
|
604
|
+
bound: false,
|
|
605
|
+
keywordDetected: false,
|
|
606
|
+
prompt: promptPreview
|
|
607
|
+
});
|
|
608
|
+
process.exit(0);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// ============================================================================
|
|
613
|
+
// 主逻辑
|
|
614
|
+
// ============================================================================
|
|
615
|
+
|
|
616
|
+
async function main() {
|
|
617
|
+
const eventType = process.argv[2];
|
|
618
|
+
|
|
619
|
+
if (!eventType) {
|
|
620
|
+
// 无事件类型,静默退出
|
|
621
|
+
process.exit(0);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
// 读取 Hook 输入
|
|
625
|
+
const input = await readStdin();
|
|
626
|
+
const sessionId = input.session_id;
|
|
627
|
+
|
|
628
|
+
if (!sessionId) {
|
|
629
|
+
// 无会话 ID,静默退出
|
|
630
|
+
process.exit(0);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
// 检查会话绑定
|
|
634
|
+
const binding = getSessionBinding(sessionId);
|
|
635
|
+
|
|
636
|
+
// 根据事件类型处理
|
|
637
|
+
switch (eventType) {
|
|
638
|
+
case 'SessionStart':
|
|
639
|
+
handleSessionStart(sessionId, binding, input);
|
|
640
|
+
break;
|
|
641
|
+
|
|
642
|
+
case 'UserPromptSubmit':
|
|
643
|
+
handleUserPromptSubmit(sessionId, binding, input);
|
|
644
|
+
break;
|
|
645
|
+
|
|
646
|
+
case 'PostToolUse':
|
|
647
|
+
handlePostToolUse(sessionId, binding, input);
|
|
648
|
+
break;
|
|
649
|
+
|
|
650
|
+
case 'Stop':
|
|
651
|
+
handleStop(sessionId, binding, input);
|
|
652
|
+
break;
|
|
653
|
+
|
|
654
|
+
default:
|
|
655
|
+
// 未知事件,静默退出
|
|
656
|
+
process.exit(0);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
main().catch(() => {
|
|
661
|
+
// 任何错误都静默退出,不干扰用户
|
|
662
|
+
process.exit(0);
|
|
663
|
+
});
|