zero-workspace 0.0.2
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 +18 -0
- package/README.md +187 -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 +94 -0
- package/plugin/README.md +141 -0
- package/plugin/agents/zero-executor.md +114 -0
- package/plugin/agents/zero-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/web/dist/assets/DocsView-Bls_Vjsr.css +1 -0
- package/web/dist/assets/DocsView-Cxc0B63r.js +1447 -0
- package/web/dist/assets/HomeView-C7df9thb.js +9 -0
- package/web/dist/assets/HomeView-ufUdnfHk.css +1 -0
- package/web/dist/assets/MarkdownContent-DXp6CtSP.js +308 -0
- package/web/dist/assets/MarkdownContent-NFqiOBLH.css +1 -0
- package/web/dist/assets/NotFoundView-BYX1oZAn.css +1 -0
- package/web/dist/assets/NotFoundView-zrc0lT9q.js +1 -0
- package/web/dist/assets/WorkspaceView-BckqgNcX.js +27 -0
- package/web/dist/assets/WorkspaceView-J1dgpYMx.css +1 -0
- package/web/dist/assets/WsConfirmDialog-C1CvL4my.css +1 -0
- package/web/dist/assets/WsConfirmDialog-gLEP7uBD.js +4 -0
- package/web/dist/assets/arc-DPkKTkUT.js +1 -0
- package/web/dist/assets/architectureDiagram-VXUJARFQ-CEGpqUlZ.js +36 -0
- package/web/dist/assets/blockDiagram-VD42YOAC-Bv-mqdQH.js +122 -0
- package/web/dist/assets/c4Diagram-YG6GDRKO-DRyPatZ_.js +10 -0
- package/web/dist/assets/channel-B84mKLDZ.js +1 -0
- package/web/dist/assets/chunk-4BX2VUAB-c7DivX0u.js +1 -0
- package/web/dist/assets/chunk-55IACEB6-CGKTaLlo.js +1 -0
- package/web/dist/assets/chunk-B4BG7PRW-Czhx5Q_P.js +165 -0
- package/web/dist/assets/chunk-DI55MBZ5-CQVA7hcZ.js +220 -0
- package/web/dist/assets/chunk-FMBD7UC4-hEiPmi7V.js +15 -0
- package/web/dist/assets/chunk-QN33PNHL-rL6yYI-E.js +1 -0
- package/web/dist/assets/chunk-QZHKN3VN-BRyHBBzq.js +1 -0
- package/web/dist/assets/chunk-TZMSLE5B-D4PXmTz9.js +1 -0
- package/web/dist/assets/classDiagram-2ON5EDUG-CNn53ohi.js +1 -0
- package/web/dist/assets/classDiagram-v2-WZHVMYZB-CNn53ohi.js +1 -0
- package/web/dist/assets/cose-bilkent-S5V4N54A-BAREnRga.js +1 -0
- package/web/dist/assets/cytoscape.esm-BnkdMOzK.js +321 -0
- package/web/dist/assets/dagre-6UL2VRFP-DaYzb3MT.js +4 -0
- package/web/dist/assets/defaultLocale-C4B-KCzX.js +1 -0
- package/web/dist/assets/diagram-PSM6KHXK-BFltDqvd.js +24 -0
- package/web/dist/assets/diagram-QEK2KX5R-CR4VU2La.js +43 -0
- package/web/dist/assets/diagram-S2PKOQOG-0UfIeT-1.js +24 -0
- package/web/dist/assets/erDiagram-Q2GNP2WA-Bo17Xmng.js +60 -0
- package/web/dist/assets/flowDiagram-NV44I4VS-CzqhQp8s.js +162 -0
- package/web/dist/assets/ganttDiagram-JELNMOA3-TXwXtUcq.js +267 -0
- package/web/dist/assets/gitGraphDiagram-NY62KEGX-CoFQTy9O.js +65 -0
- package/web/dist/assets/graph-CIQcRIVd.js +1 -0
- package/web/dist/assets/index-BgLd_o_M.css +1 -0
- package/web/dist/assets/index-Cd_J3fZn.js +30 -0
- package/web/dist/assets/infoDiagram-WHAUD3N6-Dq0xXfVu.js +2 -0
- package/web/dist/assets/init-Gi6I4Gst.js +1 -0
- package/web/dist/assets/journeyDiagram-XKPGCS4Q-jIg5BOfC.js +139 -0
- package/web/dist/assets/kanban-definition-3W4ZIXB7-D2giu6aZ.js +89 -0
- package/web/dist/assets/katex-XbL3y5x-.js +261 -0
- package/web/dist/assets/layout-Bm-XCM-8.js +1 -0
- package/web/dist/assets/linear-FbekP9OZ.js +1 -0
- package/web/dist/assets/min-BrRCpYmF.js +1 -0
- package/web/dist/assets/mindmap-definition-VGOIOE7T-o-4ubbY9.js +68 -0
- package/web/dist/assets/noto-emoji-0-400-normal-BTQbhB77.woff +0 -0
- package/web/dist/assets/noto-emoji-0-400-normal-DHdy6Uhy.woff2 +0 -0
- package/web/dist/assets/noto-emoji-1-400-normal-0IvkdXBB.woff +0 -0
- package/web/dist/assets/noto-emoji-1-400-normal-BY9OovbM.woff2 +0 -0
- package/web/dist/assets/noto-emoji-10-400-normal-D9w4QCof.woff2 +0 -0
- package/web/dist/assets/noto-emoji-10-400-normal-DtCumcZR.woff +0 -0
- package/web/dist/assets/noto-emoji-11-400-normal-BboTlyvx.woff +0 -0
- package/web/dist/assets/noto-emoji-12-400-normal-BB5pgBKj.woff2 +0 -0
- package/web/dist/assets/noto-emoji-12-400-normal-g186qhiA.woff +0 -0
- package/web/dist/assets/noto-emoji-2-400-normal-BKCR1azW.woff2 +0 -0
- package/web/dist/assets/noto-emoji-2-400-normal-BYH0KhDr.woff +0 -0
- package/web/dist/assets/noto-emoji-3-400-normal-CnPTUeEK.woff +0 -0
- package/web/dist/assets/noto-emoji-3-400-normal-TrTb2VQM.woff2 +0 -0
- package/web/dist/assets/noto-emoji-4-400-normal-BxD0KVdj.woff +0 -0
- package/web/dist/assets/noto-emoji-4-400-normal-s_n9EyG1.woff2 +0 -0
- package/web/dist/assets/noto-emoji-5-400-normal-C190AIxR.woff +0 -0
- package/web/dist/assets/noto-emoji-5-400-normal-Ctfx4xc6.woff2 +0 -0
- package/web/dist/assets/noto-emoji-6-400-normal-DlXlXWt7.woff +0 -0
- package/web/dist/assets/noto-emoji-6-400-normal-NzsjD754.woff2 +0 -0
- package/web/dist/assets/noto-emoji-7-400-normal-BHP8KeA6.woff2 +0 -0
- package/web/dist/assets/noto-emoji-7-400-normal-CtuKhtAZ.woff +0 -0
- package/web/dist/assets/noto-emoji-8-400-normal-DR49ZFe7.woff +0 -0
- package/web/dist/assets/noto-emoji-8-400-normal-Dvmkf6b2.woff2 +0 -0
- package/web/dist/assets/noto-emoji-9-400-normal-BeHJQ2iK.woff2 +0 -0
- package/web/dist/assets/noto-emoji-9-400-normal-BlXmCgeQ.woff +0 -0
- package/web/dist/assets/ordinal-Cboi1Yqb.js +1 -0
- package/web/dist/assets/pieDiagram-ADFJNKIX-C45wSpld.js +30 -0
- package/web/dist/assets/quadrantDiagram-AYHSOK5B-tv-_fe-W.js +7 -0
- package/web/dist/assets/reduce-CoLNNlNb.js +1 -0
- package/web/dist/assets/requirementDiagram-UZGBJVZJ-Dn6PDfkL.js +64 -0
- package/web/dist/assets/sankeyDiagram-TZEHDZUN-CbXTZAsG.js +10 -0
- package/web/dist/assets/sequenceDiagram-WL72ISMW-B-o1CUJ5.js +145 -0
- package/web/dist/assets/stateDiagram-FKZM4ZOC-hzrupXQi.js +1 -0
- package/web/dist/assets/stateDiagram-v2-4FDKWEC3-DN-c2M96.js +1 -0
- package/web/dist/assets/timeline-definition-IT6M3QCI-R5SP9GDo.js +61 -0
- package/web/dist/assets/treemap-KMMF4GRG-Pg9KlUOt.js +128 -0
- package/web/dist/assets/xychartDiagram-PRI3JC2R-C3vbJhd1.js +7 -0
- package/web/dist/favicon.svg +13 -0
- package/web/dist/index.html +17 -0
- package//351/205/215/347/275/256/346/226/271/345/274/217.md +330 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 会话绑定逻辑
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const { readJsonFile } = require('./utils.cjs');
|
|
7
|
+
const { BINDINGS_PATH } = require('./config.cjs');
|
|
8
|
+
|
|
9
|
+
// 提醒节流间隔(毫秒)
|
|
10
|
+
const THROTTLE_INTERVAL = 3 * 60 * 1000; // 3 分钟
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 获取会话绑定信息(本地读取)
|
|
14
|
+
* @param {string} sessionId - 会话 ID(CC 的 session_id 或 Cursor 的 conversation_id)
|
|
15
|
+
* @returns {object|null} 绑定信息或 null
|
|
16
|
+
*/
|
|
17
|
+
function getSessionBinding(sessionId) {
|
|
18
|
+
const bindings = readJsonFile(BINDINGS_PATH);
|
|
19
|
+
if (!bindings || !bindings.bindings) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return bindings.bindings[sessionId] || null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 检测文本是否涉及工作区关键词
|
|
27
|
+
* @param {string} text - 要检测的文本
|
|
28
|
+
* @returns {boolean}
|
|
29
|
+
*/
|
|
30
|
+
function containsWorkspaceKeywords(text) {
|
|
31
|
+
const { WORKSPACE_KEYWORDS } = require('./config.cjs');
|
|
32
|
+
if (!text) return false;
|
|
33
|
+
const lowerText = text.toLowerCase();
|
|
34
|
+
return WORKSPACE_KEYWORDS.some(kw => lowerText.includes(kw.toLowerCase()));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 判断是否应该节流提醒
|
|
39
|
+
* @param {object} binding - 会话绑定信息
|
|
40
|
+
* @param {string} reminderType - 提醒类型
|
|
41
|
+
* @param {number} [customInterval] - 自定义节流间隔(毫秒),默认使用 THROTTLE_INTERVAL
|
|
42
|
+
* @returns {boolean} true 表示应该节流(不发送提醒)
|
|
43
|
+
*/
|
|
44
|
+
function shouldThrottle(binding, reminderType, customInterval) {
|
|
45
|
+
// P0 (problem) 类型不节流,每次都提醒
|
|
46
|
+
if (reminderType === 'problem') {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!binding || !binding.lastReminder) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const lastReminder = binding.lastReminder;
|
|
55
|
+
const interval = customInterval || THROTTLE_INTERVAL;
|
|
56
|
+
|
|
57
|
+
// 同一类型的提醒需要节流
|
|
58
|
+
if (lastReminder.type === reminderType) {
|
|
59
|
+
const lastTime = new Date(lastReminder.time).getTime();
|
|
60
|
+
const now = Date.now();
|
|
61
|
+
return (now - lastTime) < interval;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 更新上次提醒记录
|
|
69
|
+
* @param {string} sessionId - 会话 ID
|
|
70
|
+
* @param {string} reminderType - 提醒类型
|
|
71
|
+
* @returns {boolean} 是否更新成功
|
|
72
|
+
*/
|
|
73
|
+
function updateLastReminder(sessionId, reminderType) {
|
|
74
|
+
try {
|
|
75
|
+
const bindings = readJsonFile(BINDINGS_PATH);
|
|
76
|
+
if (!bindings || !bindings.bindings || !bindings.bindings[sessionId]) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
bindings.bindings[sessionId].lastReminder = {
|
|
81
|
+
type: reminderType,
|
|
82
|
+
time: new Date().toISOString()
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
fs.writeFileSync(BINDINGS_PATH, JSON.stringify(bindings, null, 2), 'utf-8');
|
|
86
|
+
return true;
|
|
87
|
+
} catch {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
module.exports = {
|
|
93
|
+
getSessionBinding,
|
|
94
|
+
containsWorkspaceKeywords,
|
|
95
|
+
shouldThrottle,
|
|
96
|
+
updateLastReminder,
|
|
97
|
+
THROTTLE_INTERVAL
|
|
98
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 共享配置
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
const os = require('node:os');
|
|
8
|
+
|
|
9
|
+
// 判断是否为开发模式(通过环境变量)
|
|
10
|
+
const IS_DEV_ENV = process.env.NODE_ENV === 'development' || process.env.ZERO_DEV === 'true';
|
|
11
|
+
|
|
12
|
+
// 两个可能的目录路径
|
|
13
|
+
const ZERO_HOME_DEV = path.join(os.homedir(), '.zero-workspace-dev');
|
|
14
|
+
const ZERO_HOME_PROD = path.join(os.homedir(), '.zero-workspace');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 自动检测实际使用的目录
|
|
18
|
+
* 优先检查 dev 目录是否存在绑定文件,如果存在则使用 dev 目录
|
|
19
|
+
* 这解决了 Hook 脚本没有 ZERO_DEV 环境变量但需要访问 dev 数据的问题
|
|
20
|
+
*/
|
|
21
|
+
function detectZeroHome() {
|
|
22
|
+
// 如果环境变量明确指定了 dev 模式,直接使用
|
|
23
|
+
if (IS_DEV_ENV) {
|
|
24
|
+
return ZERO_HOME_DEV;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// 否则,检查 dev 目录是否存在且有绑定文件(说明服务在 dev 模式运行)
|
|
28
|
+
const devBindingsPath = path.join(ZERO_HOME_DEV, 'session-bindings.json');
|
|
29
|
+
if (fs.existsSync(devBindingsPath)) {
|
|
30
|
+
return ZERO_HOME_DEV;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 默认使用生产目录
|
|
34
|
+
return ZERO_HOME_PROD;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const ZERO_HOME = detectZeroHome();
|
|
38
|
+
const IS_DEV = ZERO_HOME === ZERO_HOME_DEV;
|
|
39
|
+
const DIR_SUFFIX = IS_DEV ? '-dev' : '';
|
|
40
|
+
|
|
41
|
+
// 路径配置
|
|
42
|
+
const BINDINGS_PATH = path.join(ZERO_HOME, 'session-bindings.json');
|
|
43
|
+
const INDEX_PATH = path.join(ZERO_HOME, 'index.json');
|
|
44
|
+
|
|
45
|
+
// HTTP 端口
|
|
46
|
+
const HTTP_PORT = process.env.HTTP_PORT || process.env.PORT || (IS_DEV ? '3001' : '3000');
|
|
47
|
+
const MCP_URL = `http://localhost:${HTTP_PORT}`;
|
|
48
|
+
|
|
49
|
+
// 工作区相关关键词(用于检测用户消息是否涉及工作区)
|
|
50
|
+
const WORKSPACE_KEYWORDS = [
|
|
51
|
+
'工作区', 'workspace', '任务', '节点', 'node',
|
|
52
|
+
'继续', 'continue', '进度', 'progress',
|
|
53
|
+
'zero', 'session_bind', 'workspace_'
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
module.exports = {
|
|
57
|
+
IS_DEV,
|
|
58
|
+
DIR_SUFFIX,
|
|
59
|
+
ZERO_HOME,
|
|
60
|
+
BINDINGS_PATH,
|
|
61
|
+
INDEX_PATH,
|
|
62
|
+
HTTP_PORT,
|
|
63
|
+
MCP_URL,
|
|
64
|
+
WORKSPACE_KEYWORDS
|
|
65
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 上下文生成逻辑
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 生成工作区上下文注入内容
|
|
7
|
+
* @param {object} binding - 会话绑定信息
|
|
8
|
+
* @param {object} config - 工作区配置
|
|
9
|
+
* @param {object} workspaceMdData - 工作区 Markdown 数据
|
|
10
|
+
* @param {object} graph - 节点图
|
|
11
|
+
* @param {object} focusedNodeInfo - 聚焦节点信息
|
|
12
|
+
* @returns {string} 上下文内容
|
|
13
|
+
*/
|
|
14
|
+
function generateWorkspaceContext(binding, config, workspaceMdData, graph, focusedNodeInfo) {
|
|
15
|
+
let context = `
|
|
16
|
+
<zero-workspace-context>
|
|
17
|
+
## 当前工作区: ${config.name}
|
|
18
|
+
|
|
19
|
+
**目标**: ${workspaceMdData.goal}
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
// 添加规则
|
|
23
|
+
if (workspaceMdData.rules && workspaceMdData.rules.length > 0) {
|
|
24
|
+
context += `
|
|
25
|
+
**规则** (必须遵守):
|
|
26
|
+
${workspaceMdData.rules.map(r => `- ${r}`).join('\n')}
|
|
27
|
+
`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// 添加聚焦节点信息(优先使用 graph.currentFocus 作为权威来源)
|
|
31
|
+
const focusNodeId = graph?.currentFocus || binding.focusedNodeId;
|
|
32
|
+
if (focusNodeId && focusedNodeInfo) {
|
|
33
|
+
const nodeStatus = graph?.nodes[focusNodeId]?.status || focusedNodeInfo.status;
|
|
34
|
+
context += `
|
|
35
|
+
**当前聚焦节点**: ${focusedNodeInfo.title}
|
|
36
|
+
- 节点 ID: ${focusNodeId}
|
|
37
|
+
- 状态: ${nodeStatus}
|
|
38
|
+
${focusedNodeInfo.requirement ? `- 需求: ${focusedNodeInfo.requirement}` : ''}
|
|
39
|
+
`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
context += `
|
|
43
|
+
---
|
|
44
|
+
**工作流程提醒**:
|
|
45
|
+
- 开始任务前: 调用 node_transition(action='start')
|
|
46
|
+
- 完成任务后: 调用 node_transition(action='complete', conclusion='...')
|
|
47
|
+
- 重要事件时: 调用 log_append 记录
|
|
48
|
+
- 遇到问题时: 调用 problem_update 记录
|
|
49
|
+
</zero-workspace-context>
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
return context;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 生成 sessionId 注入内容(让 AI 知道自己的会话 ID)
|
|
57
|
+
* @param {string} sessionId - 会话 ID
|
|
58
|
+
* @param {string} platform - 平台标识 ('claude-code' | 'cursor')
|
|
59
|
+
* @returns {string} 注入内容
|
|
60
|
+
*/
|
|
61
|
+
function generateSessionIdContext(sessionId, platform = 'claude-code') {
|
|
62
|
+
const idName = platform === 'cursor' ? 'conversation_id' : 'sessionId';
|
|
63
|
+
const paramName = platform === 'cursor' ? 'sessionId' : 'sessionId';
|
|
64
|
+
|
|
65
|
+
return `<zero-session-info>
|
|
66
|
+
当前会话 ID: ${sessionId}
|
|
67
|
+
如需使用 ZeroWorkspace 管理任务,请调用: session_bind(${paramName}="${sessionId}", workspaceId="...")
|
|
68
|
+
可用 session_status(${paramName}="${sessionId}") 查看可用工作区列表。
|
|
69
|
+
</zero-session-info>`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 生成绑定提醒内容(未绑定但检测到工作区关键词时)
|
|
74
|
+
* @param {string} sessionId - 会话 ID
|
|
75
|
+
* @param {string} platform - 平台标识 ('claude-code' | 'cursor')
|
|
76
|
+
* @returns {string} 提醒内容
|
|
77
|
+
*/
|
|
78
|
+
function generateBindingReminder(sessionId, platform = 'claude-code') {
|
|
79
|
+
const paramName = platform === 'cursor' ? 'sessionId' : 'sessionId';
|
|
80
|
+
|
|
81
|
+
return `<zero-workspace-reminder>
|
|
82
|
+
检测到可能涉及工作区任务,但当前会话未绑定工作区。
|
|
83
|
+
如需使用 ZeroWorkspace 功能,请先绑定:
|
|
84
|
+
- 查看可用工作区: session_status(${paramName}="${sessionId}")
|
|
85
|
+
- 绑定工作区: session_bind(${paramName}="${sessionId}", workspaceId="...")
|
|
86
|
+
</zero-workspace-reminder>`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 获取完整的工作区上下文(组合调用)
|
|
91
|
+
* @param {object} binding - 会话绑定信息
|
|
92
|
+
* @returns {string|null} 上下文内容或 null
|
|
93
|
+
*/
|
|
94
|
+
function getFullWorkspaceContext(binding) {
|
|
95
|
+
const { getWorkspaceConfig, getWorkspaceMdData, getNodeGraph, getNodeInfo } = require('./workspace.cjs');
|
|
96
|
+
|
|
97
|
+
const config = getWorkspaceConfig(binding.workspaceId);
|
|
98
|
+
if (!config) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const workspaceMdData = getWorkspaceMdData(binding.workspaceId);
|
|
103
|
+
const graph = getNodeGraph(binding.workspaceId);
|
|
104
|
+
// 优先使用 graph.currentFocus 作为权威来源
|
|
105
|
+
const focusNodeId = graph?.currentFocus || binding.focusedNodeId;
|
|
106
|
+
const focusedNodeInfo = focusNodeId ? getNodeInfo(binding.workspaceId, focusNodeId) : null;
|
|
107
|
+
|
|
108
|
+
if (workspaceMdData) {
|
|
109
|
+
return generateWorkspaceContext(binding, config, workspaceMdData, graph, focusedNodeInfo);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
module.exports = {
|
|
116
|
+
generateWorkspaceContext,
|
|
117
|
+
generateSessionIdContext,
|
|
118
|
+
generateBindingReminder,
|
|
119
|
+
getFullWorkspaceContext
|
|
120
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 共享模块统一导出
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const config = require('./config.cjs');
|
|
6
|
+
const utils = require('./utils.cjs');
|
|
7
|
+
const binding = require('./binding.cjs');
|
|
8
|
+
const workspace = require('./workspace.cjs');
|
|
9
|
+
const context = require('./context.cjs');
|
|
10
|
+
const reminder = require('./reminder.cjs');
|
|
11
|
+
const logger = require('./logger.cjs');
|
|
12
|
+
|
|
13
|
+
module.exports = {
|
|
14
|
+
// 配置
|
|
15
|
+
...config,
|
|
16
|
+
|
|
17
|
+
// 工具函数
|
|
18
|
+
...utils,
|
|
19
|
+
|
|
20
|
+
// 绑定逻辑
|
|
21
|
+
...binding,
|
|
22
|
+
|
|
23
|
+
// 工作区数据
|
|
24
|
+
...workspace,
|
|
25
|
+
|
|
26
|
+
// 上下文生成
|
|
27
|
+
...context,
|
|
28
|
+
|
|
29
|
+
// 智能提醒
|
|
30
|
+
...reminder,
|
|
31
|
+
|
|
32
|
+
// 日志
|
|
33
|
+
...logger
|
|
34
|
+
};
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zero-Workspace 日志模块
|
|
3
|
+
*
|
|
4
|
+
* 功能:
|
|
5
|
+
* - 仅在 dev 模式下记录日志
|
|
6
|
+
* - 按会话 ID 分文件记录
|
|
7
|
+
* - 自动轮转,最多保留 50 个日志文件
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const fs = require('node:fs');
|
|
11
|
+
const path = require('node:path');
|
|
12
|
+
const { IS_DEV, ZERO_HOME } = require('./config.cjs');
|
|
13
|
+
|
|
14
|
+
// 日志目录
|
|
15
|
+
const LOGS_DIR = path.join(ZERO_HOME, 'logs');
|
|
16
|
+
|
|
17
|
+
// 最大日志文件数
|
|
18
|
+
const MAX_LOG_FILES = 50;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 确保日志目录存在
|
|
22
|
+
*/
|
|
23
|
+
function ensureLogsDir() {
|
|
24
|
+
if (!IS_DEV) return false;
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
if (!fs.existsSync(LOGS_DIR)) {
|
|
28
|
+
fs.mkdirSync(LOGS_DIR, { recursive: true });
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
} catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 获取日志文件路径
|
|
38
|
+
* @param {string} sessionId - 会话 ID
|
|
39
|
+
* @returns {string} 日志文件路径
|
|
40
|
+
*/
|
|
41
|
+
function getLogFilePath(sessionId) {
|
|
42
|
+
const fileName = sessionId ? `${sessionId}.log` : 'default.log';
|
|
43
|
+
return path.join(LOGS_DIR, fileName);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 格式化时间戳
|
|
48
|
+
* @returns {string} 格式化的时间戳
|
|
49
|
+
*/
|
|
50
|
+
function formatTimestamp() {
|
|
51
|
+
return new Date().toISOString();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 清理旧日志文件,保留最新的 MAX_LOG_FILES 个
|
|
56
|
+
*/
|
|
57
|
+
function rotateLogsIfNeeded() {
|
|
58
|
+
if (!IS_DEV) return;
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
if (!fs.existsSync(LOGS_DIR)) return;
|
|
62
|
+
|
|
63
|
+
const files = fs.readdirSync(LOGS_DIR)
|
|
64
|
+
.filter(f => f.endsWith('.log'))
|
|
65
|
+
.map(f => ({
|
|
66
|
+
name: f,
|
|
67
|
+
path: path.join(LOGS_DIR, f),
|
|
68
|
+
mtime: fs.statSync(path.join(LOGS_DIR, f)).mtime.getTime()
|
|
69
|
+
}))
|
|
70
|
+
.sort((a, b) => b.mtime - a.mtime); // 按修改时间降序
|
|
71
|
+
|
|
72
|
+
// 删除超出限制的旧文件
|
|
73
|
+
if (files.length > MAX_LOG_FILES) {
|
|
74
|
+
const toDelete = files.slice(MAX_LOG_FILES);
|
|
75
|
+
for (const file of toDelete) {
|
|
76
|
+
try {
|
|
77
|
+
fs.unlinkSync(file.path);
|
|
78
|
+
} catch {
|
|
79
|
+
// 忽略删除失败
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
} catch {
|
|
84
|
+
// 忽略轮转错误
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 写入日志
|
|
90
|
+
* @param {string} sessionId - 会话 ID(可选)
|
|
91
|
+
* @param {string} type - 日志类型 (hook/mcp)
|
|
92
|
+
* @param {string} event - 事件名称
|
|
93
|
+
* @param {object} data - 日志数据
|
|
94
|
+
*/
|
|
95
|
+
function log(sessionId, type, event, data = {}) {
|
|
96
|
+
if (!IS_DEV) return;
|
|
97
|
+
|
|
98
|
+
if (!ensureLogsDir()) return;
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
const logPath = getLogFilePath(sessionId);
|
|
102
|
+
const timestamp = formatTimestamp();
|
|
103
|
+
|
|
104
|
+
const logLine = `[${timestamp}] [${type.toUpperCase()}] ${event}: ${JSON.stringify(data)}\n`;
|
|
105
|
+
|
|
106
|
+
fs.appendFileSync(logPath, logLine, 'utf-8');
|
|
107
|
+
|
|
108
|
+
// 每次写入后检查是否需要轮转
|
|
109
|
+
rotateLogsIfNeeded();
|
|
110
|
+
} catch {
|
|
111
|
+
// 静默失败,不影响主流程
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* 记录 Hook 调用
|
|
117
|
+
* @param {string} sessionId - 会话 ID
|
|
118
|
+
* @param {string} hookEvent - Hook 事件类型
|
|
119
|
+
* @param {object} details - 详细信息
|
|
120
|
+
*/
|
|
121
|
+
function logHook(sessionId, hookEvent, details = {}) {
|
|
122
|
+
log(sessionId, 'hook', hookEvent, details);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* 记录 Hook 完整输出(包含发送给 AI 的内容)
|
|
127
|
+
* @param {string} sessionId - 会话 ID
|
|
128
|
+
* @param {string} hookEvent - Hook 事件类型
|
|
129
|
+
* @param {string} action - 动作类型 (output|throttled|silent)
|
|
130
|
+
* @param {object} details - 详细信息
|
|
131
|
+
* @param {string} [output] - 实际输出给 AI 的内容(截断到 500 字符)
|
|
132
|
+
*/
|
|
133
|
+
function logHookOutput(sessionId, hookEvent, action, details = {}, output = null) {
|
|
134
|
+
const logData = {
|
|
135
|
+
action,
|
|
136
|
+
...details
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
if (output && typeof output === 'string') {
|
|
140
|
+
// 截断输出内容,避免日志过大
|
|
141
|
+
logData.output = output.length > 500 ? output.slice(0, 500) + '...[truncated]' : output;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
log(sessionId, 'hook', `${hookEvent}:${action}`, logData);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 记录 MCP 工具调用开始
|
|
149
|
+
* @param {string} sessionId - 会话 ID
|
|
150
|
+
* @param {string} toolName - 工具名称
|
|
151
|
+
* @param {object} params - 调用参数
|
|
152
|
+
*/
|
|
153
|
+
function logMcpStart(sessionId, toolName, params = {}) {
|
|
154
|
+
log(sessionId, 'mcp', `${toolName}:start`, { params });
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* 记录 MCP 工具调用结束
|
|
159
|
+
* @param {string} sessionId - 会话 ID
|
|
160
|
+
* @param {string} toolName - 工具名称
|
|
161
|
+
* @param {boolean} success - 是否成功
|
|
162
|
+
* @param {any} result - 调用结果(截断)
|
|
163
|
+
* @param {number} durationMs - 耗时(毫秒)
|
|
164
|
+
*/
|
|
165
|
+
function logMcpEnd(sessionId, toolName, success, result, durationMs = 0) {
|
|
166
|
+
const resultStr = typeof result === 'object' ? JSON.stringify(result) : String(result);
|
|
167
|
+
const details = {
|
|
168
|
+
success,
|
|
169
|
+
result: resultStr.length > 500 ? resultStr.slice(0, 500) + '...' : resultStr,
|
|
170
|
+
durationMs
|
|
171
|
+
};
|
|
172
|
+
log(sessionId, 'mcp', `${toolName}:end`, details);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* 记录错误
|
|
177
|
+
* @param {string} sessionId - 会话 ID
|
|
178
|
+
* @param {string} context - 错误上下文
|
|
179
|
+
* @param {Error|string} error - 错误信息
|
|
180
|
+
*/
|
|
181
|
+
function logError(sessionId, context, error) {
|
|
182
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
183
|
+
log(sessionId, 'error', context, { error: errorMsg });
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
module.exports = {
|
|
187
|
+
LOGS_DIR,
|
|
188
|
+
MAX_LOG_FILES,
|
|
189
|
+
log,
|
|
190
|
+
logHook,
|
|
191
|
+
logHookOutput,
|
|
192
|
+
logMcpStart,
|
|
193
|
+
logMcpEnd,
|
|
194
|
+
logError,
|
|
195
|
+
rotateLogsIfNeeded
|
|
196
|
+
};
|