@ai-setting/roy-agent-core 1.0.0
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/dist/index.js +99145 -0
- package/package.json +114 -0
- package/src/config/config-component.test.ts +627 -0
- package/src/config/config-component.ts +906 -0
- package/src/config/config-parser.test.ts +319 -0
- package/src/config/config-parser.ts +203 -0
- package/src/config/decentralized-config.test.ts +740 -0
- package/src/config/env-key.ts +210 -0
- package/src/config/env-source.test.ts +252 -0
- package/src/config/env-source.ts +301 -0
- package/src/config/file-source.test.ts +357 -0
- package/src/config/file-source.ts +421 -0
- package/src/config/index.ts +24 -0
- package/src/config/protocol-resolver.test.ts +217 -0
- package/src/config/protocol-resolver.ts +228 -0
- package/src/env/agent/agent-component.abort.test.ts +511 -0
- package/src/env/agent/agent-component.record-session.test.ts +349 -0
- package/src/env/agent/agent-component.test.ts +1389 -0
- package/src/env/agent/agent-component.tool-error.test.ts +327 -0
- package/src/env/agent/agent-component.ts +1711 -0
- package/src/env/agent/agent-config-registration.test.ts +226 -0
- package/src/env/agent/agent-config-registration.ts +46 -0
- package/src/env/agent/agent-reminder-plugin.integration.test.ts +243 -0
- package/src/env/agent/index.ts +10 -0
- package/src/env/agent/summary-agent.parse-hint.test.ts +360 -0
- package/src/env/agent/summary-agent.ts +508 -0
- package/src/env/agent/types.ts +536 -0
- package/src/env/commands/commands-component.test.ts +364 -0
- package/src/env/commands/commands-component.ts +604 -0
- package/src/env/commands/commands-config-registration.test.ts +198 -0
- package/src/env/commands/commands-config-registration.ts +38 -0
- package/src/env/commands/index.ts +21 -0
- package/src/env/commands/parser.test.ts +203 -0
- package/src/env/commands/parser.ts +115 -0
- package/src/env/commands/types.ts +184 -0
- package/src/env/commands-prompt-integration.test.ts +243 -0
- package/src/env/component-env.test.ts +119 -0
- package/src/env/component.ts +335 -0
- package/src/env/constants.test.ts +72 -0
- package/src/env/constants.ts +123 -0
- package/src/env/debug/debug-component.test.ts +114 -0
- package/src/env/debug/debug-component.ts +547 -0
- package/src/env/debug/formatters/index.ts +9 -0
- package/src/env/debug/formatters/repl-formatter.test.ts +139 -0
- package/src/env/debug/formatters/repl-formatter.ts +358 -0
- package/src/env/debug/formatters/trace-formatter.test.ts +119 -0
- package/src/env/debug/formatters/trace-formatter.ts +191 -0
- package/src/env/debug/formatters/tree-formatter.test.ts +107 -0
- package/src/env/debug/formatters/tree-formatter.ts +325 -0
- package/src/env/debug/index.ts +38 -0
- package/src/env/debug/parser/regex-parser.test.ts +201 -0
- package/src/env/debug/parser/regex-parser.ts +196 -0
- package/src/env/debug/parser/span-builder.test.ts +241 -0
- package/src/env/debug/parser/span-builder.ts +386 -0
- package/src/env/debug/reader/log-reader.test.ts +170 -0
- package/src/env/debug/reader/log-reader.ts +186 -0
- package/src/env/debug/reader/span-db-reader.test.ts +118 -0
- package/src/env/debug/reader/span-db-reader.ts +201 -0
- package/src/env/debug/types.test.ts +187 -0
- package/src/env/debug/types.ts +171 -0
- package/src/env/environment-init.test.ts +183 -0
- package/src/env/environment-lifecycle.test.ts +516 -0
- package/src/env/environment-service.test.ts +332 -0
- package/src/env/environment.handle-query.test.ts +96 -0
- package/src/env/environment.test.ts +232 -0
- package/src/env/environment.ts +708 -0
- package/src/env/errors.test.ts +165 -0
- package/src/env/errors.ts +157 -0
- package/src/env/event-source/event-source-agent-handler.test.ts +193 -0
- package/src/env/event-source/event-source-agent-handler.ts +111 -0
- package/src/env/event-source/event-source-component.process-cleanup.test.ts +236 -0
- package/src/env/event-source/event-source-component.stop.test.ts +346 -0
- package/src/env/event-source/event-source-component.test.ts +1207 -0
- package/src/env/event-source/event-source-component.ts +1379 -0
- package/src/env/event-source/event-source-config-registration.test.ts +242 -0
- package/src/env/event-source/event-source-config-registration.ts +37 -0
- package/src/env/event-source/event-source-integration.test.ts +320 -0
- package/src/env/event-source/event-source-platform.test.ts +630 -0
- package/src/env/event-source/types.ts +298 -0
- package/src/env/hook/global-hook-manager.ts +162 -0
- package/src/env/hook/hook-manager.test.ts +374 -0
- package/src/env/hook/hook-manager.ts +309 -0
- package/src/env/hook/index.ts +38 -0
- package/src/env/hook/types.ts +138 -0
- package/src/env/index.ts +144 -0
- package/src/env/interface.ts +203 -0
- package/src/env/llm/hooks.test.ts +293 -0
- package/src/env/llm/hooks.ts +316 -0
- package/src/env/llm/index.ts +61 -0
- package/src/env/llm/invoke-threshold-check.test.ts +88 -0
- package/src/env/llm/invoke-timeout.test.ts +54 -0
- package/src/env/llm/invoke.test.ts +71 -0
- package/src/env/llm/invoke.ts +1039 -0
- package/src/env/llm/llm-config.test.ts +523 -0
- package/src/env/llm/llm.test.ts +233 -0
- package/src/env/llm/llm.ts +568 -0
- package/src/env/llm/provider.test.ts +182 -0
- package/src/env/llm/provider.ts +108 -0
- package/src/env/llm/transform.test.ts +251 -0
- package/src/env/llm/transform.ts +286 -0
- package/src/env/llm/types.test.ts +580 -0
- package/src/env/llm/types.ts +424 -0
- package/src/env/log-trace/decorator-otel.test.ts +182 -0
- package/src/env/log-trace/decorator.ts +230 -0
- package/src/env/log-trace/index.ts +79 -0
- package/src/env/log-trace/log-trace-component.test.ts +242 -0
- package/src/env/log-trace/log-trace-component.ts +497 -0
- package/src/env/log-trace/log-trace-config-registration.test.ts +348 -0
- package/src/env/log-trace/log-trace-config-registration.ts +45 -0
- package/src/env/log-trace/logger.test.ts +149 -0
- package/src/env/log-trace/logger.ts +522 -0
- package/src/env/log-trace/opentelemetry/cli-propagation.test.ts +147 -0
- package/src/env/log-trace/opentelemetry/cli-propagation.ts +194 -0
- package/src/env/log-trace/opentelemetry/integration.test.ts +668 -0
- package/src/env/log-trace/opentelemetry/mod.ts +25 -0
- package/src/env/log-trace/opentelemetry/propagation-env.test.ts +181 -0
- package/src/env/log-trace/opentelemetry/propagation-env.ts +136 -0
- package/src/env/log-trace/opentelemetry/propagation.test.ts +259 -0
- package/src/env/log-trace/opentelemetry/propagation.ts +215 -0
- package/src/env/log-trace/opentelemetry/tracer-provider-context.test.ts +166 -0
- package/src/env/log-trace/opentelemetry/tracer-provider.test.ts +379 -0
- package/src/env/log-trace/opentelemetry/tracer-provider.ts +612 -0
- package/src/env/log-trace/span-storage.test.ts +145 -0
- package/src/env/log-trace/span-storage.ts +230 -0
- package/src/env/log-trace/trace-context.test.ts +187 -0
- package/src/env/log-trace/trace-context.ts +162 -0
- package/src/env/log-trace/types.test.ts +63 -0
- package/src/env/log-trace/types.ts +172 -0
- package/src/env/mcp/README.md +244 -0
- package/src/env/mcp/__integration__/mcp-component.integration.test.ts +373 -0
- package/src/env/mcp/config.test.ts +74 -0
- package/src/env/mcp/config.ts +116 -0
- package/src/env/mcp/index.ts +41 -0
- package/src/env/mcp/loader.test.ts +161 -0
- package/src/env/mcp/loader.ts +209 -0
- package/src/env/mcp/mcp-component.test.ts +111 -0
- package/src/env/mcp/mcp-component.ts +358 -0
- package/src/env/mcp/mcp-config-registration.test.ts +304 -0
- package/src/env/mcp/mcp-config-registration.ts +50 -0
- package/src/env/mcp/scanner.test.ts +170 -0
- package/src/env/mcp/scanner.ts +246 -0
- package/src/env/mcp/tool/adapter.test.ts +520 -0
- package/src/env/mcp/tool/adapter.ts +521 -0
- package/src/env/mcp/tool/index.ts +5 -0
- package/src/env/mcp/types.test.ts +171 -0
- package/src/env/mcp/types.ts +79 -0
- package/src/env/memory/README.md +177 -0
- package/src/env/memory/built-in/index.ts +59 -0
- package/src/env/memory/built-in/recall-memory.ts +103 -0
- package/src/env/memory/built-in/record-memory.ts +148 -0
- package/src/env/memory/index.ts +20 -0
- package/src/env/memory/memory-component.test.ts +239 -0
- package/src/env/memory/memory-component.ts +503 -0
- package/src/env/memory/memory-config-registration.test.ts +67 -0
- package/src/env/memory/memory-config-registration.ts +48 -0
- package/src/env/memory/memory-config.ts +45 -0
- package/src/env/memory/memory-file.test.ts +268 -0
- package/src/env/memory/plugin/index.ts +48 -0
- package/src/env/memory/plugin/memory-agent.test.ts +249 -0
- package/src/env/memory/plugin/memory-agent.ts +365 -0
- package/src/env/memory/plugin/memory-manager.ts +198 -0
- package/src/env/memory/plugin/memory-plugin-agent.test.ts +145 -0
- package/src/env/memory/plugin/memory-plugin.ts +210 -0
- package/src/env/memory/plugin/plugin-simplified.test.ts +51 -0
- package/src/env/memory/plugin/recall-memory.test.ts +106 -0
- package/src/env/memory/plugin/recall-memory.ts +53 -0
- package/src/env/memory/plugin/types.ts +101 -0
- package/src/env/memory/tools/memory-agent-tools.ts +228 -0
- package/src/env/memory/types.ts +85 -0
- package/src/env/paths.ts +118 -0
- package/src/env/prompt/index.ts +18 -0
- package/src/env/prompt/memory-prompts.test.ts +91 -0
- package/src/env/prompt/prompt-component.test.ts +491 -0
- package/src/env/prompt/prompt-component.ts +619 -0
- package/src/env/prompt/prompt-config-registration.test.ts +213 -0
- package/src/env/prompt/prompt-config-registration.ts +39 -0
- package/src/env/prompt/prompts-index.ts +504 -0
- package/src/env/prompt/renderer.ts +67 -0
- package/src/env/prompt/types.ts +136 -0
- package/src/env/session/hooks.ts +18 -0
- package/src/env/session/index.ts +37 -0
- package/src/env/session/search-query-parser.test.ts +425 -0
- package/src/env/session/search-query-parser.ts +171 -0
- package/src/env/session/session-checkpoint.test.ts +523 -0
- package/src/env/session/session-component.extract-recent-messages.test.ts +209 -0
- package/src/env/session/session-component.test.ts +132 -0
- package/src/env/session/session-component.ts +1249 -0
- package/src/env/session/session-config-registration.test.ts +138 -0
- package/src/env/session/session-config-registration.ts +52 -0
- package/src/env/session/session-message-converter.test.ts +763 -0
- package/src/env/session/session-message-converter.ts +415 -0
- package/src/env/session/session-message-e2e.test.ts +448 -0
- package/src/env/session/session-search.test.ts +391 -0
- package/src/env/session/session-store.test.ts +362 -0
- package/src/env/session/session-store.ts +141 -0
- package/src/env/session/storage/index.ts +6 -0
- package/src/env/session/storage/memory.ts +502 -0
- package/src/env/session/storage/sqlite.ts +794 -0
- package/src/env/session/types.ts +742 -0
- package/src/env/skill/config.ts +39 -0
- package/src/env/skill/index.ts +6 -0
- package/src/env/skill/parser.test.ts +116 -0
- package/src/env/skill/parser.ts +77 -0
- package/src/env/skill/scanner.test.ts +211 -0
- package/src/env/skill/scanner.ts +119 -0
- package/src/env/skill/skill-component.test.ts +234 -0
- package/src/env/skill/skill-component.ts +352 -0
- package/src/env/skill/skill-config-registration.test.ts +60 -0
- package/src/env/skill/skill-config-registration.ts +43 -0
- package/src/env/skill/tool/index.ts +1 -0
- package/src/env/skill/tool/skill-tool.test.ts +100 -0
- package/src/env/skill/tool/skill-tool.ts +72 -0
- package/src/env/skill/types.ts +64 -0
- package/src/env/task/delegate/delegate-tool.test.ts +498 -0
- package/src/env/task/delegate/delegate-tool.ts +1014 -0
- package/src/env/task/delegate/index.ts +18 -0
- package/src/env/task/delegate/stop-tool.test.ts +140 -0
- package/src/env/task/delegate/stop-tool.ts +119 -0
- package/src/env/task/delegate/task-events.test.ts +178 -0
- package/src/env/task/delegate/task-events.ts +143 -0
- package/src/env/task/hooks/contexts.test.ts +92 -0
- package/src/env/task/hooks/contexts.ts +192 -0
- package/src/env/task/hooks/index.ts +23 -0
- package/src/env/task/hooks/task-hook-points.test.ts +32 -0
- package/src/env/task/hooks/task-hook-points.ts +54 -0
- package/src/env/task/index.ts +7 -0
- package/src/env/task/plugins/index.ts +13 -0
- package/src/env/task/plugins/task-plugin.test.ts +74 -0
- package/src/env/task/plugins/task-plugin.ts +89 -0
- package/src/env/task/plugins/task-tag-plugin.test.ts +377 -0
- package/src/env/task/plugins/task-tag-plugin.ts +319 -0
- package/src/env/task/plugins/task-workflow-extractor.integration.test.ts +226 -0
- package/src/env/task/plugins/workflow-extractor-agent.test.ts +107 -0
- package/src/env/task/plugins/workflow-extractor-agent.ts +225 -0
- package/src/env/task/storage/index.ts +6 -0
- package/src/env/task/storage/sqlite-task-store.test.ts +283 -0
- package/src/env/task/storage/sqlite-task-store.ts +903 -0
- package/src/env/task/storage/task-search.test.ts +291 -0
- package/src/env/task/tag-service.test.ts +198 -0
- package/src/env/task/tag-service.ts +264 -0
- package/src/env/task/task-component.test.ts +193 -0
- package/src/env/task/task-component.ts +658 -0
- package/src/env/task/task-config-registration.test.ts +57 -0
- package/src/env/task/task-config-registration.ts +37 -0
- package/src/env/task/task-types.test.ts +137 -0
- package/src/env/task/tools/complete-tool.ts +44 -0
- package/src/env/task/tools/create-tool.ts +49 -0
- package/src/env/task/tools/delete-tool.ts +43 -0
- package/src/env/task/tools/get-tool.ts +59 -0
- package/src/env/task/tools/index.ts +10 -0
- package/src/env/task/tools/list-tool.ts +40 -0
- package/src/env/task/tools/operation/create-tool.ts +48 -0
- package/src/env/task/tools/operation/delete-tool.ts +43 -0
- package/src/env/task/tools/operation/get-tool.ts +43 -0
- package/src/env/task/tools/operation/index.ts +9 -0
- package/src/env/task/tools/operation/list-tool.ts +40 -0
- package/src/env/task/tools/operation/operation-tools.test.ts +274 -0
- package/src/env/task/tools/operation/operation-types.ts +75 -0
- package/src/env/task/tools/operation/update-tool.ts +47 -0
- package/src/env/task/tools/task-tools.test.ts +203 -0
- package/src/env/task/tools/task-types.test.ts +75 -0
- package/src/env/task/tools/task-types.ts +68 -0
- package/src/env/task/tools/update-tool.ts +70 -0
- package/src/env/task/types.ts +160 -0
- package/src/env/tool/built-in/bash.ts +201 -0
- package/src/env/tool/built-in/echo.ts +29 -0
- package/src/env/tool/built-in/edit-file.test.ts +136 -0
- package/src/env/tool/built-in/edit-file.ts +92 -0
- package/src/env/tool/built-in/glob.test.ts +94 -0
- package/src/env/tool/built-in/glob.ts +65 -0
- package/src/env/tool/built-in/grep.test.ts +122 -0
- package/src/env/tool/built-in/grep.ts +108 -0
- package/src/env/tool/built-in/index.ts +44 -0
- package/src/env/tool/built-in/read-file.test.ts +84 -0
- package/src/env/tool/built-in/read-file.ts +75 -0
- package/src/env/tool/built-in/write-file.test.ts +119 -0
- package/src/env/tool/built-in/write-file.ts +68 -0
- package/src/env/tool/index.ts +24 -0
- package/src/env/tool/registry.test.ts +257 -0
- package/src/env/tool/registry.ts +167 -0
- package/src/env/tool/tool-component.test.ts +559 -0
- package/src/env/tool/tool-component.ts +563 -0
- package/src/env/tool/tool-config-registration.test.ts +249 -0
- package/src/env/tool/tool-config-registration.ts +46 -0
- package/src/env/tool/types.ts +267 -0
- package/src/env/tool/validator.test.ts +143 -0
- package/src/env/tool/validator.ts +44 -0
- package/src/env/types.ts +180 -0
- package/src/env/workflow/ask-user-tool-registration.test.ts +216 -0
- package/src/env/workflow/complex-workflow.integration.test.ts +1900 -0
- package/src/env/workflow/decorators/decorator-node.ts +229 -0
- package/src/env/workflow/decorators/decorator.test.ts +196 -0
- package/src/env/workflow/decorators/edge.ts +82 -0
- package/src/env/workflow/decorators/index.ts +31 -0
- package/src/env/workflow/decorators/node-as.ts +98 -0
- package/src/env/workflow/decorators/workflow.ts +54 -0
- package/src/env/workflow/engine/dag-manager.test.ts +570 -0
- package/src/env/workflow/engine/dag-manager.ts +594 -0
- package/src/env/workflow/engine/engine.ts +1422 -0
- package/src/env/workflow/engine/event-bus.test.ts +359 -0
- package/src/env/workflow/engine/event-bus.ts +156 -0
- package/src/env/workflow/engine/executor-agent-session.test.ts +84 -0
- package/src/env/workflow/engine/executor.test.ts +619 -0
- package/src/env/workflow/engine/executor.ts +593 -0
- package/src/env/workflow/engine/index.ts +24 -0
- package/src/env/workflow/engine/node-registry.test.ts +560 -0
- package/src/env/workflow/engine/node-registry.ts +289 -0
- package/src/env/workflow/engine/resume-removed.test.ts +22 -0
- package/src/env/workflow/engine/scheduler.test.ts +715 -0
- package/src/env/workflow/engine/scheduler.ts +318 -0
- package/src/env/workflow/engine/workflow-engine.test.ts +815 -0
- package/src/env/workflow/extractor/workflow-converter.ts +306 -0
- package/src/env/workflow/fixtures.ts +380 -0
- package/src/env/workflow/index.ts +38 -0
- package/src/env/workflow/integration/run-resume-unified.test.ts +186 -0
- package/src/env/workflow/integration/service-integration.test.ts +267 -0
- package/src/env/workflow/metadata/keys.ts +12 -0
- package/src/env/workflow/nodes/agent-component-adapter.test.ts +318 -0
- package/src/env/workflow/nodes/agent-component-adapter.ts +448 -0
- package/src/env/workflow/nodes/agent-node.test.ts +371 -0
- package/src/env/workflow/nodes/agent-node.ts +598 -0
- package/src/env/workflow/nodes/ask-user-node.ts +113 -0
- package/src/env/workflow/nodes/condition-node.ts +200 -0
- package/src/env/workflow/nodes/index.ts +9 -0
- package/src/env/workflow/nodes/merge-node.ts +141 -0
- package/src/env/workflow/nodes/skill-node.test.ts +253 -0
- package/src/env/workflow/nodes/skill-node.ts +393 -0
- package/src/env/workflow/nodes/tool-node.test.ts +251 -0
- package/src/env/workflow/nodes/tool-node.ts +493 -0
- package/src/env/workflow/nodes/workflow-llm-history.test.ts +455 -0
- package/src/env/workflow/nodes/workflow-node.test.ts +315 -0
- package/src/env/workflow/nodes/workflow-node.ts +311 -0
- package/src/env/workflow/service/index.ts +27 -0
- package/src/env/workflow/service/registry.test.ts +133 -0
- package/src/env/workflow/service/registry.ts +71 -0
- package/src/env/workflow/service/workflow-service.test.ts +310 -0
- package/src/env/workflow/service/workflow-service.ts +393 -0
- package/src/env/workflow/storage/index.ts +28 -0
- package/src/env/workflow/storage/mock-repositories.ts +385 -0
- package/src/env/workflow/storage/sqlite.test.ts +179 -0
- package/src/env/workflow/storage/sqlite.ts +163 -0
- package/src/env/workflow/storage/workflow-repo.test.ts +780 -0
- package/src/env/workflow/storage/workflow-repo.ts +342 -0
- package/src/env/workflow/tools/ask-user-tool.ts +82 -0
- package/src/env/workflow/tools/index.ts +26 -0
- package/src/env/workflow/tools/run-workflow.test.ts +352 -0
- package/src/env/workflow/tools/run-workflow.ts +214 -0
- package/src/env/workflow/types/context.ts +18 -0
- package/src/env/workflow/types/decorators-types.ts +198 -0
- package/src/env/workflow/types/event.test.ts +515 -0
- package/src/env/workflow/types/event.ts +193 -0
- package/src/env/workflow/types/index.ts +49 -0
- package/src/env/workflow/types/run.test.ts +437 -0
- package/src/env/workflow/types/run.ts +173 -0
- package/src/env/workflow/types/workflow-hil.ts +114 -0
- package/src/env/workflow/types/workflow-message.test.ts +138 -0
- package/src/env/workflow/types/workflow-message.ts +196 -0
- package/src/env/workflow/types/workflow-session.test.ts +95 -0
- package/src/env/workflow/types/workflow-session.ts +59 -0
- package/src/env/workflow/types/workflow.test.ts +495 -0
- package/src/env/workflow/types/workflow.ts +195 -0
- package/src/env/workflow/types_compat.ts +51 -0
- package/src/env/workflow/utils/create-workflow.ts +47 -0
- package/src/env/workflow/utils/execution-state.ts +245 -0
- package/src/env/workflow/utils/index.ts +18 -0
- package/src/env/workflow/utils/node-registry-helper.ts +58 -0
- package/src/env/workflow/utils/recovery-validator.test.ts +460 -0
- package/src/env/workflow/utils/recovery-validator.ts +377 -0
- package/src/env/workflow/utils/session-parser.test.ts +111 -0
- package/src/env/workflow/utils/session-parser.ts +94 -0
- package/src/env/workflow/utils/session-recovery.test.ts +334 -0
- package/src/env/workflow/utils/session-recovery.ts +188 -0
- package/src/env/workflow/utils/template-resolver.test.ts +258 -0
- package/src/env/workflow/utils/template-resolver.ts +436 -0
- package/src/env/workflow/utils/validation-rules.ts +149 -0
- package/src/env/workflow/workflow-component.ts +544 -0
- package/src/index.ts +422 -0
- package/src/utils/id.ts +21 -0
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview SummaryAgent parseHintResponse 测试
|
|
3
|
+
*
|
|
4
|
+
* TDD 规范:覆盖 LLM 可能返回的各种输出格式
|
|
5
|
+
*
|
|
6
|
+
* 测试 parseCompactHintResponse 函数的解析逻辑
|
|
7
|
+
*
|
|
8
|
+
* Hint 阶段输出格式:JSON with guidance_prompt key
|
|
9
|
+
* 需要兼容各种 LLM 输出格式
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { describe, expect, test } from "bun:test";
|
|
13
|
+
import { parseCompactHintResponse } from "./summary-agent";
|
|
14
|
+
|
|
15
|
+
// ============================================================================
|
|
16
|
+
// 测试数据:各种 LLM 输出场景
|
|
17
|
+
// ============================================================================
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 场景1: JSON with guidance_prompt key (标准格式)
|
|
21
|
+
* 新格式:包含 Work type, Progress, CRITICAL to preserve, Focus extraction on
|
|
22
|
+
*/
|
|
23
|
+
const LLM_OUTPUT_JSON_STANDARD = `{
|
|
24
|
+
"guidance_prompt": "Bug investigation: User is debugging LSP diagnostics not updating after file edits. Progress: identified root cause (getDiagnostics needs to read latest file content and trigger didChange notification), implemented fix, CI verified. CRITICAL to preserve: the fix implementation details (file path, code changes), that 2 agent-node-integration tests still fail due to test assertion timing issue (expects 'running' but completes in ~78ms) - this is unrelated to LSP work. Focus extraction on: root cause analysis, fix implementation, known remaining test issues."
|
|
25
|
+
}`;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 场景2: JSON with explanation (text + json 混合)
|
|
29
|
+
*/
|
|
30
|
+
const LLM_OUTPUT_JSON_WITH_EXPLANATION = `Based on my analysis of the conversation, here is the guidance prompt:
|
|
31
|
+
|
|
32
|
+
{
|
|
33
|
+
"guidance_prompt": "Feature development: User is implementing JWT authentication for auth-service. Progress: designed auth flow, implemented token refresh logic, middleware partially done. CRITICAL to preserve: auth flow decisions (token storage, refresh strategy), completed middleware components, modules pending implementation. Focus extraction on: architectural decisions, completed components, pending work."
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
This guidance will help generate a more focused checkpoint.`;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 场景3: JSON wrapped in ```json ```
|
|
40
|
+
*/
|
|
41
|
+
const LLM_OUTPUT_JSON_CODE_BLOCK = `Here's the analysis:
|
|
42
|
+
|
|
43
|
+
\`\`\`json
|
|
44
|
+
{
|
|
45
|
+
"guidance_prompt": "Refactoring: User is migrating data layer to repository pattern. Progress: migrated UserRepository and OrderRepository, 3 more pending. CRITICAL to preserve: pattern decisions (interface definitions, dependency injection approach), completed repositories, modules pending migration. Focus extraction on: pattern implementation details, completed vs pending modules."
|
|
46
|
+
}
|
|
47
|
+
\`\`\`
|
|
48
|
+
|
|
49
|
+
Let me know if you need any adjustments.`;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 场景4: JSON wrapped in plain ``` ```
|
|
53
|
+
*/
|
|
54
|
+
const LLM_OUTPUT_JSON_PLAIN_CODE_BLOCK = `\`\`\`
|
|
55
|
+
{
|
|
56
|
+
"guidance_prompt": "Bug investigation. User is debugging intermittent 500 errors on /api/users endpoint. CRITICAL to preserve: suspected root cause (race condition), metrics added, remaining investigation steps. Focus on: root cause analysis and next steps."
|
|
57
|
+
}
|
|
58
|
+
\`\`\``;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 场景5: Markdown code block with language hint
|
|
62
|
+
*/
|
|
63
|
+
const LLM_OUTPUT_MARKDOWN_CODE_BLOCK = `### Guidance Prompt
|
|
64
|
+
|
|
65
|
+
\`\`\`markdown
|
|
66
|
+
Feature development. User is implementing JWT authentication. CRITICAL to preserve: auth flow decisions.
|
|
67
|
+
\`\`\``;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 场景5a: 纯 markdown code block(无语言标识)
|
|
71
|
+
*/
|
|
72
|
+
const LLM_OUTPUT_PLAIN_CODE_BLOCK_PLAIN = `\`\`\`
|
|
73
|
+
Feature development. User is implementing JWT authentication. CRITICAL to preserve: auth flow decisions.
|
|
74
|
+
\`\`\``;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 场景6: 纯文本(无 JSON)- 降级处理
|
|
78
|
+
*/
|
|
79
|
+
const LLM_OUTPUT_PLAIN_TEXT = `Bug investigation: User is debugging LSP diagnostics not updating after file edits. Progress: identified root cause, implemented fix. CRITICAL to preserve: fix implementation details, remaining test issues. Focus on: root cause analysis, fix implementation.`;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 场景7: 带空白的 JSON
|
|
83
|
+
*/
|
|
84
|
+
const LLM_OUTPUT_JSON_WITH_WHITESPACE = `
|
|
85
|
+
|
|
86
|
+
{
|
|
87
|
+
"guidance_prompt": "Bug investigation: User is debugging intermittent 500 errors on /api/users endpoint. Progress: identified root cause. CRITICAL to preserve: race condition findings, metrics added. Focus on: remaining investigation steps."
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
`;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 场景8: JSON with additional fields
|
|
94
|
+
*/
|
|
95
|
+
const LLM_OUTPUT_JSON_WITH_EXTRA_FIELDS = `{
|
|
96
|
+
"analysis": "The user is working on a feature implementation",
|
|
97
|
+
"guidance_prompt": "Feature development: User is implementing JWT authentication. Progress: designed auth flow. CRITICAL to preserve: token storage strategy, refresh logic. Focus extraction on: architectural decisions.",
|
|
98
|
+
"work_type": "feature",
|
|
99
|
+
"priority": "high"
|
|
100
|
+
}`;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 场景9: 超长 JSON
|
|
104
|
+
*/
|
|
105
|
+
const LLM_OUTPUT_JSON_LONG = `{
|
|
106
|
+
"guidance_prompt": "Feature development: User is implementing JWT authentication for the auth-service. Progress: designed auth flow, implemented token refresh logic, middleware partially done. CRITICAL to preserve: auth flow decisions (token storage, refresh strategy), completed middleware components, modules pending implementation. Focus extraction on: architectural decisions, completed components, pending work. ${"x".repeat(300)}"
|
|
107
|
+
}`;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* 场景10: 空白内容
|
|
111
|
+
*/
|
|
112
|
+
const LLM_OUTPUT_EMPTY = "";
|
|
113
|
+
|
|
114
|
+
// ============================================================================
|
|
115
|
+
// TDD 测试:按场景覆盖
|
|
116
|
+
// ============================================================================
|
|
117
|
+
|
|
118
|
+
describe("SummaryAgent.parseCompactHintResponse", () => {
|
|
119
|
+
|
|
120
|
+
describe("场景1: JSON 标准格式 (新格式)", () => {
|
|
121
|
+
|
|
122
|
+
test("应正确解析 JSON 并提取 guidance_prompt", () => {
|
|
123
|
+
const result = parseCompactHintResponse(LLM_OUTPUT_JSON_STANDARD);
|
|
124
|
+
|
|
125
|
+
expect(result).toContain("Bug investigation");
|
|
126
|
+
expect(result).toContain("Progress:");
|
|
127
|
+
expect(result).toContain("CRITICAL to preserve:");
|
|
128
|
+
expect(result).toContain("Focus extraction on:");
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe("场景2: JSON with explanation (text + json 混合)", () => {
|
|
134
|
+
|
|
135
|
+
test("应正确解析包含说明文本的 JSON", () => {
|
|
136
|
+
const result = parseCompactHintResponse(LLM_OUTPUT_JSON_WITH_EXPLANATION);
|
|
137
|
+
|
|
138
|
+
expect(result).toContain("Feature development");
|
|
139
|
+
expect(result).toContain("Progress:");
|
|
140
|
+
expect(result).toContain("CRITICAL to preserve:");
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe("场景3: JSON wrapped in ```json ```", () => {
|
|
146
|
+
|
|
147
|
+
test("应正确解析 ```json ``` 包裹的 JSON", () => {
|
|
148
|
+
const result = parseCompactHintResponse(LLM_OUTPUT_JSON_CODE_BLOCK);
|
|
149
|
+
|
|
150
|
+
expect(result).toContain("Refactoring");
|
|
151
|
+
expect(result).toContain("Progress:");
|
|
152
|
+
expect(result).toContain("CRITICAL to preserve:");
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe("场景4: JSON wrapped in plain ``` ```", () => {
|
|
158
|
+
|
|
159
|
+
test("应正确解析 ``` ``` 包裹的 JSON", () => {
|
|
160
|
+
const result = parseCompactHintResponse(LLM_OUTPUT_JSON_PLAIN_CODE_BLOCK);
|
|
161
|
+
|
|
162
|
+
expect(result).toContain("Bug investigation");
|
|
163
|
+
expect(result).toContain("CRITICAL to preserve:");
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
describe("场景5: Markdown code block with language hint", () => {
|
|
169
|
+
|
|
170
|
+
test("应正确解析 markdown 包裹的纯文本", () => {
|
|
171
|
+
const result = parseCompactHintResponse(LLM_OUTPUT_MARKDOWN_CODE_BLOCK);
|
|
172
|
+
|
|
173
|
+
// markdown ```...``` 提取内部内容,前面的文本会被保留
|
|
174
|
+
expect(result).toContain("Feature development");
|
|
175
|
+
expect(result).toContain("CRITICAL to preserve:");
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
describe("场景5a: 纯 code block(无语言标识)", () => {
|
|
181
|
+
|
|
182
|
+
test("应正确提取 code block 内的纯文本", () => {
|
|
183
|
+
const result = parseCompactHintResponse(LLM_OUTPUT_PLAIN_CODE_BLOCK_PLAIN);
|
|
184
|
+
|
|
185
|
+
expect(result).toContain("Feature development");
|
|
186
|
+
expect(result).toContain("CRITICAL to preserve:");
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
describe("场景6: 纯文本(无 JSON)- 降级处理", () => {
|
|
192
|
+
|
|
193
|
+
test("纯文本应直接返回(作为降级方案)", () => {
|
|
194
|
+
const result = parseCompactHintResponse(LLM_OUTPUT_PLAIN_TEXT);
|
|
195
|
+
|
|
196
|
+
expect(result).toContain("Bug investigation");
|
|
197
|
+
expect(result).toContain("Progress:");
|
|
198
|
+
expect(result).toContain("CRITICAL to preserve:");
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test("纯文本应包含必要元素", () => {
|
|
202
|
+
const result = parseCompactHintResponse(LLM_OUTPUT_PLAIN_TEXT);
|
|
203
|
+
|
|
204
|
+
expect(result).toMatch(/Bug investigation|Feature development|Refactoring/i);
|
|
205
|
+
expect(result).toMatch(/Progress:/i);
|
|
206
|
+
expect(result).toMatch(/CRITICAL to preserve:/i);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
describe("场景7: 带空白的 JSON", () => {
|
|
212
|
+
|
|
213
|
+
test("应正确解析带空白的 JSON", () => {
|
|
214
|
+
const result = parseCompactHintResponse(LLM_OUTPUT_JSON_WITH_WHITESPACE);
|
|
215
|
+
|
|
216
|
+
expect(result).toContain("Bug investigation");
|
|
217
|
+
expect(result).toContain("Progress:");
|
|
218
|
+
expect(result).toContain("CRITICAL to preserve:");
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
describe("场景8: JSON with extra fields", () => {
|
|
224
|
+
|
|
225
|
+
test("应忽略额外字段,只提取 guidance_prompt", () => {
|
|
226
|
+
const result = parseCompactHintResponse(LLM_OUTPUT_JSON_WITH_EXTRA_FIELDS);
|
|
227
|
+
|
|
228
|
+
expect(result).toContain("Feature development");
|
|
229
|
+
expect(result).toContain("Progress:");
|
|
230
|
+
expect(result).toContain("CRITICAL to preserve:");
|
|
231
|
+
// 不应包含额外字段
|
|
232
|
+
expect(result).not.toContain('"analysis"');
|
|
233
|
+
expect(result).not.toContain('"work_type"');
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
describe("场景9: 超长 JSON guidance_prompt", () => {
|
|
239
|
+
|
|
240
|
+
test("超长内容应被截断到 500 字符", () => {
|
|
241
|
+
const result = parseCompactHintResponse(LLM_OUTPUT_JSON_LONG);
|
|
242
|
+
|
|
243
|
+
expect(result.length).toBe(503); // 500 + "..."
|
|
244
|
+
expect(result.endsWith("...")).toBe(true);
|
|
245
|
+
expect(result).toContain("Feature development");
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
describe("场景10: 空白内容", () => {
|
|
251
|
+
|
|
252
|
+
test("空字符串应返回降级提示", () => {
|
|
253
|
+
const result = parseCompactHintResponse(LLM_OUTPUT_EMPTY);
|
|
254
|
+
|
|
255
|
+
expect(result).toBe("[Hint extraction failed]");
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
describe("边界情况", () => {
|
|
261
|
+
|
|
262
|
+
test("纯空白应返回降级提示", () => {
|
|
263
|
+
const result = parseCompactHintResponse(" \n\n ");
|
|
264
|
+
|
|
265
|
+
expect(result).toBe("[Hint extraction failed]");
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
test("带 guidance_prompt key 但值为空应返回降级提示", () => {
|
|
269
|
+
const result = parseCompactHintResponse('{"guidance_prompt": ""}');
|
|
270
|
+
|
|
271
|
+
expect(result).toBe("[Hint extraction failed]");
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
test("JSON 但缺少 guidance_prompt 字段应降级处理", () => {
|
|
275
|
+
const result = parseCompactHintResponse('{"other_field": "some value"}');
|
|
276
|
+
|
|
277
|
+
// 降级到纯文本处理
|
|
278
|
+
expect(result).toBe('{"other_field": "some value"}');
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
test("无效 JSON 应降级处理", () => {
|
|
282
|
+
const result = parseCompactHintResponse("This is not JSON at all");
|
|
283
|
+
|
|
284
|
+
// 降级到纯文本处理
|
|
285
|
+
expect(result).toBe("This is not JSON at all");
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
test("JSON 解析失败但有代码块应尝试提取", () => {
|
|
289
|
+
const result = parseCompactHintResponse("```json\ninvalid json {}\n```");
|
|
290
|
+
|
|
291
|
+
// 降级处理后可能是原始内容
|
|
292
|
+
expect(typeof result).toBe("string");
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
// ============================================================================
|
|
300
|
+
// 补充测试:指导 Prompt 格式验证 (新格式)
|
|
301
|
+
// ============================================================================
|
|
302
|
+
|
|
303
|
+
describe("Compact Guidance Prompt 格式示例 (新格式)", () => {
|
|
304
|
+
|
|
305
|
+
const goodExamples = [
|
|
306
|
+
"Bug investigation: User is debugging LSP diagnostics not updating. Progress: identified root cause, implemented fix. CRITICAL to preserve: fix implementation details, remaining test issues. Focus extraction on: root cause analysis.",
|
|
307
|
+
"Feature development: User is implementing JWT authentication. Progress: designed auth flow, implemented token refresh. CRITICAL to preserve: auth flow decisions, completed components. Focus extraction on: architectural decisions.",
|
|
308
|
+
"Refactoring: User is migrating data layer to repository pattern. Progress: migrated UserRepository, 3 more pending. CRITICAL to preserve: pattern decisions, completed repositories. Focus extraction on: pattern implementation details.",
|
|
309
|
+
];
|
|
310
|
+
|
|
311
|
+
test.each(goodExamples)("示例应包含必要元素", (example) => {
|
|
312
|
+
const result = parseCompactHintResponse(example);
|
|
313
|
+
|
|
314
|
+
// 应该包含工作类型关键词
|
|
315
|
+
expect(result).toMatch(/Bug investigation:|Feature development:|Refactoring:/i);
|
|
316
|
+
|
|
317
|
+
// 应该包含 Progress:
|
|
318
|
+
expect(result).toMatch(/Progress:/i);
|
|
319
|
+
|
|
320
|
+
// 应该包含 CRITICAL to preserve:
|
|
321
|
+
expect(result).toMatch(/CRITICAL to preserve:/i);
|
|
322
|
+
|
|
323
|
+
// 应该包含 Focus extraction on:
|
|
324
|
+
expect(result).toMatch(/Focus extraction on:/i);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
// ============================================================================
|
|
330
|
+
// 输出约束测试
|
|
331
|
+
// ============================================================================
|
|
332
|
+
|
|
333
|
+
describe("LLM Output Format 约束", () => {
|
|
334
|
+
|
|
335
|
+
describe("guidance_prompt key 验证", () => {
|
|
336
|
+
|
|
337
|
+
test("正确格式的 JSON 应能被解析", () => {
|
|
338
|
+
const jsonInput = '{"guidance_prompt": "Test prompt"}';
|
|
339
|
+
const result = parseCompactHintResponse(jsonInput);
|
|
340
|
+
|
|
341
|
+
expect(result).toBe("Test prompt");
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
test("带转义字符的 guidance_prompt 应正确解析", () => {
|
|
345
|
+
const jsonInput = '{"guidance_prompt": "Test with \\"quotes\\" and \\\\ backslash"}';
|
|
346
|
+
const result = parseCompactHintResponse(jsonInput);
|
|
347
|
+
|
|
348
|
+
expect(result).toBe('Test with "quotes" and \\ backslash');
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
test("带换行符的 guidance_prompt 应正确解析", () => {
|
|
352
|
+
const jsonInput = '{"guidance_prompt": "Line 1\\nLine 2"}';
|
|
353
|
+
const result = parseCompactHintResponse(jsonInput);
|
|
354
|
+
|
|
355
|
+
expect(result).toBe("Line 1\nLine 2");
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
});
|